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 
12 namespace taco {
13 
14 class PersistentCatCache: public CatCacheBase<PersistentCatCache> {
15 public:
17 
18 private:
29  FileId CreateCatalogFile(bool format_heapfile);
30 
37  struct FileHandle {
38  // the file ID of the table
40 
41  // the heap file, this might be nullptr initially
42  std::unique_ptr<Table> m_table;
43  };
44 
50  FileHandle OpenCatalogFile(FileId fid, const TableDesc *tabdesc);
51 
55  void CloseCatalogFile(FileHandle &fh);
56 
62 
74  PageHandle GetFirstPage(FileHandle &fh, char **pagebuf);
75 
79  void MarkPageDirty(PageHandle &pghandle);
80 
84  void ReleasePage(PageHandle &pghandle);
85 
91  void AppendRecord(FileHandle &fh, Record &rec);
92 
98 
103 
109 
114  bool NextCatEntry(CatFileIterator &iter);
115 
121  const char *GetCurrentCatEntry(CatFileIterator &iter);
122 
128 
141  void UpdateCurrentCatEntry(CatFileIterator &iter, Record &rec);
142 
147 
154 
160 
161  friend class CatCacheBase<PersistentCatCache>;
162 };
163 
168 extern template class CatCacheBase<PersistentCatCache>;
169 
170 } // namespace taco
171 
172 #endif // CATALOG_PERSISTENTCATCACHE_H
CatCacheBase implements the common routines and public interfaces for accessing and modifying the sys...
Definition: CatCacheBase.h:103
Definition: PersistentCatCache.h:14
void MarkPageDirty(PageHandle &pghandle)
Marks a page pointed by the page handle as dirty.
Definition: PersistentCatCache.cpp:112
void UpdateCurrentCatEntry(CatFileIterator &iter, Record &rec)
Updates the current catalog entry pointed by the iterator with the record rec.
Definition: PersistentCatCache.cpp:155
Table::Iterator CatFileIterator
An opaque handle for iterating a catalog file.
Definition: PersistentCatCache.h:97
const char * GetCurrentCatEntry(CatFileIterator &iter)
Returns the current catalog entry pointed by the iterator as a buffer pointer.
Definition: PersistentCatCache.cpp:145
void ReleasePage(PageHandle &pghandle)
Releases the pin over the page pointed by the page handle.
Definition: PersistentCatCache.cpp:117
void _CreateTableIfNullForFileHandle(FileHandle &fh, FieldOffset reclen)
Creates the Table object in the file handle using a fake table descriptor.
Definition: PersistentCatCache.cpp:167
bool NextCatEntry(CatFileIterator &iter)
Tries to move the iterator to the next row and returns whether such a row exists.
Definition: PersistentCatCache.cpp:140
PersistentCatCache()
Definition: PersistentCatCache.cpp:15
RecordId GetCurrentCatEntryRecordId(CatFileIterator &iter)
Returns the current catalog entry's record ID.
Definition: PersistentCatCache.cpp:150
CatFileIterator IterateCatEntryFrom(FileHandle &fh, RecordId rid)
Creates an iterator that starts at rid.
Definition: PersistentCatCache.cpp:134
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:159
FileHandle OpenCatalogFile(FileId fid, const TableDesc *tabdesc)
Opens a catalog file for access.
Definition: PersistentCatCache.cpp:60
void AppendRecord(FileHandle &fh, Record &rec)
Appends a record to the catalog file specified by the file ID.
Definition: PersistentCatCache.cpp:122
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:102
ScopedBufferId PageHandle
An opaque handle for a data page in an unformatted catalog file.
Definition: PersistentCatCache.h:61
void CloseCatalogFile(FileHandle &fh)
Closes a catalog file pointed by the file handle.
Definition: PersistentCatCache.cpp:96
void EndIterateCatEntry(CatFileIterator &iter)
Releses any resource associated with the catalog file iterator.
Definition: PersistentCatCache.cpp:161
CatFileIterator IterateCatEntry(FileHandle &fh)
Creates an iterator over the catalog file specified by the file ID.
Definition: PersistentCatCache.cpp:128
FileId CreateCatalogFile(bool format_heapfile)
Creates a new catalog file and returns its file ID.
Definition: PersistentCatCache.cpp:19
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:218
uint32_t FileId
The file ID.
Definition: tdb_base.h:228
uint32_t PageNumber
Definition: tdb_base.h:220
An opaque handle for a catalog file.
Definition: PersistentCatCache.h:37
std::unique_ptr< Table > m_table
Definition: PersistentCatCache.h:42
FileId m_fid
Definition: PersistentCatCache.h:39
The record ID of a record on a page is a pair of ‘(PageNumber, SlotId)’.
Definition: Record.h:17