taco-db  0.1.0
VolatileCatCache.h
Go to the documentation of this file.
1 #ifndef CATALOG_VOLATILE_CATCACHE_H
2 #define CATALOG_VOLATILE_CATCACHE_H
3 
4 #include "tdb.h"
5 
6 #include "catalog/CatCacheBase.h"
7 #include "storage/Record.h"
9 
10 namespace taco {
11 
12 class VolatileCatCache: public CatCacheBase<VolatileCatCache> {
13 public:
19  LOG(kError,
20  "voatile catlog cannot be initialized from an existing data "
21  "directory");
22  }
23 
24 private:
25  struct InmemFile {
26  std::vector<bool> m_valid;
27  std::vector<size_t> m_offsets;
28  std::vector<char> m_bytes;
29  };
30 
35  struct CatFileIterator {
37  uint16_t m_nextidx;
38  uint16_t m_endidx;
39  };
40 
42  public:
43  InmemFileBulkLoadIterator(std::shared_ptr<const IndexDesc> idxdesc,
44  std::shared_ptr<const TableDesc> tabdesc,
45  VolatileCatCache *vcatcache,
46  CatFileIterator iter):
47  BulkLoadIterator(idxdesc->GetKeySchema()),
48  m_idxdesc(std::move(idxdesc)),
49  m_tabdesc(std::move(tabdesc)),
50  m_vcatcache(vcatcache),
51  m_iter(iter),
52  m_data() {}
53 
54  bool Next() override;
55 
56  void EndScan() override {
58  }
59 
60  private:
61  std::shared_ptr<const IndexDesc> m_idxdesc;
62  std::shared_ptr<const TableDesc> m_tabdesc;
65  std::vector<Datum> m_data;
66  };
67 
69 
85  FileId CreateCatalogFile(bool format_heapfile, FieldOffset /*unused*/ = 0);
86 
92  typedef FileId FileHandle;
93 
101  FileHandle OpenCatalogFile(FileId fid, const TableDesc *tabdesc);
102 
107  void CloseCatalogFile(FileHandle &fh);
108 
113  typedef int PageHandle;
114 
121  PageHandle GetFirstPage(FileHandle &fh, char **pagebuf);
122 
127  void MarkPageDirty(PageHandle &pghandle);
128 
133  void ReleasePage(PageHandle &pghandle);
134 
140  void AppendRecord(FileHandle &fh, Record &rec);
141 
146 
152 
157  bool NextCatEntry(CatFileIterator &iter);
158 
164  const char *GetCurrentCatEntry(CatFileIterator &iter);
165 
171 
184  void UpdateCurrentCatEntry(CatFileIterator &iter, Record &rec);
185 
192 
197  FileHandle &fh,
198  std::shared_ptr<const TableDesc> tabdesc,
199  std::shared_ptr<const IndexDesc> idxdesc);
200 
205  std::vector<std::unique_ptr<InmemFile>> m_systables;
206 
211 
213 };
214 
219 extern template class CatCacheBase<VolatileCatCache>;
220 
221 } // namespace taco
222 
223 #endif // CATALOG_VOLATILE_CATCACHE_H
taco::VolatileCatCache::UpdateCurrentCatEntry
void UpdateCurrentCatEntry(CatFileIterator &iter, Record &rec)
Updates the current catalog entry pointed by the iterator with the record rec.
Definition: VolatileCatCache.cpp:159
taco::FieldOffset
int16_t FieldOffset
Definition: tdb_base.h:212
taco::VolatileCatCache::AppendRecord
void AppendRecord(FileHandle &fh, Record &rec)
Appends a record to the catalog file specified by the file ID.
Definition: VolatileCatCache.cpp:72
taco::TableDesc
Definition: TableDesc.h:11
taco::VolatileCatCache::NextCatEntry
bool NextCatEntry(CatFileIterator &iter)
Tries to move the iterator to the next row and returns whether such a row exists.
Definition: VolatileCatCache.cpp:117
taco
Definition: datum.h:28
taco::VolatileCatCache::CreateCatalogFile
FileId CreateCatalogFile(bool format_heapfile, FieldOffset=0)
Creates a new catalog file and returns its file ID.
Definition: VolatileCatCache.cpp:12
taco::VolatileCatCache::CloseCatalogFile
void CloseCatalogFile(FileHandle &fh)
Closes a catalog file pointed by the file handle.
Definition: VolatileCatCache.cpp:40
taco::VolatileCatCache::InmemFile
Definition: VolatileCatCache.h:25
taco::kError
constexpr LogSeverity kError
Definition: logging.h:21
taco::VolatileCatCache::InmemFile::m_offsets
std::vector< size_t > m_offsets
Definition: VolatileCatCache.h:27
taco::VolatileCatCache::PageHandle
int PageHandle
An opaque handle for a data page in an unformatted catalog file.
Definition: VolatileCatCache.h:113
taco::VolatileCatCache::ReleasePage
void ReleasePage(PageHandle &pghandle)
Releases the pin over the page pointed by the page handle.
Definition: VolatileCatCache.cpp:63
taco::VolatileCatCache::InmemFileBulkLoadIterator::InmemFileBulkLoadIterator
InmemFileBulkLoadIterator(std::shared_ptr< const IndexDesc > idxdesc, std::shared_ptr< const TableDesc > tabdesc, VolatileCatCache *vcatcache, CatFileIterator iter)
Definition: VolatileCatCache.h:43
taco::VolatileCatCache::InmemFileBulkLoadIterator::EndScan
void EndScan() override
Ends the scan.
Definition: VolatileCatCache.h:56
taco::VolatileCatCache::GetCurrentCatEntryRecordId
RecordId GetCurrentCatEntryRecordId(CatFileIterator &iter)
Returns the current catalog entry's record ID.
Definition: VolatileCatCache.cpp:149
unique_malloced_ptr
std::unique_ptr< void, AlignedAllocImpl::FreeMem > unique_malloced_ptr
Definition: tdb_base.h:94
taco::RecordId
The record ID of a record on a page is a pair of ‘(PageNumber, SlotId)’.
Definition: Record.h:17
taco::VolatileCatCache::CatFileIterator
An opaque handle for iterating a catalog file.
Definition: VolatileCatCache.h:35
taco::VolatileCatCache::InmemFileBulkLoadIterator::Next
bool Next() override
Subclass should override the Next() function for moving to the next (key, record id) pair.
Definition: VolatileCatCache.cpp:206
taco::VolatileCatCache::InmemFile::m_valid
std::vector< bool > m_valid
Definition: VolatileCatCache.h:26
taco::VolatileCatCache::CatFileIterator::m_endidx
uint16_t m_endidx
Definition: VolatileCatCache.h:38
taco::VolatileCatCache::CatFileIterator::m_nextidx
uint16_t m_nextidx
Definition: VolatileCatCache.h:37
tdb.h
taco::VolatileCatCache::InmemFileBulkLoadIterator::m_data
std::vector< Datum > m_data
Definition: VolatileCatCache.h:65
taco::VolatileCatCache::IterateCatEntryFrom
CatFileIterator IterateCatEntryFrom(FileHandle &fh, RecordId rid)
Creates an iterator that starts at rid.
Definition: VolatileCatCache.cpp:107
taco::VolatileCatCache::GetFirstPage
PageHandle GetFirstPage(FileHandle &fh, char **pagebuf)
Returns a handle to the first page in the unformatted catalog file with it pinned in the memory.
Definition: VolatileCatCache.cpp:45
taco::VolatileCatCache::InmemFileBulkLoadIterator::m_iter
CatFileIterator m_iter
Definition: VolatileCatCache.h:64
taco::VolatileCatCache::FileHandle
FileId FileHandle
An opaque handle for a catalog file.
Definition: VolatileCatCache.h:92
taco::VolatileCatCache::GetCurrentCatEntry
const char * GetCurrentCatEntry(CatFileIterator &iter)
Returns the current catalog entry pointed by the iterator as a buffer pointer.
Definition: VolatileCatCache.cpp:137
taco::FileId
uint32_t FileId
The file ID.
Definition: tdb_base.h:222
taco::VolatileCatCache::InmemFileBulkLoadIterator::m_tabdesc
std::shared_ptr< const TableDesc > m_tabdesc
Definition: VolatileCatCache.h:62
CatCacheBase.h
taco::VolatileCatCache::IterateCatEntry
CatFileIterator IterateCatEntry(FileHandle &fh)
Creates an iterator over the catalog file specified by the file ID.
Definition: VolatileCatCache.cpp:99
taco::BulkLoadIterator
BulkLoadIterator is an interface for providing (key, RecordId) pairs for index bulk loading.
Definition: BulkLoadIterator.h:17
taco::VolatileCatCache::EndIterateCatEntry
void EndIterateCatEntry(CatFileIterator &iter)
Releses any resource associated with the catalog file iterator.
Definition: VolatileCatCache.cpp:188
taco::Record
Definition: Record.h:87
taco::VolatileCatCache::InmemFile::m_bytes
std::vector< char > m_bytes
Definition: VolatileCatCache.h:28
LOG
#define LOG(level,...)
LOG(LogSeverity level, const char *fmt, ...)
Definition: logging.h:116
taco::VolatileCatCache
Definition: VolatileCatCache.h:12
std
Definition: Record.h:148
taco::VolatileCatCache::InmemFileBulkLoadIterator
Definition: VolatileCatCache.h:41
taco::VolatileCatCache::OpenCatalogFile
FileHandle OpenCatalogFile(FileId fid, const TableDesc *tabdesc)
Opens a catalog file for access.
Definition: VolatileCatCache.cpp:32
taco::VolatileCatCache::GetBulkLoadIterator
BulkLoadIterator * GetBulkLoadIterator(FileHandle &fh, std::shared_ptr< const TableDesc > tabdesc, std::shared_ptr< const IndexDesc > idxdesc)
Returns a BulkLoadIterator for bulk loading a systable index.
Definition: VolatileCatCache.cpp:193
taco::VolatileCatCache::m_systables
std::vector< std::unique_ptr< InmemFile > > m_systables
This vector stores all our in-memory only files.
Definition: VolatileCatCache.h:205
taco::VolatileCatCache::CatFileIterator::m_fid
FileId m_fid
Definition: VolatileCatCache.h:36
BulkLoadIterator.h
taco::VolatileCatCache::InitializeFromExistingData
void InitializeFromExistingData()
Not implemented.
Definition: VolatileCatCache.h:18
taco::VolatileCatCache::MarkPageDirty
void MarkPageDirty(PageHandle &pghandle)
Marks a page pointed by the page handle as dirty.
Definition: VolatileCatCache.cpp:55
taco::VolatileCatCache::InmemFileBulkLoadIterator::m_idxdesc
std::shared_ptr< const IndexDesc > m_idxdesc
Definition: VolatileCatCache.h:61
Record.h
taco::CatCacheBase
CatCacheBase implements the common routines and public interfaces for accessing and modifying the sys...
Definition: CatCacheBase.h:103
taco::VolatileCatCache::m_dbmeta_page
unique_malloced_ptr m_dbmeta_page
The pointer to the in-memory only dbmeta page.
Definition: VolatileCatCache.h:210
taco::VolatileCatCache::InmemFileBulkLoadIterator::m_vcatcache
VolatileCatCache * m_vcatcache
Definition: VolatileCatCache.h:63