Class which represents a file in the filesystem containing database pages. More...
#include <file.h>
Public Member Functions | |
File (const File &other) | |
File & | operator= (const File &rhs) |
~File () | |
Page | allocatePage () |
Page | readPage (const PageId page_number) const |
void | writePage (const Page &new_page) |
void | deletePage (const PageId page_number) |
const std::string & | filename () const |
FileIterator | begin () |
FileIterator | end () |
Static Public Member Functions | |
static File | create (const std::string &filename) |
static File | open (const std::string &filename) |
static void | remove (const std::string &filename) |
static bool | isOpen (const std::string &filename) |
static bool | exists (const std::string &filename) |
Friends | |
class | FileIterator |
class | FileTest |
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 File & | other | ) |
badgerdb::File::~File | ( | ) |
Page badgerdb::File::allocatePage | ( | ) |
FileIterator badgerdb::File::begin | ( | ) |
|
static |
Creates a new file.
filename | Name of the file. |
FileExistsException | If the requested file already exists. |
Definition at line 29 of file file.cpp.
void badgerdb::File::deletePage | ( | const PageId | page_number | ) |
FileIterator badgerdb::File::end | ( | ) |
|
static |
|
inline |
|
static |
|
static |
Opens the file named fileName and returns the corresponding File object. It first checks if the file is already open. If so, then the new File object created uses the same input-output stream to read to or write fom that already open file. Reference count (open_counts_ static variable inside the File object) is incremented whenever an already open file is opened again. Otherwise the UNIX file is actually opened. The fileName and the stream associated with this File object are inserted into the open_streams_ map.
filename | Name of the file. |
FileNotFoundException | If the requested file doesn't exist. |
Definition at line 33 of file file.cpp.
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. |
Definition at line 149 of file file.cpp.
|
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 37 of file file.cpp.
void badgerdb::File::writePage | ( | const Page & | new_page | ) |
Writes a page into the file, replacing any existing contents. The page must have been already allocated in this file by a call to allocatePage().
new_page | Page to write. |
Definition at line 169 of file file.cpp.