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

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< FSFilem_fsfile
 

Friends

class FileManager
 

Detailed Description

Represents an open virtual file managed by the FileManager.

Constructor & Destructor Documentation

◆ ~File()

taco::File::~File ( )

Destructor.

Automatically calls Close().

◆ File()

taco::File::File ( )
inlineprivate

Member Function Documentation

◆ AllocatePage() [1/2]

PageNumber taco::File::AllocatePage ( )
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.

◆ AllocatePage() [2/2]

BufferId taco::File::AllocatePage ( LatchMode  mode)
inline

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.

◆ AllocatePageImpl()

uint64_t taco::File::AllocatePageImpl ( bool  need_latch,
LatchMode  mode 
)
private

The actual implementation of AllocatePage().

◆ Close()

void taco::File::Close ( )

Closes the file.

It never fails.

◆ Flush()

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.

◆ FreePage() [1/2]

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.

◆ FreePage() [2/2]

void taco::File::FreePage ( ScopedBufferId bufid)
inline

Same as FreePage(BufferId) but prevents double free.

It is an error if it is called on a TMP or WAL file.

◆ GetFileId()

constexpr FileId taco::File::GetFileId ( ) const
inlineconstexpr

◆ GetFirstPageNumber()

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.

◆ GetLastPageNumber()

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.

◆ IsMainFile()

constexpr bool taco::File::IsMainFile ( ) const
inlineconstexpr

◆ IsOpen()

constexpr bool taco::File::IsOpen ( ) const
inlineconstexprnoexcept

◆ IsTmpFile()

constexpr bool taco::File::IsTmpFile ( ) const
inlineconstexpr

◆ IsWalFile()

constexpr bool taco::File::IsWalFile ( ) const
inlineconstexpr

◆ ReadPage()

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.

◆ WritePage()

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.

Friends And Related Function Documentation

◆ FileManager

friend class FileManager
friend

Member Data Documentation

◆ m_fileid

FileId taco::File::m_fileid
private

◆ m_fsfile

std::unique_ptr<FSFile> taco::File::m_fsfile
private

◆ m_meta_pid

PageNumber taco::File::m_meta_pid
private

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