taco-db  0.1.0
PersistentCatCache.h
Go to the documentation of this file.
1 #ifndef CATALOG_PERSISTENTCATCACHE_H
2 #define CATALOG_PERSISTENTCATCACHE_H
3 
4 #include "tdb.h"
5 
6 #include "catalog/CatCacheBase.h"
8 #include "storage/FileManager.h"
9 #include "storage/Record.h"
10 #include "storage/Table.h"
11 #include "index/BulkLoadIterator.h"
12 
13 namespace taco {
14 
15 class PersistentCatCache: public CatCacheBase<PersistentCatCache> {
16 public:
18 
19 private:
30  FileId CreateCatalogFile(bool format_heapfile);
31 
38  struct FileHandle {
39  // the file ID of the table
41 
42  // the heap file, this might be nullptr initially
43  std::unique_ptr<Table> m_table;
44  };
45 
51  FileHandle OpenCatalogFile(FileId fid, const TableDesc *tabdesc);
52 
56  void CloseCatalogFile(FileHandle &fh);
57 
63 
75  PageHandle GetFirstPage(FileHandle &fh, char **pagebuf);
76 
80  void MarkPageDirty(PageHandle &pghandle);
81 
85  void ReleasePage(PageHandle &pghandle);
86 
92  void AppendRecord(FileHandle &fh, Record &rec);
93 
99 
104 
110 
115  bool NextCatEntry(CatFileIterator &iter);
116 
122  const char *GetCurrentCatEntry(CatFileIterator &iter);
123 
129 
142  void UpdateCurrentCatEntry(CatFileIterator &iter, Record &rec);
143 
148 
153  FileHandle &fh,
154  std::shared_ptr<const TableDesc> tabdesc,
155  std::shared_ptr<const IndexDesc> idxdesc);
156 
163 
169 
170  friend class CatCacheBase<PersistentCatCache>;
171 };
172 
177 extern template class CatCacheBase<PersistentCatCache>;
178 
179 } // namespace taco
180 
181 #endif // CATALOG_PERSISTENTCATCACHE_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: PersistentCatCache.h:15
void MarkPageDirty(PageHandle &pghandle)
Marks a page pointed by the page handle as dirty.
Definition: PersistentCatCache.cpp:113
void UpdateCurrentCatEntry(CatFileIterator &iter, Record &rec)
Updates the current catalog entry pointed by the iterator with the record rec.
Definition: PersistentCatCache.cpp:156
Table::Iterator CatFileIterator
An opaque handle for iterating a catalog file.
Definition: PersistentCatCache.h:98
const char * GetCurrentCatEntry(CatFileIterator &iter)
Returns the current catalog entry pointed by the iterator as a buffer pointer.
Definition: PersistentCatCache.cpp:146
void ReleasePage(PageHandle &pghandle)
Releases the pin over the page pointed by the page handle.
Definition: PersistentCatCache.cpp:118
void _CreateTableIfNullForFileHandle(FileHandle &fh, FieldOffset reclen)
Creates the Table object in the file handle using a fake table descriptor.
Definition: PersistentCatCache.cpp:178
bool NextCatEntry(CatFileIterator &iter)
Tries to move the iterator to the next row and returns whether such a row exists.
Definition: PersistentCatCache.cpp:141
PersistentCatCache()
Definition: PersistentCatCache.cpp:16
RecordId GetCurrentCatEntryRecordId(CatFileIterator &iter)
Returns the current catalog entry's record ID.
Definition: PersistentCatCache.cpp:151
CatFileIterator IterateCatEntryFrom(FileHandle &fh, RecordId rid)
Creates an iterator that starts at rid.
Definition: PersistentCatCache.cpp:135
PageNumber m_dbmetapg_pid
The page number of the DB meta page, which is the first page of the DB meta file.
Definition: PersistentCatCache.h:168
FileHandle OpenCatalogFile(FileId fid, const TableDesc *tabdesc)
Opens a catalog file for access.
Definition: PersistentCatCache.cpp:61
void AppendRecord(FileHandle &fh, Record &rec)
Appends a record to the catalog file specified by the file ID.
Definition: PersistentCatCache.cpp:123
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: PersistentCatCache.cpp:103
ScopedBufferId PageHandle
An opaque handle for a data page in an unformatted catalog file.
Definition: PersistentCatCache.h:62
void CloseCatalogFile(FileHandle &fh)
Closes a catalog file pointed by the file handle.
Definition: PersistentCatCache.cpp:97
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: PersistentCatCache.cpp:168
void EndIterateCatEntry(CatFileIterator &iter)
Releses any resource associated with the catalog file iterator.
Definition: PersistentCatCache.cpp:162
CatFileIterator IterateCatEntry(FileHandle &fh)
Creates an iterator over the catalog file specified by the file ID.
Definition: PersistentCatCache.cpp:129
FileId CreateCatalogFile(bool format_heapfile)
Creates a new catalog file and returns its file ID.
Definition: PersistentCatCache.cpp:20
Definition: Record.h:87
Definition: TableDesc.h:11
The Iterator interface for scanning the heap file.
Definition: Table.h:185
Definition: datum.h:28
int16_t FieldOffset
Definition: tdb_base.h:211
uint32_t FileId
The file ID.
Definition: tdb_base.h:221
uint32_t PageNumber
Definition: tdb_base.h:213
An opaque handle for a catalog file.
Definition: PersistentCatCache.h:38
std::unique_ptr< Table > m_table
Definition: PersistentCatCache.h:43
FileId m_fid
Definition: PersistentCatCache.h:40
The record ID of a record on a page is a pair of ‘(PageNumber, SlotId)’.
Definition: Record.h:17