11#ifndef _SWATDB_DISKMGR_H_
12#define _SWATDB_DISKMGR_H_
22#include <unordered_set>
23#include <unordered_map>
314 std::unordered_map <FileId, DiskFileInfo*>
file_map;
void _serializeFileHeader(SerializedFileHeader *file_header, DiskFileInfo *disk_file_info)
Serializes Unix file metadata by initializing SerializedFileHeader object given DiskFileInfo object.
void readPage(PageId page_id, Page *page)
Reads the page data from the Unix file into the Page object pointer.
std::uint32_t getSize(FileId file_id)
Get method for size of a file.
void deallocatePage(PageId page_id)
Deallocates page by adding its offest to unused_pages in the appropriate DiskFileInfo struct.
void removeFile(FileId file_id)
Deletes the Unix file corresponding to file_id, and removes the <FileId, DiskFileInfo*> key-value pai...
static const std::uint32_t DISK_HEADER_SIZE
Definition diskmgr.h:250
PageId allocatePage(FileId file_id)
Allocates a Page to the file which corresponds to file_id.
void printFile(FileId file_id)
THIS METHOD IS FOR DEBUGGING ONLY. Prints contents of a file inlcuding FileId, size,...
void _getDiskFileInfo(FileId file_id, DiskFileInfo **disk_file_info)
Initializes DiskFileInfo** of the given FileId.
bool isValidPage(PageId page_id)
Checks if the page of a given pageId is valid.
void createFile(FileId file_id)
Creates a new Unix file, opens the fstream, initializes DiskFileInfo object, and adds <FileId,...
DiskManager(Catalog *catalog)
DiskManager constructor. Uses Catalog object pointer and a vector of FileIds to initialize file_map.
std::unordered_map< FileId, DiskFileInfo * > file_map
Definition diskmgr.h:314
std::mutex file_map_mtx
Definition diskmgr.h:326
char temp_page[PAGE_SIZE]
Definition diskmgr.h:331
~DiskManager()
DiskManager destructor. All pages have been written to disk prior to this call.
void _flushDiskFileInfo(FileId file_id)
Writes data from DiskFileInfo struct to Unix file for the given FileId.
void _deserializeFileHeader(SerializedFileHeader *file_header, DiskFileInfo *disk_file_info)
Intializes DiskFileInfo object given SerializedFileHeader object.
Catalog * catalog
Definition diskmgr.h:321
static const std::uint32_t DISK_HEADER_BITMAP_SIZE
Definition diskmgr.h:258
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.
std::uint32_t getCapacity(FileId file_id)
Get method for the capacity of a file.
std::mutex file_mtx
Definition diskmgr.h:307
std::fstream file
Definition diskmgr.h:292
std::unordered_set< PageNum > unused_pages
Definition diskmgr.h:302
std::uint32_t capacity
Definition diskmgr.h:297
Definition swatdb_types.h:54
std::uint32_t FileId
Definition swatdb_types.h:33
const std::uint32_t PAGE_SIZE
Definition swatdb_types.h:258
const std::uint32_t MAX_PAGE_NUM
Definition swatdb_types.h:281