OmniSciDB  6686921089
 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 89 of file CachingFileMgr.h.

Constructor & Destructor Documentation

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

Definition at line 714 of file CachingFileMgr.cpp.

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

715  : table_path_(table_path)
718  , epoch_(Epoch())
719  , is_checkpointed_(true) {
720  if (!bf::exists(table_path_)) {
721  bf::create_directory(table_path_);
722  } else {
723  CHECK(bf::is_directory(table_path_)) << "Specified path '" << table_path_
724  << "' for cache table data is not a directory.";
725  }
726  if (bf::exists(epoch_file_path_)) {
727  CHECK(bf::is_regular_file(epoch_file_path_))
728  << "Found epoch file '" << epoch_file_path_ << "' which is not a regular file";
730  << "Found epoch file '" << epoch_file_path_ << "' which is not of expected size";
733  } else {
736  incrementEpoch();
737  }
738 }
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:49
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:133
void incrementEpoch()
increment the epoch for this subdir (not synced to disk).
static constexpr char EPOCH_FILENAME[]
Definition: FileMgr.h:376
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:98
#define CHECK(condition)
Definition: Logger.h:209
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 92 of file CachingFileMgr.h.

References File_Namespace::close(), and epoch_file_.

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

+ 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 784 of file CachingFileMgr.cpp.

References table_mutex_, and wrapper_file_path_.

784  {
785  mapd_unique_lock<mapd_shared_mutex> w_lock(table_mutex_);
786  bf::remove_all(wrapper_file_path_);
787 }
mapd_shared_mutex table_mutex_
int32_t File_Namespace::TableFileMgr::getEpoch ( ) const

Returns the current epoch (locked)

Definition at line 749 of file CachingFileMgr.cpp.

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

749  {
750  mapd_shared_lock<mapd_shared_mutex> r_lock(table_mutex_);
751  return static_cast<int32_t>(epoch_.ceiling());
752 }
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 773 of file CachingFileMgr.cpp.

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

773  {
774  mapd_shared_lock<mapd_shared_mutex> r_lock(table_mutex_);
775  size_t space = 0;
776  for (const auto& file : bf::recursive_directory_iterator(table_path_)) {
777  if (bf::is_regular_file(file.path())) {
778  space += bf::file_size(file.path());
779  }
780  }
781  return space;
782 }
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 740 of file CachingFileMgr.cpp.

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

Referenced by TableFileMgr().

740  {
741  mapd_unique_lock<mapd_shared_mutex> w_lock(table_mutex_);
742  epoch_.increment();
743  is_checkpointed_ = false;
745  << "Epoch greater than maximum allowed value (" << epoch_.ceiling() << " > "
746  << Epoch::max_allowable_epoch() << ").";
747 }
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:209

+ 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 768 of file CachingFileMgr.cpp.

References table_mutex_, and table_path_.

768  {
769  mapd_unique_lock<mapd_shared_mutex> w_lock(table_mutex_);
770  bf::remove_all(table_path_);
771 }
mapd_shared_mutex table_mutex_
void File_Namespace::TableFileMgr::writeAndSyncEpochToDisk ( )

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

Definition at line 754 of file CachingFileMgr.cpp.

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

Referenced by TableFileMgr().

754  {
755  mapd_unique_lock<mapd_shared_mutex> w_lock(table_mutex_);
757  int32_t status = fflush(epoch_file_);
758  CHECK(status == 0) << "Could not flush epoch file to disk";
759 #ifdef __APPLE__
760  status = fcntl(fileno(epoch_file_), 51);
761 #else
762  status = omnisci::fsync(fileno(epoch_file_));
763 #endif
764  CHECK(status == 0) << "Could not sync epoch file to disk";
765  is_checkpointed_ = true;
766 }
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:141
mapd_shared_mutex table_mutex_
int fsync(int fd)
Definition: omnisci_fs.cpp:60
static size_t byte_size()
Definition: Epoch.h:63
#define CHECK(condition)
Definition: Logger.h:209

+ 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 789 of file CachingFileMgr.cpp.

References table_mutex_, and wrapper_file_path_.

789  {
790  mapd_unique_lock<mapd_shared_mutex> w_lock(table_mutex_);
791  std::ofstream ofs(wrapper_file_path_);
792  if (!ofs) {
793  throw std::runtime_error{"Error trying to create file \"" + wrapper_file_path_ +
794  "\". The error was: " + std::strerror(errno)};
795  }
796  ofs << doc;
797 }
mapd_shared_mutex table_mutex_

Member Data Documentation

Epoch File_Namespace::TableFileMgr::epoch_
private

Definition at line 133 of file CachingFileMgr.h.

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

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

Definition at line 135 of file CachingFileMgr.h.

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

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

Definition at line 131 of file CachingFileMgr.h.

Referenced by TableFileMgr().

bool File_Namespace::TableFileMgr::is_checkpointed_ = true
private

Definition at line 134 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 130 of file CachingFileMgr.h.

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

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

Definition at line 132 of file CachingFileMgr.h.

Referenced by deleteWrapperFile(), and writeWrapperFile().


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