taco-db
0.1.0
|
FileManager
exposes a virtual file interface based on FSFile
.
More...
#include <storage/FileManager.h>
Public Member Functions | |
FileManager () | |
~FileManager () | |
void | CloseAll () |
void | Init (std::string datadir, size_t init_size, bool create) |
Initializes the FileManager with a specified data directory path datadir . More... | |
std::unique_ptr< File > | Open (FileId fid) |
Creates or opens a virtual file. More... | |
void | ReadPage (PageNumber pid, char *buf) |
Reading a page pid in the main data file into buf . More... | |
void | WritePage (PageNumber pid, const char *buf) |
Writing a buffered page in buf to the page pid in the main data file. More... | |
void | Flush () |
Flushes all buffered writes to the main data file to disk. More... | |
std::string | GetMainDataFilePath (uint64_t DataFileId) const |
Returns the path to the specified main data file. More... | |
Private Member Functions | |
void | FormatMeta () |
void | LoadMeta () |
std::unique_ptr< File > | CreateTmpFile () |
std::unique_ptr< File > | OpenTmpFile (FileId fid) |
std::unique_ptr< File > | CreateRegularFile () |
std::unique_ptr< File > | OpenRegularFile (FileId fid) |
FileId | FindFreeFileId () |
void | AllocateL2FileDirectory (BufferId fdir1_bufid, size_t fdir1_off) |
PageNumber | AllocatePageGroup () |
void | InitFreePageList (FreePageList *fpl, PageNumber last_pg) |
PageNumber | GetNextFreePageNumber (FreePageList *fpl, BufferId meta_bufid) |
void | AddToFreePageList (FreePageList *fpl, BufferId pg_bufid, BufferId meta_bufid) |
friend | void ::taco_fileman_readpage_impl (::taco::FileManager *, ::taco::PageNumber, char *) |
friend | void ::taco_fileman_writepage_impl (::taco::FileManager *, ::taco::PageNumber, const char *) |
friend | void ::__wrap_taco_fileman_readpage_impl (::taco::FileManager *, ::taco::PageNumber, char *) |
friend | void ::__wrap_taco_fileman_writepage_impl (::taco::FileManager *, ::taco::PageNumber, const char *) |
Private Attributes | |
std::mutex | m_fsfile_extension_latch |
std::mutex | m_fdir1_latch |
std::mutex | m_meta_latch |
std::string | m_datadir |
std::string | m_maindir |
std::string | m_tmpdir |
std::string | m_waldir |
std::vector< std::unique_ptr< FSFile > > | m_mainfiles |
FMMetaPageData * | m_meta |
Friends | |
class | File |
FileManager
exposes a virtual file interface based on FSFile
.
There are three types of files -Regular file (main data file). These have persistent file ID numbers in the range of [MinRegularFileId
, MaxRegularFileId
]. A regular file is an non-empty unordered list of pages. The first page of a regular file never changes once created or deallocated unless the file gets deleted. In contrast to the common File abstraction found in a file system, the page numbers are not consecutive nor monotonic (e.g., a file may have a list of pages with PID = [5, 1, 2, 4, 3]). As a result, one may only enumerate the pages by iteratively call ‘PageHeaderData::GetNextPageNumber()’ (or ‘PageHeaderdata::GetPrevPageNumber()’), or implement their own indexing/ordering scheme.
-Temporary files. These are files to be deleted upon work done or program exit (though the program may fail to clear these files due to errors). They are assigned unique file IDs at runtime with bit TMP_FILEID_MASK set but the file ID may never be INVALID_FID (0) after zeroing its mask bit.
-Write-Ahead Logging file. These have persistent file ID numbers with WAL_FILEID_MASK set. Assignment policy TBD.
taco::FileManager::FileManager | ( | ) |
taco::FileManager::~FileManager | ( | ) |
|
private |
|
private |
|
private |
void taco::FileManager::CloseAll | ( | ) |
|
private |
|
private |
|
private |
void taco::FileManager::Flush | ( | ) |
Flushes all buffered writes to the main data file to disk.
Note: to flush a WAL or TMP file, use File::Flush().
|
private |
std::string taco::FileManager::GetMainDataFilePath | ( | uint64_t | DataFileId | ) | const |
Returns the path to the specified main data file.
|
private |
void taco::FileManager::Init | ( | std::string | datadir, |
size_t | init_size, | ||
bool | create | ||
) |
Initializes the FileManager with a specified data directory path datadir
.
Any member function except the destructor and CloseAll() may not be called before Init() is successfully called.
If create
== true, Init()
will try to create and format a new directory at the specified path. In this case, the initial size of the first main data file will be init_size
after it is rounded to the smallest value that is multiples of the page allocation group size and fits the necessary metadata.
If create
== true, it tries to initializes itself by reading data files found at the specified path. It is an error if the metadata could not be read or is obviously corrupt. init_size
is ignored in this case.
This function either succeed or throws a fatal error.
|
private |
|
private |
Creates or opens a virtual file.
If fid
is
This function never returns a null pointer but may log an error or a fatal error if it fails.
|
inline |
Reading a page pid
in the main data file into buf
.
It is a fatal error if the specified page does not exist. This is mainly for BufferManager use and all others should use File::ReadPage().
Note: reading from WAL or TMP files must go through File::ReadPage().
|
private |
|
private |
|
private |
|
private |
|
inline |
Writing a buffered page in buf
to the page pid
in the main data file.
It is a fatal error if the specified page does not exist. This is mainly for BufferManager use and all others should use File::WritePage().
Note: writing to WAL or TMP files should go through File::WritePage().
|
friend |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |