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"
8 
9 namespace taco {
10 
11 class VolatileCatCache: public CatCacheBase<VolatileCatCache> {
12 public:
18  LOG(kError,
19  "voatile catlog cannot be initialized from an existing data "
20  "directory");
21  }
22 
23 private:
24  struct InmemFile {
25  std::vector<bool> m_valid;
26  std::vector<size_t> m_offsets;
27  std::vector<char> m_bytes;
28  };
29 
34  struct CatFileIterator {
36  uint16_t m_nextidx;
37  uint16_t m_endidx;
38  };
39 
55  FileId CreateCatalogFile(bool format_heapfile, FieldOffset /*unused*/ = 0);
56 
62  typedef FileId FileHandle;
63 
71  FileHandle OpenCatalogFile(FileId fid, const TableDesc *tabdesc);
72 
77  void CloseCatalogFile(FileHandle &fh);
78 
83  typedef int PageHandle;
84 
91  PageHandle GetFirstPage(FileHandle &fh, char **pagebuf);
92 
97  void MarkPageDirty(PageHandle &pghandle);
98 
103  void ReleasePage(PageHandle &pghandle);
104 
110  void AppendRecord(FileHandle &fh, Record &rec);
111 
116 
122 
127  bool NextCatEntry(CatFileIterator &iter);
128 
134  const char *GetCurrentCatEntry(CatFileIterator &iter);
135 
141 
154  void UpdateCurrentCatEntry(CatFileIterator &iter, Record &rec);
155 
162 
167  std::vector<std::unique_ptr<InmemFile>> m_systables;
168 
173 
174  friend class CatCacheBase<VolatileCatCache>;
175 };
176 
181 extern template class CatCacheBase<VolatileCatCache>;
182 
183 } // namespace taco
184 
185 #endif // CATALOG_VOLATILE_CATCACHE_H
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:11
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:83
void InitializeFromExistingData()
Not implemented.
Definition: VolatileCatCache.h:17
unique_malloced_ptr m_dbmeta_page
The pointer to the in-memory only dbmeta page.
Definition: VolatileCatCache.h:172
void EndIterateCatEntry(CatFileIterator &iter)
Releses any resource associated with the catalog file iterator.
Definition: VolatileCatCache.cpp:188
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:62
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:167
#define LOG(level,...)
LOG(LogSeverity level, const char *fmt, ...)
Definition: logging.h:116
Definition: datum.h:28
constexpr LogSeverity kError
Definition: logging.h:21
int16_t FieldOffset
Definition: tdb_base.h:218
uint32_t FileId
The file ID.
Definition: tdb_base.h:228
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:34
uint16_t m_nextidx
Definition: VolatileCatCache.h:36
uint16_t m_endidx
Definition: VolatileCatCache.h:37
FileId m_fid
Definition: VolatileCatCache.h:35
Definition: VolatileCatCache.h:24
std::vector< bool > m_valid
Definition: VolatileCatCache.h:25
std::vector< char > m_bytes
Definition: VolatileCatCache.h:27
std::vector< size_t > m_offsets
Definition: VolatileCatCache.h:26
std::unique_ptr< void, AlignedAllocImpl::FreeMem > unique_malloced_ptr
Definition: tdb_base.h:100