0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
Hypertable::MetaLog::Reader Class Reference

Reads a MetaLog. More...

#include <MetaLogReader.h>

Collaboration diagram for Hypertable::MetaLog::Reader:
Collaboration graph
[legend]

Public Types

enum  Flags { LOAD_ALL_ENTITIES =1 }
 

Public Member Functions

 Reader (FilesystemPtr &fs, DefinitionPtr &definition, int flags=0)
 Constructor. More...
 
 Reader (FilesystemPtr &fs, DefinitionPtr &definition, const std::string &path, int flags=0)
 Constructor. More...
 
void get_entities (std::vector< EntityPtr > &entities)
 Returns latest version of all entities. More...
 
void get_all_entities (std::vector< EntityPtr > &entities)
 Returns all versions of all entities. More...
 
void reload ()
 Loads MetaLog. More...
 
int32_t next_file_number ()
 Returns next unused numeric file name. More...
 
void load_file (const std::string &fname)
 Loads MetaLog file. More...
 
uint16_t version ()
 Returns MetaLog Definition version read from log file header. More...
 

Private Member Functions

void verify_backup (int32_t file_num)
 Sanity check local backup file. More...
 
void read_header (int fd, int64_t *offsetp)
 Reads the log file header. More...
 

Private Attributes

FilesystemPtr m_fs
 Smart pointer to Filesystem object. More...
 
MetaLog::DefinitionPtr m_definition
 Smart pointer to MetaLog Definition. More...
 
std::string m_path
 Path name of MetaLog directory. More...
 
int m_flags
 Flags that control read behavior. More...
 
std::deque< int32_t > m_file_nums
 Vector of numeric file names found in log directory. More...
 
std::map< EntityHeader, EntityPtrm_entity_map
 Map containing latest version of each Entity read from MetaLog. More...
 
std::vector< EntityPtrm_entities
 Vector containing all versions of each Entity read from MetaLog. More...
 
std::string m_backup_path
 Local backup path initialized in primary_metalog_reader_constructor. More...
 
uint16_t m_version
 MetaLog Definition version read from log file header. More...
 

Detailed Description

Reads a MetaLog.

This class is part of a group of generic meta log manipulation classes. A meta log is a server state log and is currently used by both the RangeServer and the Master servers. The set of valid MetaLog::Entity classes are defined by a MetaLog::Definition class that is defined for each server. This class reads a meta log and provides access to the latest versions of live MetaLog entities that have been persisted in the log.

Definition at line 56 of file MetaLogReader.h.

Constructor & Destructor Documentation

Reader::Reader ( FilesystemPtr fs,
DefinitionPtr definition,
int  flags = 0 
)

Constructor.

Constructs and empty object. This constructor is used when opening a specific MetaLog fragment file and is typically followed by a call to load_file().

Parameters
fsSmart pointer to Filesystem object
definitionSmart pointer to Definition object
flagsFlags that control reading behavior

Definition at line 52 of file MetaLogReader.cc.

Reader::Reader ( FilesystemPtr fs,
DefinitionPtr definition,
const std::string &  path,
int  flags = 0 
)

Constructor.

This constructor initializes the Reader and loads the MetaLog specified by path. It initializes m_backup_path as follows:

$data_dir     = Config::properties->get_str("Hypertable.DataDirectory");
$name         = m_definition->name();
$backup_label = m_definition->backup_label()
m_backup_path = $data_dir/run/log_backup/$name/$backup_label

It then calls reload() to load the MetaLog.

Parameters
fsSmart pointer to Filesystem object
definitionSmart pointer to Definition object
pathPath to MetaLog directory
flagsFlags that control reading behavior

Definition at line 57 of file MetaLogReader.cc.

Member Function Documentation

void Reader::get_all_entities ( std::vector< EntityPtr > &  entities)

Returns all versions of all entities.

Parameters
entitiesReference to vector to hold returned entities

Definition at line 79 of file MetaLogReader.cc.

void Reader::get_entities ( std::vector< EntityPtr > &  entities)

Returns latest version of all entities.

Parameters
entitiesReference to vector to hold returned entities

Definition at line 73 of file MetaLogReader.cc.

void Reader::load_file ( const std::string &  fname)

Loads MetaLog file.

This method opens fname and reads the header with a call to read_header(). It then reads each Entity from the file by first reading and decoding the EntityHeader. If the flags field of the header has the EntityHeader::FLAG_REMOVE bit set, it is purged from m_entity_map and skipped. Otherwise, the entity is constructed with a call to the Definition::create() of m_definition, afterwhich the entity's state is decoded with a call to the entity's Entity::decode() method and it is inserted into both m_entity_map and m_entities. If a read comes up short, this method will throw an Exception with error code Error::METALOG_ENTRY_TRUNCATED. If there is a checksum mis-match, it will throw an Exception with error code Error::METALOG_CHECKSUM_MISMATCH. If after the complete file is read, if an EntityRecover was not encountered, an Exception is thrown with error code Error::METALOG_MISSING_RECOVER_ENTITY.

Parameters
fnameFull pathname of MetaLog file to load
Exceptions
%Exceptionwith code Error::METALOG_ENTRY_TRUNCATED, or Error::METALOG_CHECKSUM_MISMATCH, or Error::METALOG_MISSING_RECOVER_ENTITY, or one of the exceptions returned by Client::open_buffered(), or Client::read().

Definition at line 133 of file MetaLogReader.cc.

int32_t Hypertable::MetaLog::Reader::next_file_number ( )
inline

Returns next unused numeric file name.

This method returns #m_next_filenum which is set during the log directory scan by taking the largest numerically named file and adding one.

Returns
Next unused numeric file name.

Definition at line 120 of file MetaLogReader.h.

void Reader::read_header ( int  fd,
int64_t *  offsetp 
)
private

Reads the log file header.

Reads and decodes the log file header (MetaLog::Header). If the read comes up short or the name in the header does not match what is returned by the Definition::name() method of m_definition, an Exception is thrown with error code Error::METALOG_BAD_HEADER. If the version read from the header is greater than what is returned by Definition::version() method of m_definition, an exception is thrown with error code Error::METALOG_VERSION_MISMATCH. Otherwise, m_version is set to the version read from the header, and *offsetp is incremented by the length of the header.

Parameters
fdOpen file descriptor for MetaLog file
offsetpPointer to current offset within the file
Exceptions
Exceptionwith code Error::METALOG_BAD_HEADER or Error::METALOG_VERSION_MISMATCH, or one of the exceptions thrown by Client::read()

Definition at line 223 of file MetaLogReader.cc.

void Reader::reload ( )

Loads MetaLog.

This method scans the MetaLog directory with a call to scan_log_directory() and then loads the largest numerically named file in the directory with a call to load_file(). The m_file_nums vector is populated with the numeric file names found in log directory. This method propagates all exceptions of type Error::METALOG_ERROR and converts all other exceptions to Error::METALOG_READ_ERROR and rethrows.

Exceptions
Exceptionwith one of the Error::METALOG_ERROR codes.

Definition at line 84 of file MetaLogReader.cc.

void Reader::verify_backup ( int32_t  file_num)
private

Sanity check local backup file.

This method throws an Exception with error code Error::METALOG_BACKUP_FILE_MISMATCH if the backup file with numeric name file_num exists and has size less than the corresponding file in the FS. Otherwise it returns successfuly.

Parameters
file_numNumeric file name of file for which to verify backup

Definition at line 114 of file MetaLogReader.cc.

uint16_t Hypertable::MetaLog::Reader::version ( )
inline

Returns MetaLog Definition version read from log file header.

Returns
MetaLog Definition version read from log file header.

Definition at line 151 of file MetaLogReader.h.

Member Data Documentation

std::string Hypertable::MetaLog::Reader::m_backup_path
private

Local backup path initialized in primary_metalog_reader_constructor.

Definition at line 206 of file MetaLogReader.h.

MetaLog::DefinitionPtr Hypertable::MetaLog::Reader::m_definition
private

Smart pointer to MetaLog Definition.

Definition at line 188 of file MetaLogReader.h.

std::vector<EntityPtr> Hypertable::MetaLog::Reader::m_entities
private

Vector containing all versions of each Entity read from MetaLog.

Definition at line 203 of file MetaLogReader.h.

std::map<EntityHeader, EntityPtr> Hypertable::MetaLog::Reader::m_entity_map
private

Map containing latest version of each Entity read from MetaLog.

Definition at line 200 of file MetaLogReader.h.

std::deque<int32_t> Hypertable::MetaLog::Reader::m_file_nums
private

Vector of numeric file names found in log directory.

Definition at line 197 of file MetaLogReader.h.

int Hypertable::MetaLog::Reader::m_flags
private

Flags that control read behavior.

Definition at line 194 of file MetaLogReader.h.

FilesystemPtr Hypertable::MetaLog::Reader::m_fs
private

Smart pointer to Filesystem object.

Definition at line 185 of file MetaLogReader.h.

std::string Hypertable::MetaLog::Reader::m_path
private

Path name of MetaLog directory.

Definition at line 191 of file MetaLogReader.h.

uint16_t Hypertable::MetaLog::Reader::m_version
private

MetaLog Definition version read from log file header.

Definition at line 209 of file MetaLogReader.h.


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