48 const uint32_t READAHEAD_BUFFER_SIZE = 131072;
49 const uint32_t LatestVersion = 1;
50 const uint32_t BlockHeaderVersions[LatestVersion+1] = { 0, 1 };
57 : m_fs(fs), m_fd(-1), m_cur_offset(0), m_file_length(0) {
62 const string &log_dir,
const string &fragment)
63 : m_fs(fs), m_fd(-1), m_cur_offset(0), m_file_length(0) {
64 load(log_dir, fragment);
77 m_fname = log_dir +
"/" + fragment;
81 READAHEAD_BUFFER_SIZE, 2);
87 READAHEAD_BUFFER_SIZE, 2);
92 "Unsupported commit log file version %u", (
unsigned)
m_version);
105 HT_ERRORF(
"Problem closing file %s - %s (%s)",
137 HT_WARNF(
"Commit log fragment '%s' truncated (block offset %llu)",
141 string archive_fname;
146 {
format(
"File archived to %s",archive_fname.c_str())});
155 HT_WARNF(
"Commit log fragment '%s' truncated (entry start position %llu)",
159 string archive_fname;
164 {
format(
"File archived to %s",archive_fname.c_str())});
178 const size_t HEADER_SIZE=8;
184 uint32_t *versionp, uint64_t *next_offset) {
185 char buf[HEADER_SIZE];
187 if (fs->read(fd, buf, HEADER_SIZE) != HEADER_SIZE) {
193 if (buf[0] !=
'C' || buf[1] !=
'L' || buf[6] !=
'\f' || buf[7] !=
'\n' ||
194 !isdigit(buf[2]) || !isdigit(buf[3]) || !isdigit(buf[4]) ||
201 *versionp = (uint32_t)atoi((
const char *)&buf[2]);
202 *next_offset = HEADER_SIZE;
210 string header_str =
format(
"CL%04u\f\n", (
unsigned)LatestVersion);
212 HT_ASSERT(header_str.size() == HEADER_SIZE);
213 memcpy(buf.
base, header_str.c_str(), HEADER_SIZE);
248 string archive_fname;
252 text =
format(
"Corruption detected in commit log file %s at offset %lld",
255 text =
format(
"Truncated block header in commit log file %s",
261 format(
"File archived to %s", archive_fname.c_str()) });
271 string &archive_fname) {
273 if (archive_directory.front() !=
'/')
274 archive_directory =
string(
"/") + archive_directory;
275 if (archive_directory.back() !=
'/')
276 archive_directory.append(
"/");
277 archive_directory.append(
"backup");
278 archive_fname = archive_directory + fname;
279 archive_directory.append(
Path(fname).parent_path().
string());
283 m_fs->mkdirs(archive_directory);
286 HT_ERRORF(
"Problem creating backup directory %s - %s (%s)",
293 if (
m_fs->exists(archive_fname))
294 m_fs->remove(archive_fname);
297 HT_ERRORF(
"Problem checking existence of backup file %s - %s (%s)",
310 HT_ERRORF(
"Problem copying file %s to %s - %s (%s)",
311 fname.c_str(), archive_fname.c_str(),
A memory buffer of static size.
#define HT_WARNF(msg,...)
static bool ms_assert_on_error
Holds information about an individual block.
Holds Nagios-style program status information.
PropertiesPtr properties
This singleton map stores all options.
std::string m_fname
Full pathname of commit log fragment file.
Compatibility class for boost::filesystem::path.
String format(const char *fmt,...)
Returns a String using printf like format facilities Vanilla snprintf is about 1.5x faster than this...
std::string m_fragment
Fragment file name within commit log directory.
CommitLogBlockStream(FilesystemPtr &fs)
long long unsigned int Llu
Shortcut for printf formats.
static void write_header(FilesystemPtr &fs, int32_t fd)
Writes commit log file header.
void copy(ClientPtr &client, const std::string &from, const std::string &to, int64_t offset=0)
uint8_t * ptr
Pointer to the end of the used part of the buffer.
virtual ~CommitLogBlockStream()
uint64_t m_cur_offset
Current read offset within the fragment file.
Declarations for CommitLogBlockStream.
int load_next_valid_header(BlockHeaderCommitLog *header)
Compatibility class for boost::filesystem::path.
FilesystemPtr m_fs
Pointer to filesystem.
const char * get_text(int error)
Returns a descriptive error message.
bool status(ContextPtr &context, Timer &timer, Status &status)
Runs a status check on the master.
void grow(size_t new_size, bool nocopy=false)
Grows the buffer and copies the data unless nocopy is true.
std::shared_ptr< Client > ClientPtr
Smart pointer to Client.
int error
Error (if any) encountered while reading block
Logging routines and macros.
Compatibility Macros for C/C++.
uint8_t * block_ptr
Pointer to beginning of compressed block.
bool archive_bad_fragment(const std::string &fname, std::string &archive_fname)
long long int Lld
Shortcut for printf formats.
static void set(const Status &status, std::vector< std::string > additional_lines)
Sets persistent status.
Implementation of checksum routines.
static bool read_header(FilesystemPtr &fs, int32_t fd, uint32_t *versionp, uint64_t *next_offset)
Reads commit log file header.
int32_t m_fd
File descriptor.
std::shared_ptr< Filesystem > FilesystemPtr
Smart pointer to Filesystem.
#define HT_THROWF(_code_, _fmt_,...)
uint8_t * base
Pointer to the allocated memory buffer.
static uint64_t header_size()
Size of header.
size_t fill() const
Returns the size of the used portion.
uint64_t m_file_length
Length of commit log fragment file.
const char * log_dir
Log directory.
This is a generic exception class for Hypertable.
Proxy class for FS broker.
Declarations for StatusPersister.
uint64_t start_offset
Starting offset of block within fragment file.
#define HT_ERRORF(msg,...)
uint64_t end_offset
Ending offset of block within fragment file.
size_t block_len
Length of block.
bool next(CommitLogBlockInfo *, BlockHeaderCommitLog *)
Declarations of utility functions.
void load(const std::string &log_dir, const std::string &fragment)
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...
DynamicBuffer m_block_buffer
Buffer holding most recently loaded block.
int code() const
Returns the error code.
uint32_t m_version
Version of commit log fragment file format.
const char * file_fragment
File name of log fragment within log_dir.
std::string m_log_dir
Directory containing commit log fragment file.