OmniSciDB  085a039ca4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
File_Namespace::TableFileMgr Class Reference

#include <CachingFileMgr.h>

+ Collaboration diagram for File_Namespace::TableFileMgr:

Public Member Functions

 TableFileMgr (const std::string &table_path)
 
 ~TableFileMgr ()
 
void incrementEpoch ()
 increment the epoch for this subdir (not synced to disk). More...
 
void writeAndSyncEpochToDisk ()
 Write and flush the epoch to the epoch file on disk. More...
 
int32_t getEpoch () const
 Returns the current epoch (locked) More...
 
void removeDiskContent () const
 Removes all disk data for the subdir. More...
 
size_t getReservedSpace () const
 Returns the disk space used (in bytes) for the subdir. More...
 
void deleteWrapperFile () const
 Deletes only the wrapper file on disk. More...
 
void writeWrapperFile (const std::string &doc) const
 Writes wrapper file to disk. More...
 

Private Attributes

std::string table_path_
 
std::string epoch_file_path_
 
std::string wrapper_file_path_
 
Epoch epoch_
 
bool is_checkpointed_ = true
 
FILE * epoch_file_ = nullptr
 
mapd_shared_mutex table_mutex_
 

Detailed Description

Definition at line 91 of file CachingFileMgr.h.

Constructor & Destructor Documentation

File_Namespace::TableFileMgr::TableFileMgr ( const std::string &  table_path)

Definition at line 744 of file CachingFileMgr.cpp.

References Epoch::byte_size(), CHECK, File_Namespace::create(), epoch_, epoch_file_, epoch_file_path_, heavyai::file_size(), incrementEpoch(), File_Namespace::open(), File_Namespace::read(), Epoch::storage_ptr(), table_path_, and writeAndSyncEpochToDisk().

745  : table_path_(table_path)
748  , epoch_(Epoch())
749  , is_checkpointed_(true) {
750  if (!bf::exists(table_path_)) {
751  bf::create_directory(table_path_);
752  } else {
753  CHECK(bf::is_directory(table_path_)) << "Specified path '" << table_path_
754  << "' for cache table data is not a directory.";
755  }
756  if (bf::exists(epoch_file_path_)) {
757  CHECK(bf::is_regular_file(epoch_file_path_))
758  << "Found epoch file '" << epoch_file_path_ << "' which is not a regular file";
760  << "Found epoch file '" << epoch_file_path_ << "' which is not of expected size";
763  } else {
766  incrementEpoch();
767  }
768 }
int8_t * storage_ptr()
Definition: Epoch.h:61
void writeAndSyncEpochToDisk()
Write and flush the epoch to the epoch file on disk.
FILE * create(const std::string &basePath, const int fileId, const size_t pageSize, const size_t numPages)
Definition: File.cpp:57
size_t read(FILE *f, const size_t offset, const size_t size, int8_t *buf)
Reads the specified number of bytes from the offset position in file f into buf.
Definition: File.cpp:142
void incrementEpoch()
increment the epoch for this subdir (not synced to disk).
static constexpr char EPOCH_FILENAME[]
Definition: FileMgr.h:387
Definition: Epoch.h:30
static size_t byte_size()
Definition: Epoch.h:63
static constexpr char WRAPPER_FILE_NAME[]
FILE * open(int fileId)
Opens/creates the file with the given id; returns NULL on error.
Definition: File.cpp:107
#define CHECK(condition)
Definition: Logger.h:223
size_t file_size(const int fd)
Definition: omnisci_fs.cpp:31

+ Here is the call graph for this function:

File_Namespace::TableFileMgr::~TableFileMgr ( )
inline

Definition at line 94 of file CachingFileMgr.h.

References File_Namespace::close(), and epoch_file_.

94 { close(epoch_file_); }
void close(FILE *f)
Closes the file pointed to by the FILE pointer.
Definition: File.cpp:128

+ Here is the call graph for this function:

Member Function Documentation

void File_Namespace::TableFileMgr::deleteWrapperFile ( ) const

Deletes only the wrapper file on disk.

Definition at line 814 of file CachingFileMgr.cpp.

References table_mutex_, and wrapper_file_path_.

814  {
815  mapd_unique_lock<mapd_shared_mutex> w_lock(table_mutex_);
816  bf::remove_all(wrapper_file_path_);
817 }
mapd_shared_mutex table_mutex_
int32_t File_Namespace::TableFileMgr::getEpoch ( ) const

Returns the current epoch (locked)

Definition at line 779 of file CachingFileMgr.cpp.

References Epoch::ceiling(), epoch_, and table_mutex_.

779  {
780  mapd_shared_lock<mapd_shared_mutex> r_lock(table_mutex_);
781  return static_cast<int32_t>(epoch_.ceiling());
782 }
int32_t ceiling() const
Definition: Epoch.h:44
mapd_shared_mutex table_mutex_

+ Here is the call graph for this function:

size_t File_Namespace::TableFileMgr::getReservedSpace ( ) const

Returns the disk space used (in bytes) for the subdir.

Definition at line 803 of file CachingFileMgr.cpp.

References heavyai::file_size(), table_mutex_, and table_path_.

803  {
804  mapd_shared_lock<mapd_shared_mutex> r_lock(table_mutex_);
805  size_t space = 0;
806  for (const auto& file : bf::recursive_directory_iterator(table_path_)) {
807  if (bf::is_regular_file(file.path())) {
808  space += bf::file_size(file.path());
809  }
810  }
811  return space;
812 }
mapd_shared_mutex table_mutex_
size_t file_size(const int fd)
Definition: omnisci_fs.cpp:31

+ Here is the call graph for this function:

void File_Namespace::TableFileMgr::incrementEpoch ( )

increment the epoch for this subdir (not synced to disk).

Definition at line 770 of file CachingFileMgr.cpp.

References Epoch::ceiling(), CHECK, epoch_, Epoch::increment(), is_checkpointed_, Epoch::max_allowable_epoch(), and table_mutex_.

Referenced by TableFileMgr().

770  {
771  mapd_unique_lock<mapd_shared_mutex> w_lock(table_mutex_);
772  epoch_.increment();
773  is_checkpointed_ = false;
775  << "Epoch greater than maximum allowed value (" << epoch_.ceiling() << " > "
776  << Epoch::max_allowable_epoch() << ").";
777 }
int32_t ceiling() const
Definition: Epoch.h:44
static int64_t max_allowable_epoch()
Definition: Epoch.h:69
mapd_shared_mutex table_mutex_
int32_t increment()
Definition: Epoch.h:54
#define CHECK(condition)
Definition: Logger.h:223

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void File_Namespace::TableFileMgr::removeDiskContent ( ) const

Removes all disk data for the subdir.

Definition at line 798 of file CachingFileMgr.cpp.

References table_mutex_, and table_path_.

798  {
799  mapd_unique_lock<mapd_shared_mutex> w_lock(table_mutex_);
800  bf::remove_all(table_path_);
801 }
mapd_shared_mutex table_mutex_
void File_Namespace::TableFileMgr::writeAndSyncEpochToDisk ( )

Write and flush the epoch to the epoch file on disk.

Definition at line 784 of file CachingFileMgr.cpp.

References Epoch::byte_size(), CHECK, epoch_, epoch_file_, heavyai::fsync(), is_checkpointed_, Epoch::storage_ptr(), table_mutex_, and File_Namespace::write().

Referenced by TableFileMgr().

784  {
785  mapd_unique_lock<mapd_shared_mutex> w_lock(table_mutex_);
787  int32_t status = fflush(epoch_file_);
788  CHECK(status == 0) << "Could not flush epoch file to disk";
789 #ifdef __APPLE__
790  status = fcntl(fileno(epoch_file_), 51);
791 #else
792  status = heavyai::fsync(fileno(epoch_file_));
793 #endif
794  CHECK(status == 0) << "Could not sync epoch file to disk";
795  is_checkpointed_ = true;
796 }
int8_t * storage_ptr()
Definition: Epoch.h:61
size_t write(FILE *f, const size_t offset, const size_t size, const int8_t *buf)
Writes the specified number of bytes to the offset position in file f from buf.
Definition: File.cpp:150
mapd_shared_mutex table_mutex_
static size_t byte_size()
Definition: Epoch.h:63
int fsync(int fd)
Definition: omnisci_fs.cpp:60
#define CHECK(condition)
Definition: Logger.h:223

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void File_Namespace::TableFileMgr::writeWrapperFile ( const std::string &  doc) const

Writes wrapper file to disk.

Definition at line 819 of file CachingFileMgr.cpp.

References table_mutex_, and wrapper_file_path_.

819  {
820  mapd_unique_lock<mapd_shared_mutex> w_lock(table_mutex_);
821  std::ofstream ofs(wrapper_file_path_);
822  if (!ofs) {
823  throw std::runtime_error{"Error trying to create file \"" + wrapper_file_path_ +
824  "\". The error was: " + std::strerror(errno)};
825  }
826  ofs << doc;
827 }
mapd_shared_mutex table_mutex_

Member Data Documentation

Epoch File_Namespace::TableFileMgr::epoch_
private

Definition at line 135 of file CachingFileMgr.h.

Referenced by getEpoch(), incrementEpoch(), TableFileMgr(), and writeAndSyncEpochToDisk().

FILE* File_Namespace::TableFileMgr::epoch_file_ = nullptr
private

Definition at line 137 of file CachingFileMgr.h.

Referenced by TableFileMgr(), writeAndSyncEpochToDisk(), and ~TableFileMgr().

std::string File_Namespace::TableFileMgr::epoch_file_path_
private

Definition at line 133 of file CachingFileMgr.h.

Referenced by TableFileMgr().

bool File_Namespace::TableFileMgr::is_checkpointed_ = true
private

Definition at line 136 of file CachingFileMgr.h.

Referenced by incrementEpoch(), and writeAndSyncEpochToDisk().

mapd_shared_mutex File_Namespace::TableFileMgr::table_mutex_
mutableprivate
std::string File_Namespace::TableFileMgr::table_path_
private

Definition at line 132 of file CachingFileMgr.h.

Referenced by getReservedSpace(), removeDiskContent(), and TableFileMgr().

std::string File_Namespace::TableFileMgr::wrapper_file_path_
private

Definition at line 134 of file CachingFileMgr.h.

Referenced by deleteWrapperFile(), and writeWrapperFile().


The documentation for this class was generated from the following files: