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 
212  friend class CatCacheBase<VolatileCatCache>;
213 };
214 
219 extern template class CatCacheBase<VolatileCatCache>;
220 
221 } // namespace taco
222 
223 #endif // CATALOG_VOLATILE_CATCACHE_H
BulkLoadIterator is an interface for providing (key, RecordId) pairs for index bulk loading.
Definition: BulkLoadIterator.h:17
CatCacheBase implements the common routines and public interfaces for accessing and modifying the sys...
Definition: CatCacheBase.h:103
Definition: Record.h:87
Definition: TableDesc.h:11
Definition: VolatileCatCache.h:41
CatFileIterator m_iter
Definition: VolatileCatCache.h:64
VolatileCatCache * m_vcatcache
Definition: VolatileCatCache.h:63
InmemFileBulkLoadIterator(std::shared_ptr< const IndexDesc > idxdesc, std::shared_ptr< const TableDesc > tabdesc, VolatileCatCache *vcatcache, CatFileIterator iter)
Definition: VolatileCatCache.h:43
std::shared_ptr< const TableDesc > m_tabdesc
Definition: VolatileCatCache.h:62
std::vector< Datum > m_data
Definition: VolatileCatCache.h:65
bool Next() override
Subclass should override the Next() function for moving to the next (key, record id) pair.
Definition: VolatileCatCache.cpp:206
void EndScan() override
Ends the scan.
Definition: VolatileCatCache.h:56
std::shared_ptr< const IndexDesc > m_idxdesc
Definition: VolatileCatCache.h:61
Definition: VolatileCatCache.h:12
void CloseCatalogFile(FileHandle &fh)
Closes a catalog file pointed by the file handle.
Definition: VolatileCatCache.cpp:40
RecordId GetCurrentCatEntryRecordId(CatFileIterator &iter)
Returns the current catalog entry's record ID.
Definition: VolatileCatCache.cpp:149
FileHandle OpenCatalogFile(FileId fid, const TableDesc *tabdesc)
Opens a catalog file for access.
Definition: VolatileCatCache.cpp:32
void AppendRecord(FileHandle &fh, Record &rec)
Appends a record to the catalog file specified by the file ID.
Definition: VolatileCatCache.cpp:72
void UpdateCurrentCatEntry(CatFileIterator &iter, Record &rec)
Updates the current catalog entry pointed by the iterator with the record rec.
Definition: VolatileCatCache.cpp:159
CatFileIterator IterateCatEntryFrom(FileHandle &fh, RecordId rid)
Creates an iterator that starts at rid.
Definition: VolatileCatCache.cpp:107
void MarkPageDirty(PageHandle &pghandle)
Marks a page pointed by the page handle as dirty.
Definition: VolatileCatCache.cpp:55
int PageHandle
An opaque handle for a data page in an unformatted catalog file.
Definition: VolatileCatCache.h:113
void InitializeFromExistingData()
Not implemented.
Definition: VolatileCatCache.h:18
unique_malloced_ptr m_dbmeta_page
The pointer to the in-memory only dbmeta page.
Definition: VolatileCatCache.h:210
void EndIterateCatEntry(CatFileIterator &iter)
Releses any resource associated with the catalog file iterator.
Definition: VolatileCatCache.cpp:188
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
FileId CreateCatalogFile(bool format_heapfile, FieldOffset=0)
Creates a new catalog file and returns its file ID.
Definition: VolatileCatCache.cpp:12
FileId FileHandle
An opaque handle for a catalog file.
Definition: VolatileCatCache.h:92
const char * GetCurrentCatEntry(CatFileIterator &iter)
Returns the current catalog entry pointed by the iterator as a buffer pointer.
Definition: VolatileCatCache.cpp:137
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
bool NextCatEntry(CatFileIterator &iter)
Tries to move the iterator to the next row and returns whether such a row exists.
Definition: VolatileCatCache.cpp:117
CatFileIterator IterateCatEntry(FileHandle &fh)
Creates an iterator over the catalog file specified by the file ID.
Definition: VolatileCatCache.cpp:99
void ReleasePage(PageHandle &pghandle)
Releases the pin over the page pointed by the page handle.
Definition: VolatileCatCache.cpp:63
std::vector< std::unique_ptr< InmemFile > > m_systables
This vector stores all our in-memory only files.
Definition: VolatileCatCache.h:205
#define LOG(level,...)
LOG(LogSeverity level, const char *fmt, ...)
Definition: logging.h:116
Definition: Record.h:148
Definition: datum.h:28
constexpr LogSeverity kError
Definition: logging.h:21
int16_t FieldOffset
Definition: tdb_base.h:211
uint32_t FileId
The file ID.
Definition: tdb_base.h:221
The record ID of a record on a page is a pair of ‘(PageNumber, SlotId)’.
Definition: Record.h:17
An opaque handle for iterating a catalog file.
Definition: VolatileCatCache.h:35
uint16_t m_nextidx
Definition: VolatileCatCache.h:37
uint16_t m_endidx
Definition: VolatileCatCache.h:38
FileId m_fid
Definition: VolatileCatCache.h:36
Definition: VolatileCatCache.h:25
std::vector< bool > m_valid
Definition: VolatileCatCache.h:26
std::vector< char > m_bytes
Definition: VolatileCatCache.h:28
std::vector< size_t > m_offsets
Definition: VolatileCatCache.h:27
std::unique_ptr< void, AlignedAllocImpl::FreeMem > unique_malloced_ptr
Definition: tdb_base.h:94