OmniSciDB  085a039ca4
 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 deviceId, std::shared_ptr< ForeignStorageInterface > fsi, std::string basePath=".", const size_t num_reader_threads=0, const size_t defaultPageSize=DEFAULT_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 getDefaultPageSize () const
 
void writeFileMgrData (FileMgr *fileMgr=0)
 
int32_t getDBVersion () const
 
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)
 

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...
 
size_t defaultPageSize_
 
int32_t omnisci_db_version_
 default page size, used to set FileMgr defaultPageSize_ More...
 
bool dbConvert_
 
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_
 
mapd_shared_mutex fileMgrs_mutex_
 

Detailed Description

Definition at line 55 of file GlobalFileMgr.h.

Constructor & Destructor Documentation

File_Namespace::GlobalFileMgr::GlobalFileMgr ( const int32_t  deviceId,
std::shared_ptr< ForeignStorageInterface fsi,
std::string  basePath = ".",
const size_t  num_reader_threads = 0,
const size_t  defaultPageSize = DEFAULT_PAGE_SIZE 
)

Constructor.

Definition at line 42 of file GlobalFileMgr.cpp.

References dbConvert_, init(), and omnisci_db_version_.

47  : AbstractBufferMgr(deviceId)
48  , fsi_(fsi)
49  , basePath_(basePath)
50  , num_reader_threads_(num_reader_threads)
51  , epoch_(-1)
52  , // set the default epoch for all tables corresponding to the time of
53  // last checkpoint
54  defaultPageSize_(defaultPageSize) {
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_
int32_t omnisci_db_version_
default page size, used to set FileMgr defaultPageSize_
size_t num_reader_threads_
The OS file system path containing the files.

+ Here is the call graph for this function:

File_Namespace::GlobalFileMgr::~GlobalFileMgr ( )
inlineoverride

Definition at line 65 of file GlobalFileMgr.h.

65 {}

Member Function Documentation

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

Definition at line 113 of file GlobalFileMgr.h.

References logger::FATAL, and LOG.

113  {
114  LOG(FATAL) << "Operation not supported";
115  return nullptr; // satisfy return-type warning
116  }
#define LOG(tag)
Definition: Logger.h:217
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  {
79  mapd_unique_lock<mapd_shared_mutex> write_lock(fileMgrs_mutex_);
80  for (auto fileMgrsIt = allFileMgrs_.begin(); fileMgrsIt != allFileMgrs_.end();
81  ++fileMgrsIt) {
82  fileMgrsIt->second->checkpoint();
83  }
84 }
std::map< TablePair, AbstractBufferMgr * > allFileMgrs_
mapd_shared_mutex fileMgrs_mutex_
mapd_unique_lock< mapd_shared_mutex > write_lock

+ 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  {
135  mapd_unique_lock<mapd_shared_mutex> write_lock(fileMgrs_mutex_);
136  deleteFileMgr(db_id, tb_id);
137 }
void deleteFileMgr(const int32_t db_id, const int32_t tb_id)
mapd_shared_mutex fileMgrs_mutex_
mapd_unique_lock< mapd_shared_mutex > write_lock

+ 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 341 of file GlobalFileMgr.cpp.

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

Referenced by TableOptimizer::vacuumDeletedRows().

341  {
342  auto file_mgr = dynamic_cast<File_Namespace::FileMgr*>(findFileMgr(db_id, tb_id));
343  {
344  mapd_unique_lock<mapd_shared_mutex> write_lock(fileMgrs_mutex_);
345  if (file_mgr) {
346  file_mgr->compactFiles();
347  deleteFileMgr(db_id, tb_id);
348  }
349  }
350 
351  // Re-initialize file manager
352  getFileMgr(db_id, tb_id);
353 }
void deleteFileMgr(const int32_t db_id, const int32_t tb_id)
AbstractBufferMgr * getFileMgr(const int32_t db_id, const int32_t tb_id)
AbstractBufferMgr * findFileMgr(const int32_t db_id, const int32_t tb_id)
mapd_shared_mutex fileMgrs_mutex_
mapd_unique_lock< mapd_shared_mutex > write_lock

+ 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 68 of file GlobalFileMgr.h.

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

70  {
71  return getFileMgr(key)->createBuffer(key, pageSize, numBytes);
72  }
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 82 of file GlobalFileMgr.h.

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

82  {
83  return getFileMgr(key)->deleteBuffer(key, purge);
84  }
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 94 of file GlobalFileMgr.h.

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

96  {
97  return getFileMgr(key)->fetchBuffer(key, destBuffer, numBytes);
98  }
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  {
159  mapd_shared_lock<mapd_shared_mutex> read_lock(fileMgrs_mutex_);
160  return findFileMgrUnlocked(db_id, tb_id);
161  }
AbstractBufferMgr * findFileMgrUnlocked(const int32_t db_id, const int32_t tb_id)
mapd_shared_lock< mapd_shared_mutex > read_lock
mapd_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 118 of file GlobalFileMgr.h.

References logger::FATAL, and LOG.

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

Definition at line 125 of file GlobalFileMgr.h.

125 { 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 90 of file GlobalFileMgr.h.

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

90  {
91  return getFileMgr(key)->getBuffer(key, numBytes);
92  }
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 130 of file GlobalFileMgr.h.

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

131  {
132  return getFileMgr(keyPrefix)->getChunkMetadataVecForKeyPrefix(chunkMetadataVec,
133  keyPrefix);
134  }
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_; }

+ Here is the caller graph for this function:

int32_t File_Namespace::GlobalFileMgr::getDBVersion ( ) const
inline

Definition at line 175 of file GlobalFileMgr.h.

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

175 { return omnisci_db_version_; }
int32_t omnisci_db_version_
default page size, used to set FileMgr defaultPageSize_

+ Here is the caller graph for this function:

size_t File_Namespace::GlobalFileMgr::getDefaultPageSize ( ) const
inline

Definition at line 171 of file GlobalFileMgr.h.

171 { return defaultPageSize_; }
AbstractBufferMgr * File_Namespace::GlobalFileMgr::getFileMgr ( const int32_t  db_id,
const int32_t  tb_id 
)

Definition at line 180 of file GlobalFileMgr.cpp.

References allFileMgrs_, CHECK, defaultPageSize_, 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().

180  {
181  { // check if FileMgr already exists for (db_id, tb_id)
182  mapd_shared_lock<mapd_shared_mutex> read_lock(fileMgrs_mutex_);
183  AbstractBufferMgr* fm = findFileMgrUnlocked(db_id, tb_id);
184  if (fm) {
185  return fm;
186  }
187  }
188 
189  { // create new FileMgr for (db_id, tb_id)
190  mapd_unique_lock<mapd_shared_mutex> write_lock(fileMgrs_mutex_);
191  AbstractBufferMgr* fm = findFileMgrUnlocked(db_id, tb_id);
192  if (fm) {
193  return fm; // mgr was added between the read lock and the write lock
194  }
195  const auto file_mgr_key = std::make_pair(db_id, tb_id);
196  const auto foreign_buffer_manager = fsi_->lookupBufferManager(db_id, tb_id);
197  if (foreign_buffer_manager) {
198  CHECK(allFileMgrs_.insert(std::make_pair(file_mgr_key, foreign_buffer_manager))
199  .second);
200  return foreign_buffer_manager;
201  } else {
202  int32_t max_rollback_epochs{-1};
203  if (max_rollback_epochs_per_table_.find(file_mgr_key) !=
205  max_rollback_epochs = max_rollback_epochs_per_table_[file_mgr_key];
206  }
207  auto s = std::make_shared<FileMgr>(0,
208  this,
209  file_mgr_key,
210  max_rollback_epochs,
212  epoch_,
214  CHECK(ownedFileMgrs_.insert(std::make_pair(file_mgr_key, s)).second);
215  CHECK(allFileMgrs_.insert(std::make_pair(file_mgr_key, s.get())).second);
216  lazy_initialized_stats_.erase(file_mgr_key);
217  return s.get();
218  }
219  }
220 }
int32_t epoch_
number of threads used when loading data
std::shared_ptr< ForeignStorageInterface > fsi_
std::map< TablePair, std::shared_ptr< FileMgr > > ownedFileMgrs_
std::map< TablePair, AbstractBufferMgr * > allFileMgrs_
AbstractBufferMgr * findFileMgrUnlocked(const int32_t db_id, const int32_t tb_id)
mapd_shared_lock< mapd_shared_mutex > read_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:223
std::map< TablePair, StorageStats > lazy_initialized_stats_
mapd_shared_mutex fileMgrs_mutex_
mapd_unique_lock< mapd_shared_mutex > write_lock

+ 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 124 of file GlobalFileMgr.h.

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

Definition at line 123 of file GlobalFileMgr.h.

123 { return 0; }
MgrType File_Namespace::GlobalFileMgr::getMgrType ( )
inlineoverride

Definition at line 120 of file GlobalFileMgr.h.

120 { 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  {
91  mapd_shared_lock<mapd_shared_mutex> read_lock(fileMgrs_mutex_);
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::map< TablePair, AbstractBufferMgr * > allFileMgrs_
mapd_shared_lock< mapd_shared_mutex > read_lock
mapd_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 147 of file GlobalFileMgr.h.

147 { return num_reader_threads_; }
size_t num_reader_threads_
The OS file system path containing the files.
std::shared_ptr< FileMgr > File_Namespace::GlobalFileMgr::getSharedFileMgr ( const int  db_id,
const int  table_id 
)

Definition at line 223 of file GlobalFileMgr.cpp.

References ownedFileMgrs_.

224  {
225  const auto table_key = std::make_pair(db_id, table_id);
226  if (ownedFileMgrs_.find(table_key) == ownedFileMgrs_.end()) {
227  return nullptr;
228  }
229  return ownedFileMgrs_[table_key];
230 }
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 322 of file GlobalFileMgr.cpp.

References defaultPageSize_, fileMgrs_mutex_, findFileMgr(), and lazy_initialized_stats_.

322  {
323  mapd_shared_lock<mapd_shared_mutex> read_lock(fileMgrs_mutex_);
324  AbstractBufferMgr* opened_fm = findFileMgr(db_id, tb_id);
325  if (opened_fm) {
326  return dynamic_cast<FileMgr*>(opened_fm)->getStorageStats();
327  }
328  TablePair file_mgr_key{db_id, tb_id};
329  auto it = lazy_initialized_stats_.find(file_mgr_key);
330  if (it != lazy_initialized_stats_.end()) {
331  return it->second;
332  } else {
333  // Do not do full init of table just to get storage stats, just check file instead
334  auto u = std::make_unique<FileMgr>(0, this, file_mgr_key, defaultPageSize_, true);
335  lazy_initialized_stats_[file_mgr_key] = u->getStorageStats();
336  u.reset();
337  return lazy_initialized_stats_[file_mgr_key];
338  }
339 }
StorageStats getStorageStats(const int32_t db_id, const int32_t tb_id)
mapd_shared_lock< mapd_shared_mutex > read_lock
AbstractBufferMgr * findFileMgr(const int32_t db_id, const int32_t tb_id)
std::map< TablePair, StorageStats > lazy_initialized_stats_
mapd_shared_mutex fileMgrs_mutex_
std::pair< const int32_t, const int32_t > TablePair
Definition: FileMgr.h:92

+ Here is the call graph for this function:

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

Definition at line 121 of file GlobalFileMgr.h.

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

Definition at line 300 of file GlobalFileMgr.cpp.

References defaultPageSize_, fileMgrs_mutex_, and findFileMgr().

300  {
301  // UX change was made to this function Oct 2020 to return checkpointed epoch. In turn,
302  // setTableEpoch was changed to set the epoch at the user's input, instead of input - 1
303  mapd_shared_lock<mapd_shared_mutex> read_lock(fileMgrs_mutex_);
304  AbstractBufferMgr* opened_fm = findFileMgr(db_id, tb_id);
305  if (opened_fm) {
306  return dynamic_cast<FileMgr*>(opened_fm)->lastCheckpointedEpoch();
307  }
308  // Do not do full init of table just to get table epoch, just check file instead
309  const auto file_mgr_key = std::make_pair(db_id, tb_id);
310  auto u = std::make_unique<FileMgr>(0, this, file_mgr_key, defaultPageSize_, true);
311  const auto epoch = u->lastCheckpointedEpoch();
312  u.reset();
313  return epoch;
314 }
mapd_shared_lock< mapd_shared_mutex > read_lock
AbstractBufferMgr * findFileMgr(const int32_t db_id, const int32_t tb_id)
mapd_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:217

+ Here is the caller graph for this function:

bool File_Namespace::GlobalFileMgr::isAllocationCapped ( )
inlineoverride

Definition at line 126 of file GlobalFileMgr.h.

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

Definition at line 74 of file GlobalFileMgr.h.

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

Definition at line 122 of file GlobalFileMgr.h.

122 { 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 106 of file GlobalFileMgr.h.

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

108  {
109  return getFileMgr(key)->putBuffer(key, d, numBytes);
110  }
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 259 of file GlobalFileMgr.cpp.

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

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

259  {
260  mapd_unique_lock<mapd_shared_mutex> write_lock(fileMgrs_mutex_);
261  auto abm = findFileMgrUnlocked(db_id, tb_id);
262  if (auto fm = dynamic_cast<File_Namespace::FileMgr*>(abm)) {
263  fm->closeRemovePhysical();
264  } else if (dynamic_cast<ForeignStorageBufferMgr*>(abm)) {
265  abm->removeTableRelatedDS(db_id, tb_id);
266  fsi_->dropBufferManager(db_id, tb_id);
267  } else {
268  // fileMgr has not been initialized so there is no need to
269  // spend the time initializing
270  // initialize just enough to have to rename
271  const auto file_mgr_key = std::make_pair(db_id, tb_id);
272  auto u = std::make_unique<FileMgr>(0, this, file_mgr_key, defaultPageSize_, true);
273  u->closeRemovePhysical();
274  }
275  // remove table related in-memory DS only if directory was removed successfully
276 
277  deleteFileMgr(db_id, tb_id);
278  max_rollback_epochs_per_table_.erase({db_id, tb_id});
279 }
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::map< TablePair, int32_t > max_rollback_epochs_per_table_
mapd_shared_mutex fileMgrs_mutex_
mapd_unique_lock< mapd_shared_mutex > write_lock

+ 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 316 of file GlobalFileMgr.cpp.

References CHECK, and getFileMgr().

316  {
317  AbstractBufferMgr* fm = getFileMgr(db_id, tb_id);
318  CHECK(fm);
319  dynamic_cast<FileMgr*>(fm)->resetEpochFloor();
320 }
AbstractBufferMgr * getFileMgr(const int32_t db_id, const int32_t tb_id)
#define CHECK(condition)
Definition: Logger.h:223

+ Here is the call graph for this function:

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

Definition at line 177 of file GlobalFileMgr.h.

void File_Namespace::GlobalFileMgr::setFileMgr ( const int  db_id,
const int  table_id,
std::shared_ptr< FileMgr file_mgr 
)

Definition at line 233 of file GlobalFileMgr.cpp.

References allFileMgrs_, lazy_initialized_stats_, and ownedFileMgrs_.

235  {
236  TablePair file_mgr_key{db_id, table_id};
237  allFileMgrs_[file_mgr_key] = file_mgr.get();
238  ownedFileMgrs_[file_mgr_key] = file_mgr;
239  lazy_initialized_stats_.erase(file_mgr_key);
240 }
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:92
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, defaultPageSize_, 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));
157  mapd_unique_lock<mapd_shared_mutex> write_lock(fileMgrs_mutex_);
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_,
173  CHECK(ownedFileMgrs_.insert(std::make_pair(file_mgr_key, s)).second);
174  CHECK(allFileMgrs_.insert(std::make_pair(file_mgr_key, s.get())).second);
175  max_rollback_epochs_per_table_[file_mgr_key] = max_rollback_epochs;
176  lazy_initialized_stats_.erase(file_mgr_key);
177  return;
178 }
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_
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:223
AbstractBufferMgr * findFileMgr(const int32_t db_id, const int32_t tb_id)
std::map< TablePair, StorageStats > lazy_initialized_stats_
mapd_shared_mutex fileMgrs_mutex_
mapd_unique_lock< mapd_shared_mutex > write_lock

+ 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 281 of file GlobalFileMgr.cpp.

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

283  {
284  AbstractBufferMgr* opened_fm = findFileMgr(db_id, tb_id);
285  if (opened_fm) {
286  // Delete this FileMgr to ensure epoch change occurs in constructor with other
287  // reads/writes locked out
288  deleteFileMgr(db_id, tb_id);
289  }
290  const auto file_mgr_key = std::make_pair(db_id, tb_id);
291  // this is where the real rollback of any data ahead of the currently set epoch is
292  // performed
293  // Will call set_epoch with start_epoch internally
294  auto u = std::make_unique<FileMgr>(
295  0, this, file_mgr_key, -1, num_reader_threads_, start_epoch, defaultPageSize_);
296  // remove the dummy one we built
297  u.reset();
298 }
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 242 of file GlobalFileMgr.cpp.

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

243  { // this function is not used, keep it for now for future needs
244  mapd_shared_lock<mapd_shared_mutex> read_lock(fileMgrs_mutex_);
245  for (auto fileMgrIt = allFileMgrs_.begin(); fileMgrIt != allFileMgrs_.end();
246  fileMgrIt++) {
247  FileMgr* fm = dynamic_cast<FileMgr*>(fileMgrIt->second);
248  CHECK(fm);
249  if ((fileMgr != 0) && (fileMgr != fm)) {
250  continue;
251  }
252  for (auto chunkIt = fm->chunkIndex_.begin(); chunkIt != fm->chunkIndex_.end();
253  chunkIt++) {
254  chunkIt->second->write((int8_t*)chunkIt->second, chunkIt->second->size(), 0);
255  }
256  }
257 }
std::map< TablePair, AbstractBufferMgr * > allFileMgrs_
mapd_shared_lock< mapd_shared_mutex > read_lock
#define CHECK(condition)
Definition: Logger.h:223
mapd_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().

bool File_Namespace::GlobalFileMgr::dbConvert_
private

DB version for DataMgr DS and corresponding file buffer read/write code

Definition at line 216 of file GlobalFileMgr.h.

Referenced by GlobalFileMgr().

size_t File_Namespace::GlobalFileMgr::defaultPageSize_
private
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 222 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 221 of file GlobalFileMgr.h.

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

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().

int32_t File_Namespace::GlobalFileMgr::omnisci_db_version_
private

default page size, used to set FileMgr defaultPageSize_

Definition at line 210 of file GlobalFileMgr.h.

Referenced by GlobalFileMgr().

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

true if conversion should be done between different "omnisci_db_version_"

Definition at line 219 of file GlobalFileMgr.h.

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


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