Reads a MetaLog. More...
#include <MetaLogReader.h>

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, EntityPtr > | m_entity_map |
| Map containing latest version of each Entity read from MetaLog. More... | |
| std::vector< EntityPtr > | m_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... | |
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.
| 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().
| fs | Smart pointer to Filesystem object |
| definition | Smart pointer to Definition object |
| flags | Flags 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.
| fs | Smart pointer to Filesystem object |
| definition | Smart pointer to Definition object |
| path | Path to MetaLog directory |
| flags | Flags that control reading behavior |
Definition at line 57 of file MetaLogReader.cc.
| void Reader::get_all_entities | ( | std::vector< EntityPtr > & | entities | ) |
Returns all versions of all entities.
| entities | Reference 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.
| entities | Reference 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.
| fname | Full pathname of MetaLog file to load |
| %Exception | with 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.
|
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.
Definition at line 120 of file MetaLogReader.h.
|
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.
| fd | Open file descriptor for MetaLog file |
| offsetp | Pointer to current offset within the file |
| Exception | with 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.
| Exception | with one of the Error::METALOG_ERROR codes. |
Definition at line 84 of file MetaLogReader.cc.
|
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.
| file_num | Numeric file name of file for which to verify backup |
Definition at line 114 of file MetaLogReader.cc.
|
inline |
Returns MetaLog Definition version read from log file header.
Definition at line 151 of file MetaLogReader.h.
|
private |
Local backup path initialized in primary_metalog_reader_constructor.
Definition at line 206 of file MetaLogReader.h.
|
private |
Smart pointer to MetaLog Definition.
Definition at line 188 of file MetaLogReader.h.
|
private |
Vector containing all versions of each Entity read from MetaLog.
Definition at line 203 of file MetaLogReader.h.
|
private |
Map containing latest version of each Entity read from MetaLog.
Definition at line 200 of file MetaLogReader.h.
|
private |
Vector of numeric file names found in log directory.
Definition at line 197 of file MetaLogReader.h.
|
private |
Flags that control read behavior.
Definition at line 194 of file MetaLogReader.h.
|
private |
Smart pointer to Filesystem object.
Definition at line 185 of file MetaLogReader.h.
|
private |
Path name of MetaLog directory.
Definition at line 191 of file MetaLogReader.h.
|
private |
MetaLog Definition version read from log file header.
Definition at line 209 of file MetaLogReader.h.
1.8.8