20 #include <unordered_set> 21 #include <unordered_map> 257 DISK_HEADER_SIZE - (
sizeof(std::uint32_t)*2);
312 std::unordered_map <FileId, DiskFileInfo*>
file_map;
void _deserializeFileHeader(SerializedFileHeader *file_header, DiskFileInfo *disk_file_info)
Intializes DiskFileInfo object given SerializedFileHeader object.
void _serializeFileHeader(SerializedFileHeader *file_header, DiskFileInfo *disk_file_info)
Serializes Unix file metadata by initializing SerializedFileHeader object given DiskFileInfo object...
DiskManager(Catalog *catalog)
DiskManager constructor. Uses Catalog object pointer and a vector of FileIds to initialize file_map...
Catalog * catalog
Definition: diskmgr.h:319
~DiskManager()
DiskManager destructor. All pages have been written to disk prior to this call.
char temp_page[PAGE_SIZE]
Definition: diskmgr.h:329
std::unordered_map< FileId, DiskFileInfo * > file_map
Definition: diskmgr.h:312
PageId allocatePage(FileId file_id)
Allocates a Page to the file which corresponds to file_id.
static const std::uint32_t DISK_HEADER_SIZE
Definition: diskmgr.h:248
void _flushDiskFileInfo(FileId file_id)
Writes data from DiskFileInfo struct to Unix file for the given FileId.
std::unordered_set< PageNum > unused_pages
Definition: diskmgr.h:300
std::fstream file
Definition: diskmgr.h:290
void writePage(PageId page_id, Page *page)
Writes the page data of the given Page object at the right offset in the appropriate Unix file...
void _getDiskFileInfo(FileId file_id, DiskFileInfo **disk_file_info)
Initializes DiskFileInfo** of the given FileId.
std::mutex file_map_mtx
Definition: diskmgr.h:324
std::mutex file_mtx
Definition: diskmgr.h:305
std::uint32_t getCapacity(FileId file_id)
Get method for the capacity of a file.
bool isValidPage(PageId page_id)
Checks if the page of a given pageId is valid.
static const std::uint32_t DISK_HEADER_BITMAP_SIZE
Definition: diskmgr.h:256
void printFile(FileId file_id)
THIS METHOD IS FOR DEBUGGING ONLY. Prints contents of a file inlcuding FileId, size, capacity, and contents of each page.
Definition: swatdb_types.h:50
const std::uint32_t MAX_PAGE_NUM
Definition: swatdb_types.h:152
std::uint32_t getSize(FileId file_id)
Get method for size of a file.
const std::uint32_t PAGE_SIZE
Definition: swatdb_types.h:129
Definition: catalog.h:134
void deallocatePage(PageId page_id)
Deallocates page by adding its offest to unused_pages in the appropriate DiskFileInfo struct...
std::uint32_t capacity
Definition: diskmgr.h:295
void readPage(PageId page_id, Page *page)
Reads the page data from the Unix file into the Page object pointer.
std::uint32_t FileId
Definition: swatdb_types.h:29
Definition: diskmgr.h:285
void createFile(FileId file_id)
Creates a new Unix file, opens the fstream, initializes DiskFileInfo object, and adds <FileId...
void removeFile(FileId file_id)
Deletes the Unix file corresponding to file_id, and removes the <FileId, DiskFileInfo*> key-value pai...