taco-db  0.1.0
Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
taco::FileManager Class Reference

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< FileOpen (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< FileCreateTmpFile ()
 
std::unique_ptr< FileOpenTmpFile (FileId fid)
 
std::unique_ptr< FileCreateRegularFile ()
 
std::unique_ptr< FileOpenRegularFile (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
 
FMMetaPageDatam_meta
 

Friends

class File
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ FileManager()

taco::FileManager::FileManager ( )

◆ ~FileManager()

taco::FileManager::~FileManager ( )

Member Function Documentation

◆ AddToFreePageList()

void taco::FileManager::AddToFreePageList ( FreePageList fpl,
BufferId  pg_bufid,
BufferId  meta_bufid 
)
private

◆ AllocateL2FileDirectory()

void taco::FileManager::AllocateL2FileDirectory ( BufferId  fdir1_bufid,
size_t  fdir1_off 
)
private

◆ AllocatePageGroup()

PageNumber taco::FileManager::AllocatePageGroup ( )
private

◆ CloseAll()

void taco::FileManager::CloseAll ( )

◆ CreateRegularFile()

std::unique_ptr< File > taco::FileManager::CreateRegularFile ( )
private

◆ CreateTmpFile()

std::unique_ptr< File > taco::FileManager::CreateTmpFile ( )
private

◆ FindFreeFileId()

FileId taco::FileManager::FindFreeFileId ( )
private

◆ Flush()

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().

◆ FormatMeta()

void taco::FileManager::FormatMeta ( )
private

◆ GetMainDataFilePath()

std::string taco::FileManager::GetMainDataFilePath ( uint64_t  DataFileId) const

Returns the path to the specified main data file.

◆ GetNextFreePageNumber()

PageNumber taco::FileManager::GetNextFreePageNumber ( FreePageList fpl,
BufferId  meta_bufid 
)
private

◆ Init()

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.

◆ InitFreePageList()

void taco::FileManager::InitFreePageList ( FreePageList fpl,
PageNumber  last_pg 
)
private

◆ LoadMeta()

void taco::FileManager::LoadMeta ( )
private

◆ Open()

std::unique_ptr< File > taco::FileManager::Open ( FileId  fid)

Creates or opens a virtual file.

If fid is

  • NEW_REGULAR_FID, it creates a new regular file.
  • a valid regular file ID. it opens the file if it exists. It is an error if the file does not exist.
  • NEW_TMP_FID, it creates a new temporary file.
  • any valid temporary file ID, it opens the temporary file. It is an error if the file does not exist.
  • any valid WAL file ID, it creates or opens the WAL file.

This function never returns a null pointer but may log an error or a fatal error if it fails.

◆ OpenRegularFile()

std::unique_ptr< File > taco::FileManager::OpenRegularFile ( FileId  fid)
private

◆ OpenTmpFile()

std::unique_ptr< File > taco::FileManager::OpenTmpFile ( FileId  fid)
private

◆ ReadPage()

void taco::FileManager::ReadPage ( PageNumber  pid,
char *  buf 
)
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().

◆ void ::__wrap_taco_fileman_readpage_impl()

taco::FileManager::void ::__wrap_taco_fileman_readpage_impl ( ::taco::FileManager ,
::taco::PageNumber  ,
char *   
)
private

◆ void ::__wrap_taco_fileman_writepage_impl()

taco::FileManager::void ::__wrap_taco_fileman_writepage_impl ( ::taco::FileManager ,
::taco::PageNumber  ,
const char *   
)
private

◆ void ::taco_fileman_readpage_impl()

taco::FileManager::void ::taco_fileman_readpage_impl ( ::taco::FileManager ,
::taco::PageNumber  ,
char *   
)
private

◆ void ::taco_fileman_writepage_impl()

taco::FileManager::void ::taco_fileman_writepage_impl ( ::taco::FileManager ,
::taco::PageNumber  ,
const char *   
)
private

◆ WritePage()

void taco::FileManager::WritePage ( PageNumber  pid,
const char *  buf 
)
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().

Friends And Related Function Documentation

◆ File

friend class File
friend

Member Data Documentation

◆ m_datadir

std::string taco::FileManager::m_datadir
private

◆ m_fdir1_latch

std::mutex taco::FileManager::m_fdir1_latch
private

◆ m_fsfile_extension_latch

std::mutex taco::FileManager::m_fsfile_extension_latch
private

◆ m_maindir

std::string taco::FileManager::m_maindir
private

◆ m_mainfiles

std::vector<std::unique_ptr<FSFile> > taco::FileManager::m_mainfiles
private

◆ m_meta

FMMetaPageData* taco::FileManager::m_meta
private

◆ m_meta_latch

std::mutex taco::FileManager::m_meta_latch
private

◆ m_tmpdir

std::string taco::FileManager::m_tmpdir
private

◆ m_waldir

std::string taco::FileManager::m_waldir
private

The documentation for this class was generated from the following files: