taco-db
0.1.0
|
Represents an open virtual file managed by the FileManager. More...
#include <storage/FileManager.h>
Public Member Functions | |
~File () | |
Destructor. More... | |
void | Close () |
Closes the file. More... | |
constexpr bool | IsOpen () const noexcept |
void | ReadPage (PageNumber pid, char *buf) const |
Reads a page at the specified page number. More... | |
void | WritePage (PageNumber pid, const char *buf) |
Writes a page at the specified page number. More... | |
PageNumber | AllocatePage () |
Allocates a new page in the file and returns it page number. More... | |
BufferId | AllocatePage (LatchMode mode) |
Allocates a new page in the file and returns a valid buffer ID where is pinned. More... | |
void | FreePage (BufferId bufid) |
Returns a page that belongs to this file to its free page list. More... | |
void | FreePage (ScopedBufferId &bufid) |
Same as FreePage(BufferId) but prevents double free. More... | |
PageNumber | GetFirstPageNumber () const |
Returns the first page's PID. More... | |
PageNumber | GetLastPageNumber () const |
Returns the last page's PID. More... | |
void | Flush () |
Flushes bytes already written to the file. More... | |
constexpr FileId | GetFileId () const |
constexpr bool | IsMainFile () const |
constexpr bool | IsTmpFile () const |
constexpr bool | IsWalFile () const |
Private Member Functions | |
File () | |
uint64_t | AllocatePageImpl (bool need_latch, LatchMode mode) |
The actual implementation of AllocatePage(). More... | |
Private Attributes | |
FileId | m_fileid |
PageNumber | m_meta_pid |
std::unique_ptr< FSFile > | m_fsfile |
Friends | |
class | FileManager |
Represents an open virtual file managed by the FileManager.
taco::File::~File | ( | ) |
Destructor.
Automatically calls Close().
|
inlineprivate |
|
inline |
Allocates a new page in the file and returns it page number.
If this is a main file, the new page is not pinned in the buffer maanger.
If this is temporary file, this function simply extends the file by 1 page.
WAL files are not supported at the moment.
Allocates a new page in the file and returns a valid buffer ID where is pinned.
You may ignore the latch mode
parameter and pass any value to use this function.
It is an error if this overload is called on a TMP or WAL file.
|
private |
The actual implementation of AllocatePage().
void taco::File::Close | ( | ) |
Closes the file.
It never fails.
void taco::File::Flush | ( | ) |
Flushes bytes already written to the file.
Note that this may not be called on a main file, where Flush() must go through file manager.
This may be called on a temporary file.
WAL files are not supported at the moment.
void taco::File::FreePage | ( | BufferId | bufid | ) |
Returns a page that belongs to this file to its free page list.
The parameter bufid
should be a valid buffer ID where the page to return is pinned.
After the call, the pin on the page is dropped.
It is an error if it is called on a TMP or WAL file.
|
inline |
Same as FreePage(BufferId) but prevents double free.
It is an error if it is called on a TMP or WAL file.
|
inlineconstexpr |
PageNumber taco::File::GetFirstPageNumber | ( | ) | const |
Returns the first page's PID.
The first page's PID never changes so it is not possible that there is any page before the returned page.
If this is a main file, this is the first page in the linked list.
If this is a temporary file, this is always 0 (note that temporary file has a different page number space than the main files).
WAL files are not supported at the moment.
PageNumber taco::File::GetLastPageNumber | ( | ) | const |
Returns the last page's PID.
Note that concurrent threads may still append new pages into this file, so the returned PID might not be the last by the time the page is read.
If this is a main file, this is the last page in the linked list.
If this is a temporary file, this is the last page number (file size / PAGE_SIZE - 1) (note that temporary file has a different page number space than the main files).
WAL files are not supported at the moment.
|
inlineconstexpr |
|
inlineconstexprnoexcept |
|
inlineconstexpr |
|
inlineconstexpr |
void taco::File::ReadPage | ( | PageNumber | pid, |
char * | buf | ||
) | const |
Reads a page at the specified page number.
If this is a main file, this function will simply forward the call to FileManager::ReadPage().
If this is a temporary file, this function will directly read the page from the underlying FSFile.
WAL files are not supported at the moment.
void taco::File::WritePage | ( | PageNumber | pid, |
const char * | buf | ||
) |
Writes a page at the specified page number.
If this is a main file, this function will simply forward the call to FileManager::WritePage().
If this is a temporary file, this function will directly write the page into the underlying FSFile.
WAL files are not supported at the moment.
|
friend |
|
private |
|
private |
|
private |