0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
MetaLogReader.h
Go to the documentation of this file.
1 /* -*- c++ -*-
2  * Copyright (C) 2007-2015 Hypertable, Inc.
3  *
4  * This file is part of Hypertable.
5  *
6  * Hypertable is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; version 3 of the
9  * License, or any later version.
10  *
11  * Hypertable is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  * 02110-1301, USA.
20  */
21 
28 #ifndef Hypertable_Lib_MetaLogReader_h
29 #define Hypertable_Lib_MetaLogReader_h
30 
31 #include "MetaLogDefinition.h"
32 
33 #include <Common/Filesystem.h>
34 
35 #include <deque>
36 #include <map>
37 #include <memory>
38 #include <vector>
39 
40 namespace Hypertable {
41 
42  namespace MetaLog {
43 
56  class Reader {
57 
58  public:
59 
60  enum Flags {
62  };
63 
72  Reader(FilesystemPtr &fs, DefinitionPtr &definition, int flags=0);
73 
90  Reader(FilesystemPtr &fs, DefinitionPtr &definition, const std::string &path, int flags=0);
91 
95  void get_entities(std::vector<EntityPtr> &entities);
96 
100  void get_all_entities(std::vector<EntityPtr> &entities);
101 
112  void reload();
113 
120  int32_t next_file_number() {
121  return m_file_nums.empty() ? 0 : m_file_nums.front() + 1;
122  }
123 
146  void load_file(const std::string &fname);
147 
151  uint16_t version() { return m_version; }
152 
153  private:
154 
164  void verify_backup(int32_t file_num);
165 
182  void read_header(int fd, int64_t *offsetp);
183 
186 
189 
191  std::string m_path;
192 
194  int m_flags;
195 
197  std::deque<int32_t> m_file_nums;
198 
200  std::map<EntityHeader, EntityPtr> m_entity_map;
201 
203  std::vector<EntityPtr> m_entities;
204 
206  std::string m_backup_path;
207 
209  uint16_t m_version;
210  };
211 
213  typedef std::shared_ptr<Reader> ReaderPtr;
214 
216  }
217 }
218 
219 #endif // Hypertable_Lib_MetaLogReader_h
void read_header(int fd, int64_t *offsetp)
Reads the log file header.
int m_flags
Flags that control read behavior.
Abstract base class for a filesystem.
void reload()
Loads MetaLog.
void get_all_entities(std::vector< EntityPtr > &entities)
Returns all versions of all entities.
uint16_t version()
Returns MetaLog Definition version read from log file header.
Declarations for MetaLog::Definition.
std::string m_backup_path
Local backup path initialized in primary_metalog_reader_constructor.
MetaLog::DefinitionPtr m_definition
Smart pointer to MetaLog Definition.
std::map< EntityHeader, EntityPtr > m_entity_map
Map containing latest version of each Entity read from MetaLog.
int32_t next_file_number()
Returns next unused numeric file name.
void get_entities(std::vector< EntityPtr > &entities)
Returns latest version of all entities.
FilesystemPtr m_fs
Smart pointer to Filesystem object.
Hypertable definitions
std::shared_ptr< Reader > ReaderPtr
Smart pointer to Reader.
std::vector< EntityPtr > m_entities
Vector containing all versions of each Entity read from MetaLog.
uint16_t m_version
MetaLog Definition version read from log file header.
std::shared_ptr< Filesystem > FilesystemPtr
Smart pointer to Filesystem.
Definition: Filesystem.h:572
Reader(FilesystemPtr &fs, DefinitionPtr &definition, int flags=0)
Constructor.
void load_file(const std::string &fname)
Loads MetaLog file.
std::deque< int32_t > m_file_nums
Vector of numeric file names found in log directory.
std::shared_ptr< Definition > DefinitionPtr
Smart pointer to Definition.
std::string m_path
Path name of MetaLog directory.
void verify_backup(int32_t file_num)
Sanity check local backup file.