OmniSciDB  ba1bac9284
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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 86 of file CachingFileMgr.h.

Constructor & Destructor Documentation

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

Definition at line 686 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().

687  : table_path_(table_path)
690  , epoch_(Epoch())
691  , is_checkpointed_(true) {
692  if (!bf::exists(table_path_)) {
693  bf::create_directory(table_path_);
694  } else {
695  CHECK(bf::is_directory(table_path_)) << "Specified path '" << table_path_
696  << "' for cache table data is not a directory.";
697  }
698  if (bf::exists(epoch_file_path_)) {
699  CHECK(bf::is_regular_file(epoch_file_path_))
700  << "Found epoch file '" << epoch_file_path_ << "' which is not a regular file";
702  << "Found epoch file '" << epoch_file_path_ << "' which is not of expected size";
705  } else {
708  incrementEpoch();
709  }
710 }
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:374
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:206
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 89 of file CachingFileMgr.h.

References File_Namespace::close(), and epoch_file_.

89 { 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 756 of file CachingFileMgr.cpp.

References table_mutex_, and wrapper_file_path_.

756  {
757  mapd_unique_lock<mapd_shared_mutex> w_lock(table_mutex_);
758  bf::remove_all(wrapper_file_path_);
759 }
mapd_shared_mutex table_mutex_
int32_t File_Namespace::TableFileMgr::getEpoch ( ) const

Returns the current epoch (locked)

Definition at line 721 of file CachingFileMgr.cpp.

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

721  {
722  mapd_shared_lock<mapd_shared_mutex> r_lock(table_mutex_);
723  return static_cast<int32_t>(epoch_.ceiling());
724 }
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 745 of file CachingFileMgr.cpp.

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

745  {
746  mapd_shared_lock<mapd_shared_mutex> r_lock(table_mutex_);
747  size_t space = 0;
748  for (const auto& file : bf::recursive_directory_iterator(table_path_)) {
749  if (bf::is_regular_file(file.path())) {
750  space += bf::file_size(file.path());
751  }
752  }
753  return space;
754 }
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 712 of file CachingFileMgr.cpp.

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

Referenced by TableFileMgr().

712  {
713  mapd_unique_lock<mapd_shared_mutex> w_lock(table_mutex_);
714  epoch_.increment();
715  is_checkpointed_ = false;
717  << "Epoch greater than maximum allowed value (" << epoch_.ceiling() << " > "
718  << Epoch::max_allowable_epoch() << ").";
719 }
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:206

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

References table_mutex_, and table_path_.

740  {
741  mapd_unique_lock<mapd_shared_mutex> w_lock(table_mutex_);
742  bf::remove_all(table_path_);
743 }
mapd_shared_mutex table_mutex_
void File_Namespace::TableFileMgr::writeAndSyncEpochToDisk ( )

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

Definition at line 726 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().

726  {
727  mapd_unique_lock<mapd_shared_mutex> w_lock(table_mutex_);
729  int32_t status = fflush(epoch_file_);
730  CHECK(status == 0) << "Could not flush epoch file to disk";
731 #ifdef __APPLE__
732  status = fcntl(fileno(epoch_file_), 51);
733 #else
734  status = omnisci::fsync(fileno(epoch_file_));
735 #endif
736  CHECK(status == 0) << "Could not sync epoch file to disk";
737  is_checkpointed_ = true;
738 }
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:206

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

References table_mutex_, and wrapper_file_path_.

761  {
762  mapd_unique_lock<mapd_shared_mutex> w_lock(table_mutex_);
763  std::ofstream ofs(wrapper_file_path_);
764  if (!ofs) {
765  throw std::runtime_error{"Error trying to create file \"" + wrapper_file_path_ +
766  "\". The error was: " + std::strerror(errno)};
767  }
768  ofs << doc;
769 }
mapd_shared_mutex table_mutex_

Member Data Documentation

Epoch File_Namespace::TableFileMgr::epoch_
private

Definition at line 130 of file CachingFileMgr.h.

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

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

Definition at line 132 of file CachingFileMgr.h.

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

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

Definition at line 128 of file CachingFileMgr.h.

Referenced by TableFileMgr().

bool File_Namespace::TableFileMgr::is_checkpointed_ = true
private

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

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

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

Definition at line 129 of file CachingFileMgr.h.

Referenced by deleteWrapperFile(), and writeWrapperFile().


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