0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
CommitLogBlockStream.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 
26 
27 #ifndef Hypertable_Lib_CommitLogBlockStream_h
28 #define Hypertable_Lib_CommitLogBlockStream_h
29 
31 
32 #include <Common/DynamicBuffer.h>
33 #include <Common/String.h>
34 #include <Common/Filesystem.h>
35 #include <Common/Status.h>
36 
37 namespace Hypertable {
38 
41 
45  const char *log_dir;
47  const char *file_fragment;
49  uint8_t *block_ptr;
51  size_t block_len;
53  uint64_t start_offset;
55  uint64_t end_offset;
57  int error;
58  };
59 
60 
63 
64  public:
65 
67  CommitLogBlockStream(FilesystemPtr &fs, const std::string &log_dir,
68  const std::string &fragment);
69  virtual ~CommitLogBlockStream();
70 
71  void load(const std::string &log_dir, const std::string &fragment);
72  void close();
74 
75  std::string &get_fname() { return m_fname; }
76 
77  static bool ms_assert_on_error;
78 
97  static bool read_header(FilesystemPtr &fs, int32_t fd,
98  uint32_t *versionp, uint64_t *next_offset);
99 
116  static void write_header(FilesystemPtr &fs, int32_t fd);
117 
121  static uint64_t header_size();
122 
123  private:
124 
126 
127  bool archive_bad_fragment(const std::string &fname,
128  std::string &archive_fname);
129 
132 
134  std::string m_log_dir;
135 
137  std::string m_fragment;
138 
140  std::string m_fname;
141 
143  uint32_t m_version;
144 
146  int32_t m_fd;
147 
149  uint64_t m_cur_offset;
150 
152  uint64_t m_file_length;
153 
156  };
157 
159 }
160 
161 #endif // Hypertable_Lib_CommitLogBlockStream_h
Holds information about an individual block.
Abstract base class for a filesystem.
std::string m_fname
Full pathname of commit log fragment file.
Declarations for Status.
std::string m_fragment
Fragment file name within commit log directory.
static void write_header(FilesystemPtr &fs, int32_t fd)
Writes commit log file header.
Abstraction for reading a stream of blocks from a commit log file.
A dynamic, resizable and reference counted memory buffer.
Definition: DynamicBuffer.h:42
uint64_t m_cur_offset
Current read offset within the fragment file.
int load_next_valid_header(BlockHeaderCommitLog *header)
A dynamic, resizable memory buffer.
FilesystemPtr m_fs
Pointer to filesystem.
int error
Error (if any) encountered while reading block
Declarations for BlockHeaderCommitLog.
uint8_t * block_ptr
Pointer to beginning of compressed block.
bool archive_bad_fragment(const std::string &fname, std::string &archive_fname)
Hypertable definitions
static bool read_header(FilesystemPtr &fs, int32_t fd, uint32_t *versionp, uint64_t *next_offset)
Reads commit log file header.
std::shared_ptr< Filesystem > FilesystemPtr
Smart pointer to Filesystem.
Definition: Filesystem.h:572
static uint64_t header_size()
Size of header.
uint64_t m_file_length
Length of commit log fragment file.
const char * log_dir
Log directory.
A String class based on std::string.
uint64_t start_offset
Starting offset of block within fragment file.
uint64_t end_offset
Ending offset of block within fragment file.
size_t block_len
Length of block.
bool next(CommitLogBlockInfo *, BlockHeaderCommitLog *)
void load(const std::string &log_dir, const std::string &fragment)
DynamicBuffer m_block_buffer
Buffer holding most recently loaded block.
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.