OmniSciDB  72c90bc290
 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...
 
bool hasWrapperFile () const
 

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
 
heavyai::shared_mutex table_mutex_
 

Detailed Description

Definition at line 98 of file CachingFileMgr.h.

Constructor & Destructor Documentation

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

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

758  : table_path_(table_path)
761  , epoch_(Epoch())
762  , is_checkpointed_(true) {
763  if (!bf::exists(table_path_)) {
764  bf::create_directory(table_path_);
765  } else {
766  CHECK(bf::is_directory(table_path_)) << "Specified path '" << table_path_
767  << "' for cache table data is not a directory.";
768  }
769  if (bf::exists(epoch_file_path_)) {
770  CHECK(bf::is_regular_file(epoch_file_path_))
771  << "Found epoch file '" << epoch_file_path_ << "' which is not a regular file";
773  << "Found epoch file '" << epoch_file_path_ << "' which is not of expected size";
776  } else {
779  incrementEpoch();
780  }
781 }
int8_t * storage_ptr()
Definition: Epoch.h:61
void writeAndSyncEpochToDisk()
Write and flush the epoch to the epoch file on disk.
std::pair< FILE *, std::string > create(const std::string &basePath, const int fileId, const size_t pageSize, const size_t numPages)
Definition: File.cpp:55
void incrementEpoch()
increment the epoch for this subdir (not synced to disk).
size_t read(FILE *f, const size_t offset, const size_t size, int8_t *buf, const std::string &file_path)
Reads the specified number of bytes from the offset position in file f into buf.
Definition: File.cpp:125
static constexpr char EPOCH_FILENAME[]
Definition: FileMgr.h:400
Definition: Epoch.h:30
static size_t byte_size()
Definition: Epoch.h:63
static constexpr char WRAPPER_FILE_NAME[]
FILE * open(int file_id)
Opens the file with the given id; fatal crash on error.
Definition: File.cpp:100
#define CHECK(condition)
Definition: Logger.h:291
size_t file_size(const int fd)
Definition: heavyai_fs.cpp:33

+ Here is the call graph for this function:

File_Namespace::TableFileMgr::~TableFileMgr ( )
inline

Definition at line 101 of file CachingFileMgr.h.

References File_Namespace::close(), and epoch_file_.

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

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

References table_mutex_, and wrapper_file_path_.

827  {
829  bf::remove_all(wrapper_file_path_);
830 }
heavyai::shared_mutex table_mutex_
std::unique_lock< T > unique_lock
int32_t File_Namespace::TableFileMgr::getEpoch ( ) const

Returns the current epoch (locked)

Definition at line 792 of file CachingFileMgr.cpp.

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

792  {
794  return static_cast<int32_t>(epoch_.ceiling());
795 }
int32_t ceiling() const
Definition: Epoch.h:44
std::shared_lock< T > shared_lock
heavyai::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 816 of file CachingFileMgr.cpp.

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

816  {
818  size_t space = 0;
819  for (const auto& file : bf::recursive_directory_iterator(table_path_)) {
820  if (bf::is_regular_file(file.path())) {
821  space += bf::file_size(file.path());
822  }
823  }
824  return space;
825 }
std::shared_lock< T > shared_lock
heavyai::shared_mutex table_mutex_
size_t file_size(const int fd)
Definition: heavyai_fs.cpp:33

+ Here is the call graph for this function:

bool File_Namespace::TableFileMgr::hasWrapperFile ( ) const

Checks if data wrapper file has been written to disk/cached.

Definition at line 842 of file CachingFileMgr.cpp.

References table_mutex_, and wrapper_file_path_.

842  {
844  return bf::exists(wrapper_file_path_);
845 }
std::shared_lock< T > shared_lock
heavyai::shared_mutex table_mutex_
void File_Namespace::TableFileMgr::incrementEpoch ( )

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

Definition at line 783 of file CachingFileMgr.cpp.

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

Referenced by TableFileMgr().

783  {
785  epoch_.increment();
786  is_checkpointed_ = false;
788  << "Epoch greater than maximum allowed value (" << epoch_.ceiling() << " > "
789  << Epoch::max_allowable_epoch() << ").";
790 }
int32_t ceiling() const
Definition: Epoch.h:44
static int64_t max_allowable_epoch()
Definition: Epoch.h:69
heavyai::shared_mutex table_mutex_
int32_t increment()
Definition: Epoch.h:54
std::unique_lock< T > unique_lock
#define CHECK(condition)
Definition: Logger.h:291

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

References table_mutex_, and table_path_.

811  {
813  bf::remove_all(table_path_);
814 }
heavyai::shared_mutex table_mutex_
std::unique_lock< T > unique_lock
void File_Namespace::TableFileMgr::writeAndSyncEpochToDisk ( )

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

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

797  {
800  int32_t status = fflush(epoch_file_);
801  CHECK(status == 0) << "Could not flush epoch file to disk";
802 #ifdef __APPLE__
803  status = fcntl(fileno(epoch_file_), 51);
804 #else
805  status = heavyai::fsync(fileno(epoch_file_));
806 #endif
807  CHECK(status == 0) << "Could not sync epoch file to disk";
808  is_checkpointed_ = true;
809 }
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:143
heavyai::shared_mutex table_mutex_
std::unique_lock< T > unique_lock
static size_t byte_size()
Definition: Epoch.h:63
int fsync(int fd)
Definition: heavyai_fs.cpp:62
#define CHECK(condition)
Definition: Logger.h:291

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

References table_mutex_, and wrapper_file_path_.

832  {
834  std::ofstream ofs(wrapper_file_path_);
835  if (!ofs) {
836  throw std::runtime_error{"Error trying to create file \"" + wrapper_file_path_ +
837  "\". The error was: " + std::strerror(errno)};
838  }
839  ofs << doc;
840 }
heavyai::shared_mutex table_mutex_
std::unique_lock< T > unique_lock

Member Data Documentation

Epoch File_Namespace::TableFileMgr::epoch_
private

Definition at line 147 of file CachingFileMgr.h.

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

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

Definition at line 149 of file CachingFileMgr.h.

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

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

Definition at line 145 of file CachingFileMgr.h.

Referenced by TableFileMgr().

bool File_Namespace::TableFileMgr::is_checkpointed_ = true
private

Definition at line 148 of file CachingFileMgr.h.

Referenced by incrementEpoch(), and writeAndSyncEpochToDisk().

heavyai::shared_mutex File_Namespace::TableFileMgr::table_mutex_
mutableprivate
std::string File_Namespace::TableFileMgr::table_path_
private

Definition at line 144 of file CachingFileMgr.h.

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

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

Definition at line 146 of file CachingFileMgr.h.

Referenced by deleteWrapperFile(), hasWrapperFile(), and writeWrapperFile().


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