43 #include <boost/algorithm/string.hpp>
44 #include <boost/shared_ptr.hpp>
53 m_fs(fs), m_definition(definition), m_flags(flags), m_version(0) {
58 const string &path,
int flags) :
59 m_fs(fs), m_definition(definition), m_flags(flags), m_version(0) {
63 boost::trim_right_if(
m_path, boost::is_any_of(
"/"));
74 std::map<EntityHeader, EntityPtr>::iterator iter;
76 entities.push_back(iter->second);
101 const uint32_t READAHEAD_BUFSZ = 1024 * 1024;
102 const uint32_t OUTSTANDING_READS = 1;
108 HT_ERRORF(
"Problem closing MetaLog: %s - %s",
116 string fname =
m_path +
"/" + file_num;
122 size_t file_length =
m_fs->length(fname);
125 if (backup_file_length < file_length)
127 "MetaLog file '%s' has length %lld backup file '%s' length is %lld",
128 fname.c_str(), (
Lld)file_length, backup_filename.c_str(),
129 (
Lld)backup_file_length);
134 int64_t file_length =
m_fs->length(fname);
135 int fd =
m_fs->open_buffered(fname, 0, READAHEAD_BUFSZ, OUTSTANDING_READS);
136 bool found_recover_entry =
false;
137 int64_t cur_offset = 0;
154 while (cur_offset < file_length) {
164 const uint8_t *ptr = buf.
base;
165 header.
decode(&ptr, &remaining);
170 found_recover_entry =
true;
174 std::map<EntityHeader, EntityPtr>::iterator iter =
m_entity_map.find(header);
187 if (nread != (
size_t)header.
length)
193 remaining = header.
length;
195 entity->decode(&ptr, &remaining,
m_version);
199 if (header.
checksum != computed_checksum)
201 "MetaLog entry checksum mismatch header=%d, computed=%d",
202 header.
checksum, computed_checksum);
213 HT_THROW2F(e.
code(), e,
"Error reading metalog file: %s: read %llu/%llu",
214 fname.c_str(), (
Llu)cur_offset, (
Llu)file_length);
217 if (!found_recover_entry)
226 const uint8_t *ptr = buf;
233 "Short read of %s header (expected %d, got %d)",
238 header.
decode(&ptr, &remaining);
248 "Unsuported %s version %d (definition version is %d)",
#define HT_THROW2F(_code_, _ex_, _fmt_,...)
The FailureInducer simulates errors.
PropertiesPtr properties
This singleton map stores all options.
std::string String
A String is simply a typedef to std::string.
Compatibility class for boost::filesystem::path.
std::shared_ptr< Entity > EntityPtr
Smart pointer to Entity.
long long unsigned int Llu
Shortcut for printf formats.
static bool exists(const String &fname)
Checks if a file or directory exists.
#define HT_ON_SCOPE_EXIT(...)
A dynamic, resizable and reference counted memory buffer.
static uint64_t size(const String &fname)
Returns the size of a file (0 on error)
uint32_t fletcher32(const void *data8, size_t len8)
Compute fletcher32 checksum for arbitary data.
Compatibility class for boost::filesystem::path.
File system utility functions.
Static length of entity header.
const char * get_text(int error)
Returns a descriptive error message.
Compatibility Macros for C/C++.
Functions to serialize/deserialize primitives to/from a memory buffer.
long long int Lld
Shortcut for printf formats.
Implementation of checksum routines.
void clear()
Clears the buffer.
#define HT_THROW2_(_code_, _ex_)
std::shared_ptr< Filesystem > FilesystemPtr
Smart pointer to Filesystem.
#define HT_THROWF(_code_, _fmt_,...)
uint8_t * base
Pointer to the allocated memory buffer.
This is a generic exception class for Hypertable.
#define HT_ERRORF(msg,...)
#define HT_MAYBE_FAIL(_label_)
String extensions and helpers: sets, maps, append operators etc.
Error codes, Exception handling, error logging.
#define HT_THROW(_code_, _msg_)
void ensure(size_t len)
Ensure space for additional data Will grow the space to 1.5 of the needed space with existing data un...
std::shared_ptr< Definition > DefinitionPtr
Smart pointer to Definition.
int code() const
Returns the error code.
void reserve(size_t len, bool nocopy=false)
Reserve space for additional data Will grow the space to exactly what's needed.
Executes user-defined functions when leaving the current scope.