Zero  0.1.0
Classes | Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | List of all members
ArchiveIndex Class Reference

Encapsulates all file and I/O operations on the log archive. More...

#include <logarchive_index.h>

Classes

struct  BlockEntry
 
struct  BlockHeader
 
struct  RunInfo
 

Public Member Functions

 ArchiveIndex (const sm_options &options)
 
virtual ~ArchiveIndex ()
 
size_t getBlockSize () const
 
std::string getArchDir () const
 
lsn_t getLastLSN ()
 
lsn_t getLastLSN (unsigned level)
 
lsn_t getFirstLSN (unsigned level)
 
rc_t openNewRun (unsigned level)
 
rc_t append (char *data, size_t length, unsigned level)
 
rc_t closeCurrentRun (lsn_t runEndLSN, unsigned level, PageID maxPID=0)
 
RunFileopenForScan (const RunId &runid)
 
void closeScan (const RunId &runid)
 
rc_t readBlock (int fd, char *buf, size_t &offset, size_t readSize=0)
 
void listFiles (std::vector< std::string > &list, int level=-1)
 
void listFileStats (std::list< RunId > &list, int level=-1)
 
void deleteRuns (unsigned replicationFactor=0)
 
size_t getSkipLogrecSize () const
 
void newBlock (const vector< pair< PageID, size_t >> &buckets, unsigned level)
 
rc_t finishRun (lsn_t first, lsn_t last, PageID maxPID, int fd, off_t offset, unsigned level)
 
template<class Input >
void probe (std::vector< Input > &, PageID, PageID, lsn_t startLSN, lsn_t endLSN=lsn_t::null)
 
void getBlockCounts (RunFile *, size_t *indexBlocks, size_t *dataBlocks)
 
void loadRunInfo (RunFile *, const RunId &)
 
void startNewRun (unsigned level)
 
unsigned getMaxLevel () const
 
size_t getBucketSize ()
 
size_t getRunCount (unsigned level)
 
void dumpIndex (ostream &out)
 
void dumpIndex (ostream &out, const RunId &runid)
 
template<class OutputIter >
void listRunsNonOverlapping (OutputIter out)
 

Static Public Member Functions

static bool parseRunFileName (string fname, RunId &fstats)
 
static size_t getFileSize (int fd)
 

Static Public Attributes

static const string RUN_PREFIX = "archive_"
 
static const string CURR_RUN_PREFIX = "current_run_"
 
static const string run_regex
 
static const string current_regex = "^current_run_[1-9][0-9]*$"
 

Private Member Functions

void appendNewRun (unsigned level)
 
size_t findRun (lsn_t lsn, unsigned level)
 
size_t findEntry (RunInfo *run, PageID pid, int from=-1, int to=-1)
 
rc_t serializeRunInfo (RunInfo &, int fd, off_t)
 
lsn_t roundToEndLSN (lsn_t lsn, unsigned level)
 
fs::path make_run_path (lsn_t begin, lsn_t end, unsigned level=1) const
 
fs::path make_current_run_path (unsigned level) const
 

Private Attributes

std::string archdir
 
std::vector< int > appendFd
 
std::vector< off_t > appendPos
 
size_t blockSize
 
fs::path archpath
 
std::vector< std::vector< RunInfo > > runs
 
std::vector< int > lastFinished
 
size_t bucketSize
 
unsigned maxLevel
 
std::unique_ptr< RunRecyclerrunRecycler
 
srwlock_t _mutex
 
std::unordered_map< RunId, RunFile_open_files
 Cache for open files (for scans only) More...
 
srwlock_t _open_file_mutex
 
bool directIO
 

Detailed Description

Encapsulates all file and I/O operations on the log archive.

The directory object serves the following purposes:

Author
Caetano Sauer

Constructor & Destructor Documentation

§ ArchiveIndex()

ArchiveIndex::ArchiveIndex ( const sm_options options)

§ ~ArchiveIndex()

ArchiveIndex::~ArchiveIndex ( )
virtual

Member Function Documentation

§ append()

rc_t ArchiveIndex::append ( char *  data,
size_t  length,
unsigned  level 
)

§ appendNewRun()

void ArchiveIndex::appendNewRun ( unsigned  level)
private

§ closeCurrentRun()

rc_t ArchiveIndex::closeCurrentRun ( lsn_t  runEndLSN,
unsigned  level,
PageID  maxPID = 0 
)

§ closeScan()

void ArchiveIndex::closeScan ( const RunId runid)

§ deleteRuns()

void ArchiveIndex::deleteRuns ( unsigned  replicationFactor = 0)

§ dumpIndex() [1/2]

void ArchiveIndex::dumpIndex ( ostream &  out)

§ dumpIndex() [2/2]

void ArchiveIndex::dumpIndex ( ostream &  out,
const RunId runid 
)

§ findEntry()

size_t ArchiveIndex::findEntry ( RunInfo run,
PageID  pid,
int  from = -1,
int  to = -1 
)
private

§ findRun()

size_t ArchiveIndex::findRun ( lsn_t  lsn,
unsigned  level 
)
private

§ finishRun()

rc_t ArchiveIndex::finishRun ( lsn_t  first,
lsn_t  last,
PageID  maxPID,
int  fd,
off_t  offset,
unsigned  level 
)

§ getArchDir()

std::string ArchiveIndex::getArchDir ( ) const
inline

§ getBlockCounts()

void ArchiveIndex::getBlockCounts ( RunFile runFile,
size_t *  indexBlocks,
size_t *  dataBlocks 
)

§ getBlockSize()

size_t ArchiveIndex::getBlockSize ( ) const
inline

§ getBucketSize()

size_t ArchiveIndex::getBucketSize ( )
inline

§ getFileSize()

size_t ArchiveIndex::getFileSize ( int  fd)
static

§ getFirstLSN()

lsn_t ArchiveIndex::getFirstLSN ( unsigned  level)

§ getLastLSN() [1/2]

lsn_t ArchiveIndex::getLastLSN ( )

§ getLastLSN() [2/2]

lsn_t ArchiveIndex::getLastLSN ( unsigned  level)

§ getMaxLevel()

unsigned ArchiveIndex::getMaxLevel ( ) const
inline

§ getRunCount()

size_t ArchiveIndex::getRunCount ( unsigned  level)
inline

§ getSkipLogrecSize()

size_t ArchiveIndex::getSkipLogrecSize ( ) const

§ listFiles()

void ArchiveIndex::listFiles ( std::vector< std::string > &  list,
int  level = -1 
)

§ listFileStats()

void ArchiveIndex::listFileStats ( std::list< RunId > &  list,
int  level = -1 
)

§ listRunsNonOverlapping()

template<class OutputIter >
void ArchiveIndex::listRunsNonOverlapping ( OutputIter  out)
inline

§ loadRunInfo()

void ArchiveIndex::loadRunInfo ( RunFile runFile,
const RunId fstats 
)

§ make_current_run_path()

fs::path ArchiveIndex::make_current_run_path ( unsigned  level) const
private

§ make_run_path()

fs::path ArchiveIndex::make_run_path ( lsn_t  begin,
lsn_t  end,
unsigned  level = 1 
) const
private

§ newBlock()

void ArchiveIndex::newBlock ( const vector< pair< PageID, size_t >> &  buckets,
unsigned  level 
)

§ openForScan()

RunFile * ArchiveIndex::openForScan ( const RunId runid)

§ openNewRun()

rc_t ArchiveIndex::openNewRun ( unsigned  level)

Opens a new run file of the log archive, closing the current run if it exists. Upon closing, the file is renamed to contain the LSN range of the log records contained in that run. The upper boundary (lastLSN) is exclusive, meaning that it will be found on the beginning of the following run. This also allows checking the filenames for any any range of the LSNs which was "lost" when archiving.

We assume the rename operation is atomic, even in case of OS crashes.

§ parseRunFileName()

bool ArchiveIndex::parseRunFileName ( string  fname,
RunId fstats 
)
static

§ probe()

template<class Input >
void ArchiveIndex::probe ( std::vector< Input > &  inputs,
PageID  startPID,
PageID  endPID,
lsn_t  startLSN,
lsn_t  endLSN = lsn_t::null 
)

§ readBlock()

rc_t ArchiveIndex::readBlock ( int  fd,
char *  buf,
size_t &  offset,
size_t  readSize = 0 
)

Note: buffer must be allocated for at least readSize + IO_ALIGN bytes, otherwise direct I/O with alignment will corrupt memory.

§ roundToEndLSN()

lsn_t ArchiveIndex::roundToEndLSN ( lsn_t  lsn,
unsigned  level 
)
private

§ serializeRunInfo()

rc_t ArchiveIndex::serializeRunInfo ( RunInfo run,
int  fd,
off_t  offset 
)
private

§ startNewRun()

void ArchiveIndex::startNewRun ( unsigned  level)

Member Data Documentation

§ _mutex

srwlock_t ArchiveIndex::_mutex
mutableprivate

§ _open_file_mutex

srwlock_t ArchiveIndex::_open_file_mutex
mutableprivate

§ _open_files

std::unordered_map<RunId, RunFile> ArchiveIndex::_open_files
private

Cache for open files (for scans only)

§ appendFd

std::vector<int> ArchiveIndex::appendFd
private

§ appendPos

std::vector<off_t> ArchiveIndex::appendPos
private

§ archdir

std::string ArchiveIndex::archdir
private

§ archpath

fs::path ArchiveIndex::archpath
private

§ blockSize

size_t ArchiveIndex::blockSize
private

§ bucketSize

size_t ArchiveIndex::bucketSize
private

Whether this index uses variable-sized buckets, i.e., entries in the index refer to fixed ranges of page ID for which the amount of log records is variable. The number gives the size of a bucket in terms of number of page ID's (or segment size in the restore case). If this is zero, then the index behaves like a B-tree, in which a bucket corresponds to a block, therefore having fixed sizes (but variable number of log records, obviously).

§ CURR_RUN_PREFIX

const string ArchiveIndex::CURR_RUN_PREFIX = "current_run_"
static

§ current_regex

const string ArchiveIndex::current_regex = "^current_run_[1-9][0-9]*$"
static

§ directIO

bool ArchiveIndex::directIO
private

§ lastFinished

std::vector<int> ArchiveIndex::lastFinished
private

§ maxLevel

unsigned ArchiveIndex::maxLevel
private

§ RUN_PREFIX

const string ArchiveIndex::RUN_PREFIX = "archive_"
static

§ run_regex

const string ArchiveIndex::run_regex
static
Initial value:
=
"^archive_([1-9][0-9]*)_([1-9][0-9]*\\.[0-9]+)-([1-9][0-9]*\\.[0-9]+)$"

§ runRecycler

std::unique_ptr<RunRecycler> ArchiveIndex::runRecycler
private

§ runs

std::vector<std::vector<RunInfo> > ArchiveIndex::runs
private

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