OmniSciDB  72c90bc290
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
File_Namespace::GlobalFileMgr Class Reference

#include <GlobalFileMgr.h>

+ Inheritance diagram for File_Namespace::GlobalFileMgr:
+ Collaboration diagram for File_Namespace::GlobalFileMgr:

Public Member Functions

 GlobalFileMgr (const int32_t device_id, std::shared_ptr< ForeignStorageInterface > fsi, std::string base_path=".", const size_t num_reader_threads=0, const size_t page_size=DEFAULT_PAGE_SIZE, const size_t metadata_page_size=DEFAULT_METADATA_PAGE_SIZE)
 Constructor. More...
 
 ~GlobalFileMgr () override
 
AbstractBuffercreateBuffer (const ChunkKey &key, size_t pageSize=0, const size_t numBytes=0) override
 Creates a chunk with the specified key and page size. More...
 
bool isBufferOnDevice (const ChunkKey &key) override
 
void deleteBuffer (const ChunkKey &key, const bool purge=true) override
 Deletes the chunk with the specified key. More...
 
void deleteBuffersWithPrefix (const ChunkKey &keyPrefix, const bool purge=true) override
 
AbstractBuffergetBuffer (const ChunkKey &key, const size_t numBytes=0) override
 Returns the a pointer to the chunk with the specified key. More...
 
void fetchBuffer (const ChunkKey &key, AbstractBuffer *destBuffer, const size_t numBytes) override
 
AbstractBufferputBuffer (const ChunkKey &key, AbstractBuffer *d, const size_t numBytes=0) override
 Puts the contents of d into the Chunk with the given key. More...
 
AbstractBufferalloc (const size_t numBytes) override
 
void free (AbstractBuffer *buffer) override
 
MgrType getMgrType () override
 
std::string getStringMgrType () override
 
std::string printSlabs () override
 
size_t getMaxSize () override
 
size_t getInUseSize () override
 
size_t getAllocated () override
 
bool isAllocationCapped () override
 
void init ()
 
void getChunkMetadataVecForKeyPrefix (ChunkMetadataVector &chunkMetadataVec, const ChunkKey &keyPrefix) override
 
void checkpoint () override
 Fsyncs data files, writes out epoch and fsyncs that. More...
 
void checkpoint (const int32_t db_id, const int32_t tb_id) override
 
size_t getNumReaderThreads ()
 Returns number of threads defined by parameter num-reader-threads which should be used during initial load and consequent read of data. More...
 
size_t getNumChunks () override
 
void compactDataFiles (const int32_t db_id, const int32_t tb_id)
 
AbstractBufferMgrfindFileMgr (const int32_t db_id, const int32_t tb_id)
 
void setFileMgrParams (const int32_t db_id, const int32_t tb_id, const FileMgrParams &file_mgr_params)
 
AbstractBufferMgrgetFileMgr (const int32_t db_id, const int32_t tb_id)
 
AbstractBufferMgrgetFileMgr (const ChunkKey &key)
 
std::string getBasePath () const
 
size_t getPageSize () const
 
size_t getMetadataPageSize () const
 
void writeFileMgrData (FileMgr *fileMgr=0)
 
bool getDBConvert () const
 
void setDBConvert (bool val)
 
void removeTableRelatedDS (const int32_t db_id, const int32_t tb_id) override
 
void setTableEpoch (const int32_t db_id, const int32_t tb_id, const int32_t start_epoch)
 
size_t getTableEpoch (const int32_t db_id, const int32_t tb_id)
 
void resetTableEpochFloor (const int32_t db_id, const int32_t tb_id)
 
StorageStats getStorageStats (const int32_t db_id, const int32_t tb_id)
 
std::shared_ptr< FileMgrgetSharedFileMgr (const int db_id, const int table_id)
 
void setFileMgr (const int db_id, const int table_id, std::shared_ptr< FileMgr > file_mgr)
 
void closeFileMgr (const int32_t db_id, const int32_t tb_id)
 

Static Public Attributes

static constexpr int32_t db_version_ {2}
 

Protected Attributes

std::shared_ptr
< ForeignStorageInterface
fsi_
 

Private Member Functions

AbstractBufferMgrfindFileMgrUnlocked (const int32_t db_id, const int32_t tb_id)
 
void deleteFileMgr (const int32_t db_id, const int32_t tb_id)
 
bool existsDiffBetweenFileMgrParamsAndFileMgr (FileMgr *file_mgr, const FileMgrParams &file_mgr_params) const
 

Private Attributes

std::string basePath_
 
size_t num_reader_threads_
 The OS file system path containing the files. More...
 
int32_t epoch_
 number of threads used when loading data More...
 
const size_t page_size_
 
const size_t metadata_page_size_
 used to set FileMgr page_size_ More...
 
bool dbConvert_
 used to set FileMgr metadta_page_size_ More...
 
std::map< TablePair,
std::shared_ptr< FileMgr > > 
ownedFileMgrs_
 
std::map< TablePair,
AbstractBufferMgr * > 
allFileMgrs_
 
std::map< TablePair, int32_t > max_rollback_epochs_per_table_
 
std::map< TablePair, StorageStatslazy_initialized_stats_
 
heavyai::shared_mutex fileMgrs_mutex_
 

Detailed Description

Definition at line 52 of file GlobalFileMgr.h.

Constructor & Destructor Documentation

File_Namespace::GlobalFileMgr::GlobalFileMgr ( const int32_t  device_id,
std::shared_ptr< ForeignStorageInterface fsi,
std::string  base_path = ".",
const size_t  num_reader_threads = 0,
const size_t  page_size = DEFAULT_PAGE_SIZE,
const size_t  metadata_page_size = DEFAULT_METADATA_PAGE_SIZE 
)

Constructor.

Definition at line 42 of file GlobalFileMgr.cpp.

References dbConvert_, and init().

48  : AbstractBufferMgr(device_id)
49  , fsi_(fsi)
50  , basePath_(base_path)
51  , num_reader_threads_(num_reader_threads)
52  , epoch_(-1) // set the default epoch for all tables corresponding to the time of
53  // last checkpoint
54  , page_size_(page_size)
55  , metadata_page_size_(metadata_page_size) {
56  // DS changes also triggered by individual FileMgr per table project (release 2.1.0)
57  dbConvert_ = false;
58  init();
59 }
int32_t epoch_
number of threads used when loading data
std::shared_ptr< ForeignStorageInterface > fsi_
const size_t metadata_page_size_
used to set FileMgr page_size_
size_t num_reader_threads_
The OS file system path containing the files.
bool dbConvert_
used to set FileMgr metadta_page_size_

+ Here is the call graph for this function:

File_Namespace::GlobalFileMgr::~GlobalFileMgr ( )
inlineoverride

Definition at line 63 of file GlobalFileMgr.h.

63 {}

Member Function Documentation

AbstractBuffer* File_Namespace::GlobalFileMgr::alloc ( const size_t  numBytes)
inlineoverride

Definition at line 111 of file GlobalFileMgr.h.

References logger::FATAL, and LOG.

111  {
112  LOG(FATAL) << "Operation not supported";
113  return nullptr; // satisfy return-type warning
114  }
#define LOG(tag)
Definition: Logger.h:285
void File_Namespace::GlobalFileMgr::checkpoint ( )
override

Fsyncs data files, writes out epoch and fsyncs that.

Definition at line 78 of file GlobalFileMgr.cpp.

References allFileMgrs_, and fileMgrs_mutex_.

Referenced by File_Namespace::CachingGlobalFileMgr::checkpoint().

78  {
80  for (auto fileMgrsIt = allFileMgrs_.begin(); fileMgrsIt != allFileMgrs_.end();
81  ++fileMgrsIt) {
82  fileMgrsIt->second->checkpoint();
83  }
84 }
std::map< TablePair, AbstractBufferMgr * > allFileMgrs_
std::unique_lock< T > unique_lock
heavyai::shared_mutex fileMgrs_mutex_

+ Here is the caller graph for this function:

void File_Namespace::GlobalFileMgr::checkpoint ( const int32_t  db_id,
const int32_t  tb_id 
)
override

Definition at line 86 of file GlobalFileMgr.cpp.

References getFileMgr().

86  {
87  getFileMgr(db_id, tb_id)->checkpoint();
88 }
AbstractBufferMgr * getFileMgr(const int32_t db_id, const int32_t tb_id)

+ Here is the call graph for this function:

void File_Namespace::GlobalFileMgr::closeFileMgr ( const int32_t  db_id,
const int32_t  tb_id 
)

Definition at line 134 of file GlobalFileMgr.cpp.

References deleteFileMgr(), and fileMgrs_mutex_.

134  {
136  deleteFileMgr(db_id, tb_id);
137 }
void deleteFileMgr(const int32_t db_id, const int32_t tb_id)
std::unique_lock< T > unique_lock
heavyai::shared_mutex fileMgrs_mutex_

+ Here is the call graph for this function:

void File_Namespace::GlobalFileMgr::compactDataFiles ( const int32_t  db_id,
const int32_t  tb_id 
)

Definition at line 335 of file GlobalFileMgr.cpp.

References deleteFileMgr(), fileMgrs_mutex_, findFileMgr(), and getFileMgr().

Referenced by TableOptimizer::vacuumDeletedRows().

335  {
336  auto file_mgr = dynamic_cast<File_Namespace::FileMgr*>(findFileMgr(db_id, tb_id));
337  {
339  if (file_mgr) {
340  file_mgr->compactFiles();
341  deleteFileMgr(db_id, tb_id);
342  }
343  }
344 
345  // Re-initialize file manager
346  getFileMgr(db_id, tb_id);
347 }
void deleteFileMgr(const int32_t db_id, const int32_t tb_id)
std::unique_lock< T > unique_lock
AbstractBufferMgr * getFileMgr(const int32_t db_id, const int32_t tb_id)
AbstractBufferMgr * findFileMgr(const int32_t db_id, const int32_t tb_id)
heavyai::shared_mutex fileMgrs_mutex_

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

AbstractBuffer* File_Namespace::GlobalFileMgr::createBuffer ( const ChunkKey key,
size_t  pageSize = 0,
const size_t  numBytes = 0 
)
inlineoverride

Creates a chunk with the specified key and page size.

Definition at line 66 of file GlobalFileMgr.h.

Referenced by File_Namespace::CachingGlobalFileMgr::createBuffer().

68  {
69  return getFileMgr(key)->createBuffer(key, pageSize, numBytes);
70  }
AbstractBufferMgr * getFileMgr(const int32_t db_id, const int32_t tb_id)

+ Here is the caller graph for this function:

void File_Namespace::GlobalFileMgr::deleteBuffer ( const ChunkKey key,
const bool  purge = true 
)
inlineoverride

Deletes the chunk with the specified key.

Definition at line 80 of file GlobalFileMgr.h.

Referenced by File_Namespace::CachingGlobalFileMgr::deleteBuffer().

80  {
81  return getFileMgr(key)->deleteBuffer(key, purge);
82  }
AbstractBufferMgr * getFileMgr(const int32_t db_id, const int32_t tb_id)

+ Here is the caller graph for this function:

void File_Namespace::GlobalFileMgr::deleteBuffersWithPrefix ( const ChunkKey keyPrefix,
const bool  purge = true 
)
override

Definition at line 101 of file GlobalFileMgr.cpp.

References getFileMgr().

Referenced by File_Namespace::CachingGlobalFileMgr::deleteBuffersWithPrefix().

101  {
102  /* keyPrefix[0] can be -1 only for gpu or cpu buffers but not for FileMgr.
103  * There is no assert here, as GlobalFileMgr is being called with -1 value as well in
104  * the same loop with other buffers. So the case of -1 will just be ignored, as nothing
105  * needs to be done.
106  */
107  if (keyPrefix[0] != -1) {
108  return getFileMgr(keyPrefix)->deleteBuffersWithPrefix(keyPrefix, purge);
109  }
110 }
AbstractBufferMgr * getFileMgr(const int32_t db_id, const int32_t tb_id)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void File_Namespace::GlobalFileMgr::deleteFileMgr ( const int32_t  db_id,
const int32_t  tb_id 
)
private

Definition at line 123 of file GlobalFileMgr.cpp.

References allFileMgrs_, and ownedFileMgrs_.

Referenced by closeFileMgr(), compactDataFiles(), removeTableRelatedDS(), setFileMgrParams(), and setTableEpoch().

123  {
124  // NOTE: only call this private function after locking is already in place
125  const auto file_mgr_key = std::make_pair(db_id, tb_id);
126  if (auto it = ownedFileMgrs_.find(file_mgr_key); it != ownedFileMgrs_.end()) {
127  ownedFileMgrs_.erase(it);
128  }
129  if (auto it = allFileMgrs_.find(file_mgr_key); it != allFileMgrs_.end()) {
130  allFileMgrs_.erase(it);
131  }
132 }
std::map< TablePair, std::shared_ptr< FileMgr > > ownedFileMgrs_
std::map< TablePair, AbstractBufferMgr * > allFileMgrs_

+ Here is the caller graph for this function:

bool File_Namespace::GlobalFileMgr::existsDiffBetweenFileMgrParamsAndFileMgr ( FileMgr file_mgr,
const FileMgrParams file_mgr_params 
) const
private

Definition at line 139 of file GlobalFileMgr.cpp.

References File_Namespace::FileMgrParams::epoch, File_Namespace::FileMgr::lastCheckpointedEpoch(), File_Namespace::FileMgrParams::max_rollback_epochs, and File_Namespace::FileMgr::maxRollbackEpochs().

141  {
142  if (file_mgr_params.epoch != -1 &&
143  file_mgr_params.epoch != file_mgr->lastCheckpointedEpoch()) {
144  return true;
145  }
146  if (file_mgr_params.max_rollback_epochs != -1 &&
147  file_mgr_params.max_rollback_epochs != file_mgr->maxRollbackEpochs()) {
148  return true;
149  }
150  return false;
151 }

+ Here is the call graph for this function:

void File_Namespace::GlobalFileMgr::fetchBuffer ( const ChunkKey key,
AbstractBuffer destBuffer,
const size_t  numBytes 
)
inlineoverride

Definition at line 92 of file GlobalFileMgr.h.

Referenced by File_Namespace::CachingGlobalFileMgr::checkpoint(), and File_Namespace::CachingGlobalFileMgr::fetchBuffer().

94  {
95  return getFileMgr(key)->fetchBuffer(key, destBuffer, numBytes);
96  }
AbstractBufferMgr * getFileMgr(const int32_t db_id, const int32_t tb_id)

+ Here is the caller graph for this function:

AbstractBufferMgr* File_Namespace::GlobalFileMgr::findFileMgr ( const int32_t  db_id,
const int32_t  tb_id 
)
inline

Definition at line 158 of file GlobalFileMgr.h.

Referenced by compactDataFiles(), File_Namespace::CachingGlobalFileMgr::fetchBuffer(), getStorageStats(), getTableEpoch(), setFileMgrParams(), and setTableEpoch().

158  {
160  return findFileMgrUnlocked(db_id, tb_id);
161  }
std::shared_lock< T > shared_lock
AbstractBufferMgr * findFileMgrUnlocked(const int32_t db_id, const int32_t tb_id)
heavyai::shared_mutex fileMgrs_mutex_

+ Here is the caller graph for this function:

AbstractBufferMgr * File_Namespace::GlobalFileMgr::findFileMgrUnlocked ( const int32_t  db_id,
const int32_t  tb_id 
)
private

Definition at line 112 of file GlobalFileMgr.cpp.

References allFileMgrs_.

Referenced by getFileMgr(), and removeTableRelatedDS().

113  {
114  // NOTE: only call this private function after locking is already in place
115  AbstractBufferMgr* fm = nullptr;
116  const auto file_mgr_key = std::make_pair(db_id, tb_id);
117  if (auto it = allFileMgrs_.find(file_mgr_key); it != allFileMgrs_.end()) {
118  fm = it->second;
119  }
120  return fm;
121 }
std::map< TablePair, AbstractBufferMgr * > allFileMgrs_

+ Here is the caller graph for this function:

void File_Namespace::GlobalFileMgr::free ( AbstractBuffer buffer)
inlineoverride

Definition at line 116 of file GlobalFileMgr.h.

References logger::FATAL, and LOG.

116 { LOG(FATAL) << "Operation not supported"; }
#define LOG(tag)
Definition: Logger.h:285
size_t File_Namespace::GlobalFileMgr::getAllocated ( )
inlineoverride

Definition at line 123 of file GlobalFileMgr.h.

123 { return 0; }
std::string File_Namespace::GlobalFileMgr::getBasePath ( ) const
inline

Definition at line 170 of file GlobalFileMgr.h.

Referenced by anonymous_namespace{TableArchiver.cpp}::abs_path(), File_Namespace::FileMgr::coreInit(), and File_Namespace::FileMgr::FileMgr().

170 { return basePath_; }

+ Here is the caller graph for this function:

AbstractBuffer* File_Namespace::GlobalFileMgr::getBuffer ( const ChunkKey key,
const size_t  numBytes = 0 
)
inlineoverride

Returns the a pointer to the chunk with the specified key.

Definition at line 88 of file GlobalFileMgr.h.

Referenced by File_Namespace::CachingGlobalFileMgr::checkpoint().

88  {
89  return getFileMgr(key)->getBuffer(key, numBytes);
90  }
AbstractBufferMgr * getFileMgr(const int32_t db_id, const int32_t tb_id)

+ Here is the caller graph for this function:

void File_Namespace::GlobalFileMgr::getChunkMetadataVecForKeyPrefix ( ChunkMetadataVector chunkMetadataVec,
const ChunkKey keyPrefix 
)
inlineoverride

Definition at line 128 of file GlobalFileMgr.h.

Referenced by File_Namespace::CachingGlobalFileMgr::getChunkMetadataVecForKeyPrefix().

129  {
130  return getFileMgr(keyPrefix)->getChunkMetadataVecForKeyPrefix(chunkMetadataVec,
131  keyPrefix);
132  }
AbstractBufferMgr * getFileMgr(const int32_t db_id, const int32_t tb_id)

+ Here is the caller graph for this function:

bool File_Namespace::GlobalFileMgr::getDBConvert ( ) const
inline

Definition at line 176 of file GlobalFileMgr.h.

Referenced by File_Namespace::FileMgr::getDBConvert().

176 { return dbConvert_; }
bool dbConvert_
used to set FileMgr metadta_page_size_

+ Here is the caller graph for this function:

AbstractBufferMgr * File_Namespace::GlobalFileMgr::getFileMgr ( const int32_t  db_id,
const int32_t  tb_id 
)

Definition at line 179 of file GlobalFileMgr.cpp.

References allFileMgrs_, CHECK, epoch_, fileMgrs_mutex_, findFileMgrUnlocked(), fsi_, lazy_initialized_stats_, max_rollback_epochs_per_table_, num_reader_threads_, and ownedFileMgrs_.

Referenced by checkpoint(), compactDataFiles(), deleteBuffersWithPrefix(), File_Namespace::FileMgr::init(), and resetTableEpochFloor().

179  {
180  { // check if FileMgr already exists for (db_id, tb_id)
182  AbstractBufferMgr* fm = findFileMgrUnlocked(db_id, tb_id);
183  if (fm) {
184  return fm;
185  }
186  }
187 
188  { // create new FileMgr for (db_id, tb_id)
190  AbstractBufferMgr* fm = findFileMgrUnlocked(db_id, tb_id);
191  if (fm) {
192  return fm; // mgr was added between the read lock and the write lock
193  }
194  const auto file_mgr_key = std::make_pair(db_id, tb_id);
195  const auto foreign_buffer_manager = fsi_->lookupBufferManager(db_id, tb_id);
196  if (foreign_buffer_manager) {
197  CHECK(allFileMgrs_.insert(std::make_pair(file_mgr_key, foreign_buffer_manager))
198  .second);
199  return foreign_buffer_manager;
200  } else {
201  int32_t max_rollback_epochs{-1};
202  if (max_rollback_epochs_per_table_.find(file_mgr_key) !=
204  max_rollback_epochs = max_rollback_epochs_per_table_[file_mgr_key];
205  }
206  auto s = std::make_shared<FileMgr>(
207  0, this, file_mgr_key, max_rollback_epochs, num_reader_threads_, epoch_);
208  CHECK(ownedFileMgrs_.insert(std::make_pair(file_mgr_key, s)).second);
209  CHECK(allFileMgrs_.insert(std::make_pair(file_mgr_key, s.get())).second);
210  lazy_initialized_stats_.erase(file_mgr_key);
211  return s.get();
212  }
213  }
214 }
int32_t epoch_
number of threads used when loading data
std::shared_ptr< ForeignStorageInterface > fsi_
std::map< TablePair, std::shared_ptr< FileMgr > > ownedFileMgrs_
std::shared_lock< T > shared_lock
std::map< TablePair, AbstractBufferMgr * > allFileMgrs_
AbstractBufferMgr * findFileMgrUnlocked(const int32_t db_id, const int32_t tb_id)
std::unique_lock< T > unique_lock
size_t num_reader_threads_
The OS file system path containing the files.
std::map< TablePair, int32_t > max_rollback_epochs_per_table_
#define CHECK(condition)
Definition: Logger.h:291
std::map< TablePair, StorageStats > lazy_initialized_stats_
heavyai::shared_mutex fileMgrs_mutex_

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

AbstractBufferMgr* File_Namespace::GlobalFileMgr::getFileMgr ( const ChunkKey key)
inline

Definition at line 166 of file GlobalFileMgr.h.

166  {
167  return getFileMgr(key[0], key[1]);
168  }
AbstractBufferMgr * getFileMgr(const int32_t db_id, const int32_t tb_id)
size_t File_Namespace::GlobalFileMgr::getInUseSize ( )
inlineoverride

Definition at line 122 of file GlobalFileMgr.h.

122 { return 0; }
size_t File_Namespace::GlobalFileMgr::getMaxSize ( )
inlineoverride

Definition at line 121 of file GlobalFileMgr.h.

121 { return 0; }
size_t File_Namespace::GlobalFileMgr::getMetadataPageSize ( ) const
inline

Definition at line 172 of file GlobalFileMgr.h.

172 { return metadata_page_size_; }
const size_t metadata_page_size_
used to set FileMgr page_size_
MgrType File_Namespace::GlobalFileMgr::getMgrType ( )
inlineoverride

Definition at line 118 of file GlobalFileMgr.h.

118 { return GLOBAL_FILE_MGR; };
size_t File_Namespace::GlobalFileMgr::getNumChunks ( )
override

Definition at line 90 of file GlobalFileMgr.cpp.

References allFileMgrs_, and fileMgrs_mutex_.

90  {
92  size_t num_chunks = 0;
93  for (auto fileMgrsIt = allFileMgrs_.begin(); fileMgrsIt != allFileMgrs_.end();
94  ++fileMgrsIt) {
95  num_chunks += fileMgrsIt->second->getNumChunks();
96  }
97 
98  return num_chunks;
99 }
std::shared_lock< T > shared_lock
std::map< TablePair, AbstractBufferMgr * > allFileMgrs_
heavyai::shared_mutex fileMgrs_mutex_
size_t File_Namespace::GlobalFileMgr::getNumReaderThreads ( )
inline

Returns number of threads defined by parameter num-reader-threads which should be used during initial load and consequent read of data.

Definition at line 145 of file GlobalFileMgr.h.

145 { return num_reader_threads_; }
size_t num_reader_threads_
The OS file system path containing the files.
size_t File_Namespace::GlobalFileMgr::getPageSize ( ) const
inline

Definition at line 171 of file GlobalFileMgr.h.

171 { return page_size_; }
std::shared_ptr< FileMgr > File_Namespace::GlobalFileMgr::getSharedFileMgr ( const int  db_id,
const int  table_id 
)

Definition at line 217 of file GlobalFileMgr.cpp.

References ownedFileMgrs_.

218  {
219  const auto table_key = std::make_pair(db_id, table_id);
220  if (ownedFileMgrs_.find(table_key) == ownedFileMgrs_.end()) {
221  return nullptr;
222  }
223  return ownedFileMgrs_[table_key];
224 }
std::map< TablePair, std::shared_ptr< FileMgr > > ownedFileMgrs_
StorageStats File_Namespace::GlobalFileMgr::getStorageStats ( const int32_t  db_id,
const int32_t  tb_id 
)

Definition at line 316 of file GlobalFileMgr.cpp.

References fileMgrs_mutex_, findFileMgr(), and lazy_initialized_stats_.

316  {
318  AbstractBufferMgr* opened_fm = findFileMgr(db_id, tb_id);
319  if (opened_fm) {
320  return dynamic_cast<FileMgr*>(opened_fm)->getStorageStats();
321  }
322  TablePair file_mgr_key{db_id, tb_id};
323  auto it = lazy_initialized_stats_.find(file_mgr_key);
324  if (it != lazy_initialized_stats_.end()) {
325  return it->second;
326  } else {
327  // Do not do full init of table just to get storage stats, just check file instead
328  auto u = std::make_unique<FileMgr>(0, this, file_mgr_key, true);
329  lazy_initialized_stats_[file_mgr_key] = u->getStorageStats();
330  u.reset();
331  return lazy_initialized_stats_[file_mgr_key];
332  }
333 }
std::shared_lock< T > shared_lock
StorageStats getStorageStats(const int32_t db_id, const int32_t tb_id)
AbstractBufferMgr * findFileMgr(const int32_t db_id, const int32_t tb_id)
std::map< TablePair, StorageStats > lazy_initialized_stats_
std::pair< const int32_t, const int32_t > TablePair
Definition: FileMgr.h:98
heavyai::shared_mutex fileMgrs_mutex_

+ Here is the call graph for this function:

std::string File_Namespace::GlobalFileMgr::getStringMgrType ( )
inlineoverride

Definition at line 119 of file GlobalFileMgr.h.

119 { return ToString(GLOBAL_FILE_MGR); }
size_t File_Namespace::GlobalFileMgr::getTableEpoch ( const int32_t  db_id,
const int32_t  tb_id 
)

Definition at line 294 of file GlobalFileMgr.cpp.

References fileMgrs_mutex_, and findFileMgr().

294  {
295  // UX change was made to this function Oct 2020 to return checkpointed epoch. In turn,
296  // setTableEpoch was changed to set the epoch at the user's input, instead of input - 1
298  AbstractBufferMgr* opened_fm = findFileMgr(db_id, tb_id);
299  if (opened_fm) {
300  return dynamic_cast<FileMgr*>(opened_fm)->lastCheckpointedEpoch();
301  }
302  // Do not do full init of table just to get table epoch, just check file instead
303  const auto file_mgr_key = std::make_pair(db_id, tb_id);
304  auto u = std::make_unique<FileMgr>(0, this, file_mgr_key, true);
305  const auto epoch = u->lastCheckpointedEpoch();
306  u.reset();
307  return epoch;
308 }
std::shared_lock< T > shared_lock
AbstractBufferMgr * findFileMgr(const int32_t db_id, const int32_t tb_id)
heavyai::shared_mutex fileMgrs_mutex_

+ Here is the call graph for this function:

void File_Namespace::GlobalFileMgr::init ( )

Definition at line 61 of file GlobalFileMgr.cpp.

References basePath_, logger::FATAL, and LOG.

Referenced by GlobalFileMgr().

61  {
62  // check if basePath_ already exists, and if not create one
63  boost::filesystem::path path(basePath_);
64  if (basePath_.size() > 0 && basePath_[basePath_.size() - 1] != '/') {
65  basePath_.push_back('/');
66  }
67  if (boost::filesystem::exists(path)) {
68  if (!boost::filesystem::is_directory(path)) {
69  LOG(FATAL) << "Specified path is not a directory.";
70  }
71  } else { // data directory does not exist
72  if (!boost::filesystem::create_directory(path)) {
73  LOG(FATAL) << "Could not create data directory";
74  }
75  }
76 }
#define LOG(tag)
Definition: Logger.h:285

+ Here is the caller graph for this function:

bool File_Namespace::GlobalFileMgr::isAllocationCapped ( )
inlineoverride

Definition at line 124 of file GlobalFileMgr.h.

124 { return false; }
bool File_Namespace::GlobalFileMgr::isBufferOnDevice ( const ChunkKey key)
inlineoverride

Definition at line 72 of file GlobalFileMgr.h.

72  {
73  return getFileMgr(key)->isBufferOnDevice(key);
74  }
AbstractBufferMgr * getFileMgr(const int32_t db_id, const int32_t tb_id)
std::string File_Namespace::GlobalFileMgr::printSlabs ( )
inlineoverride

Definition at line 120 of file GlobalFileMgr.h.

120 { return "Not Implemented"; }
AbstractBuffer* File_Namespace::GlobalFileMgr::putBuffer ( const ChunkKey key,
AbstractBuffer d,
const size_t  numBytes = 0 
)
inlineoverride

Puts the contents of d into the Chunk with the given key.

Parameters
key- Unique identifier for a Chunk.
d- An object representing the source data for the Chunk.
Returns
AbstractBuffer*

Definition at line 104 of file GlobalFileMgr.h.

Referenced by File_Namespace::CachingGlobalFileMgr::putBuffer().

106  {
107  return getFileMgr(key)->putBuffer(key, d, numBytes);
108  }
AbstractBufferMgr * getFileMgr(const int32_t db_id, const int32_t tb_id)

+ Here is the caller graph for this function:

void File_Namespace::GlobalFileMgr::removeTableRelatedDS ( const int32_t  db_id,
const int32_t  tb_id 
)
override

Definition at line 253 of file GlobalFileMgr.cpp.

References deleteFileMgr(), fileMgrs_mutex_, findFileMgrUnlocked(), fsi_, and max_rollback_epochs_per_table_.

Referenced by File_Namespace::CachingGlobalFileMgr::removeTableRelatedDS().

253  {
255  auto abm = findFileMgrUnlocked(db_id, tb_id);
256  if (auto fm = dynamic_cast<File_Namespace::FileMgr*>(abm)) {
257  fm->closeRemovePhysical();
258  } else if (dynamic_cast<ForeignStorageBufferMgr*>(abm)) {
259  abm->removeTableRelatedDS(db_id, tb_id);
260  fsi_->dropBufferManager(db_id, tb_id);
261  } else {
262  // fileMgr has not been initialized so there is no need to
263  // spend the time initializing
264  // initialize just enough to have to rename
265  const auto file_mgr_key = std::make_pair(db_id, tb_id);
266  auto u = std::make_unique<FileMgr>(0, this, file_mgr_key, true);
267  u->closeRemovePhysical();
268  }
269  // remove table related in-memory DS only if directory was removed successfully
270 
271  deleteFileMgr(db_id, tb_id);
272  max_rollback_epochs_per_table_.erase({db_id, tb_id});
273 }
void deleteFileMgr(const int32_t db_id, const int32_t tb_id)
std::shared_ptr< ForeignStorageInterface > fsi_
AbstractBufferMgr * findFileMgrUnlocked(const int32_t db_id, const int32_t tb_id)
std::unique_lock< T > unique_lock
std::map< TablePair, int32_t > max_rollback_epochs_per_table_
heavyai::shared_mutex fileMgrs_mutex_

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void File_Namespace::GlobalFileMgr::resetTableEpochFloor ( const int32_t  db_id,
const int32_t  tb_id 
)

Definition at line 310 of file GlobalFileMgr.cpp.

References CHECK, and getFileMgr().

310  {
311  AbstractBufferMgr* fm = getFileMgr(db_id, tb_id);
312  CHECK(fm);
313  dynamic_cast<FileMgr*>(fm)->resetEpochFloor();
314 }
AbstractBufferMgr * getFileMgr(const int32_t db_id, const int32_t tb_id)
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the call graph for this function:

void File_Namespace::GlobalFileMgr::setDBConvert ( bool  val)
inline

Definition at line 177 of file GlobalFileMgr.h.

177 { dbConvert_ = val; }
bool dbConvert_
used to set FileMgr metadta_page_size_
void File_Namespace::GlobalFileMgr::setFileMgr ( const int  db_id,
const int  table_id,
std::shared_ptr< FileMgr file_mgr 
)

Definition at line 227 of file GlobalFileMgr.cpp.

References allFileMgrs_, lazy_initialized_stats_, and ownedFileMgrs_.

229  {
230  TablePair file_mgr_key{db_id, table_id};
231  allFileMgrs_[file_mgr_key] = file_mgr.get();
232  ownedFileMgrs_[file_mgr_key] = file_mgr;
233  lazy_initialized_stats_.erase(file_mgr_key);
234 }
std::map< TablePair, std::shared_ptr< FileMgr > > ownedFileMgrs_
std::map< TablePair, AbstractBufferMgr * > allFileMgrs_
std::map< TablePair, StorageStats > lazy_initialized_stats_
std::pair< const int32_t, const int32_t > TablePair
Definition: FileMgr.h:98
void File_Namespace::GlobalFileMgr::setFileMgrParams ( const int32_t  db_id,
const int32_t  tb_id,
const FileMgrParams file_mgr_params 
)

Definition at line 153 of file GlobalFileMgr.cpp.

References allFileMgrs_, CHECK, deleteFileMgr(), File_Namespace::FileMgrParams::epoch, epoch_, fileMgrs_mutex_, findFileMgr(), lazy_initialized_stats_, File_Namespace::FileMgrParams::max_rollback_epochs, max_rollback_epochs_per_table_, num_reader_threads_, and ownedFileMgrs_.

155  {
156  auto fm = dynamic_cast<File_Namespace::FileMgr*>(findFileMgr(db_id, tb_id));
158  if (fm) {
159  deleteFileMgr(db_id, tb_id);
160  }
161  const auto file_mgr_key = std::make_pair(db_id, tb_id);
162  auto max_rollback_epochs =
163  (file_mgr_params.max_rollback_epochs >= 0 ? file_mgr_params.max_rollback_epochs
164  : -1);
165  auto s = std::make_shared<FileMgr>(
166  0,
167  this,
168  file_mgr_key,
169  max_rollback_epochs,
171  file_mgr_params.epoch != -1 ? file_mgr_params.epoch : epoch_);
172  CHECK(ownedFileMgrs_.insert(std::make_pair(file_mgr_key, s)).second);
173  CHECK(allFileMgrs_.insert(std::make_pair(file_mgr_key, s.get())).second);
174  max_rollback_epochs_per_table_[file_mgr_key] = max_rollback_epochs;
175  lazy_initialized_stats_.erase(file_mgr_key);
176  return;
177 }
void deleteFileMgr(const int32_t db_id, const int32_t tb_id)
int32_t epoch_
number of threads used when loading data
std::map< TablePair, std::shared_ptr< FileMgr > > ownedFileMgrs_
std::map< TablePair, AbstractBufferMgr * > allFileMgrs_
std::unique_lock< T > unique_lock
size_t num_reader_threads_
The OS file system path containing the files.
std::map< TablePair, int32_t > max_rollback_epochs_per_table_
#define CHECK(condition)
Definition: Logger.h:291
AbstractBufferMgr * findFileMgr(const int32_t db_id, const int32_t tb_id)
std::map< TablePair, StorageStats > lazy_initialized_stats_
heavyai::shared_mutex fileMgrs_mutex_

+ Here is the call graph for this function:

void File_Namespace::GlobalFileMgr::setTableEpoch ( const int32_t  db_id,
const int32_t  tb_id,
const int32_t  start_epoch 
)

Definition at line 275 of file GlobalFileMgr.cpp.

References deleteFileMgr(), findFileMgr(), and num_reader_threads_.

277  {
278  AbstractBufferMgr* opened_fm = findFileMgr(db_id, tb_id);
279  if (opened_fm) {
280  // Delete this FileMgr to ensure epoch change occurs in constructor with other
281  // reads/writes locked out
282  deleteFileMgr(db_id, tb_id);
283  }
284  const auto file_mgr_key = std::make_pair(db_id, tb_id);
285  // this is where the real rollback of any data ahead of the currently set epoch is
286  // performed
287  // Will call set_epoch with start_epoch internally
288  auto u = std::make_unique<FileMgr>(
289  0, this, file_mgr_key, -1, num_reader_threads_, start_epoch);
290  // remove the dummy one we built
291  u.reset();
292 }
void deleteFileMgr(const int32_t db_id, const int32_t tb_id)
size_t num_reader_threads_
The OS file system path containing the files.
AbstractBufferMgr * findFileMgr(const int32_t db_id, const int32_t tb_id)

+ Here is the call graph for this function:

void File_Namespace::GlobalFileMgr::writeFileMgrData ( FileMgr fileMgr = 0)

Definition at line 236 of file GlobalFileMgr.cpp.

References allFileMgrs_, CHECK, File_Namespace::FileMgr::chunkIndex_, and fileMgrs_mutex_.

237  { // this function is not used, keep it for now for future needs
239  for (auto fileMgrIt = allFileMgrs_.begin(); fileMgrIt != allFileMgrs_.end();
240  fileMgrIt++) {
241  FileMgr* fm = dynamic_cast<FileMgr*>(fileMgrIt->second);
242  CHECK(fm);
243  if ((fileMgr != 0) && (fileMgr != fm)) {
244  continue;
245  }
246  for (auto chunkIt = fm->chunkIndex_.begin(); chunkIt != fm->chunkIndex_.end();
247  chunkIt++) {
248  chunkIt->second->write((int8_t*)chunkIt->second, chunkIt->second->size(), 0);
249  }
250  }
251 }
std::shared_lock< T > shared_lock
std::map< TablePair, AbstractBufferMgr * > allFileMgrs_
#define CHECK(condition)
Definition: Logger.h:291
heavyai::shared_mutex fileMgrs_mutex_

Member Data Documentation

std::map<TablePair, AbstractBufferMgr*> File_Namespace::GlobalFileMgr::allFileMgrs_
private
std::string File_Namespace::GlobalFileMgr::basePath_
private

Definition at line 200 of file GlobalFileMgr.h.

Referenced by init().

constexpr int32_t File_Namespace::GlobalFileMgr::db_version_ {2}
static
bool File_Namespace::GlobalFileMgr::dbConvert_
private

used to set FileMgr metadta_page_size_

Definition at line 209 of file GlobalFileMgr.h.

Referenced by GlobalFileMgr().

int32_t File_Namespace::GlobalFileMgr::epoch_
private

number of threads used when loading data

Definition at line 203 of file GlobalFileMgr.h.

Referenced by getFileMgr(), and setFileMgrParams().

std::shared_ptr<ForeignStorageInterface> File_Namespace::GlobalFileMgr::fsi_
protected
std::map<TablePair, StorageStats> File_Namespace::GlobalFileMgr::lazy_initialized_stats_
private

Definition at line 215 of file GlobalFileMgr.h.

Referenced by getFileMgr(), getStorageStats(), setFileMgr(), and setFileMgrParams().

std::map<TablePair, int32_t> File_Namespace::GlobalFileMgr::max_rollback_epochs_per_table_
private

Definition at line 214 of file GlobalFileMgr.h.

Referenced by getFileMgr(), removeTableRelatedDS(), and setFileMgrParams().

const size_t File_Namespace::GlobalFileMgr::metadata_page_size_
private

used to set FileMgr page_size_

Definition at line 208 of file GlobalFileMgr.h.

size_t File_Namespace::GlobalFileMgr::num_reader_threads_
private

The OS file system path containing the files.

Definition at line 201 of file GlobalFileMgr.h.

Referenced by getFileMgr(), setFileMgrParams(), and setTableEpoch().

std::map<TablePair, std::shared_ptr<FileMgr> > File_Namespace::GlobalFileMgr::ownedFileMgrs_
private

true if conversion should be done between different db_version

Definition at line 212 of file GlobalFileMgr.h.

Referenced by deleteFileMgr(), getFileMgr(), getSharedFileMgr(), setFileMgr(), and setFileMgrParams().

const size_t File_Namespace::GlobalFileMgr::page_size_
private

Definition at line 207 of file GlobalFileMgr.h.


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