Class which represents a file in the filesystem containing database pages. More...
#include <file.h>
Public Member Functions | |
File (const std::string &name, const bool create_new) | |
virtual | ~File () |
virtual Page | allocatePage (PageId &new_page_number)=0 |
virtual Page | readPage (const PageId page_number) const =0 |
virtual void | writePage (const PageId page_number, const Page &new_page)=0 |
virtual void | deletePage (const PageId page_number)=0 |
const std::string & | filename () const |
PageId | getFirstPageNo () |
Static Public Member Functions | |
static void | remove (const std::string &filename) |
static bool | isOpen (const std::string &filename) |
static bool | exists (const std::string &filename) |
Protected Types | |
typedef std::map< std::string, std::shared_ptr< std::fstream > > | StreamMap |
typedef std::map< std::string, int > | CountMap |
Protected Member Functions | |
void | openIfNeeded (const bool create_new) |
void | close () |
FileHeader | readHeader () const |
void | writeHeader (const FileHeader &header) |
Static Protected Member Functions | |
static std::streampos | pagePosition (const PageId page_number) |
Protected Attributes | |
std::string | filename_ |
std::shared_ptr< std::fstream > | stream_ |
Static Protected Attributes | |
static StreamMap | open_streams_ |
static CountMap | open_counts_ |
Friends | |
class | FileIterator |
Class which represents a file in the filesystem containing database pages.
The File class wraps a stream to an underlying file on disk. Files contain fixed-sized pages, and they never deallocate space (though they do reuse deleted pages if possible). If multiple File objects refer to the same underlying file, they will share the stream in memory. If a file that has already been opened (possibly by another query), then the File class detects this (by looking in the open_streams_ map) and just returns a file object with the already created stream for the file without actually opening the UNIX file again.
badgerdb::File::File | ( | const std::string & | name, |
const bool | create_new | ||
) |
Constructs a file object representing a file on the filesystem.
name | Name of file. |
create_new | Whether to create a new file. |
FileExistsException | If the underlying file exists and create_new is true. |
FileNotFoundException | If the underlying file doesn't exist and create_new is false. |
Definition at line 67 of file file.cpp.
|
virtual |
Destructor that automatically closes the underlying file if no other File objects are using it.
Allocates a new page in the file.
Implemented in badgerdb::BlobFile, and badgerdb::PageFile.
|
protected |
|
pure virtual |
Deletes a page from the file.
page_number | Number of page to delete. |
Implemented in badgerdb::BlobFile, and badgerdb::PageFile.
|
static |
|
inline |
PageId badgerdb::File::getFirstPageNo | ( | ) |
|
static |
|
protected |
Opens the underlying file named in filename_. This method only opens the file if no other File objects exist that access the same filesystem file; otherwise, it reuses the existing stream.
create_new | Whether to create a new file. |
FileExistsException | If the underlying file exists and create_new is true. |
FileNotFoundException | If the underlying file doesn't exist and create_new is false. |
Definition at line 78 of file file.cpp.
|
inlinestaticprotected |
|
protected |
Reads an existing page from the file.
page_number | Number of page to read. |
InvalidPageException | If the page doesn't exist in the file or is not currently used. |
Implemented in badgerdb::BlobFile, and badgerdb::PageFile.
|
static |
Deletes an existing file.
filename | Name of the file. |
FileNotFoundException | If the file doesn't exist. |
FileOpenException | If the file is currently open. |
Definition at line 29 of file file.cpp.
|
protected |
|
pure virtual |
Writes a page into the file at the given page number. No bounds checking is performed.
page_number | Number of page whose contents to replace. |
new_page | Page to write. |
Implemented in badgerdb::BlobFile, and badgerdb::PageFile.
|
protected |
|
staticprotected |
|
staticprotected |
|
protected |