51 #include <boost/shared_array.hpp>
57 const char *start_row,
const char *end_row) {
58 String start = (start_row) ? start_row :
"";
71 bool second_try =
false;
82 offset = file_length - amount;
84 boost::shared_array<uint8_t> trailer_buf(
new uint8_t [amount] );
86 nread =
Global::dfs->pread(fd, trailer_buf.get(), amount, offset, second_try);
90 "Problem reading trailer for CellStore file '%s'"
91 " - only read %d of %lu bytes", name.c_str(),
92 (int)nread, (
Lu)amount);
94 const uint8_t *ptr = trailer_buf.get() + (amount-2);
100 if (version < 4 && oflags) {
108 if (amount < trailer_v7.
size())
110 "Bad length of CellStoreV7 file '%s' - %llu",
111 name.c_str(), (
Llu)file_length);
114 trailer_v7.
deserialize(trailer_buf.get() + (amount - trailer_v7.
size()));
123 HT_ERRORF(
"Problem deserializing trailer of %s", name.c_str());
127 cellstore = make_shared<CellStoreV7>(
Global::dfs.get());
128 cellstore->open(name, start, end, fd, file_length, &trailer_v7);
130 HT_ERRORF(
"Failed to open CellStore %s [%s..%s], length=%llu",
131 name.c_str(), start.c_str(), end.c_str(), (
Llu)file_length);
134 else if (version == 6) {
137 if (amount < trailer_v6.
size())
139 "Bad length of CellStoreV6 file '%s' - %llu",
140 name.c_str(), (
Llu)file_length);
143 trailer_v6.
deserialize(trailer_buf.get() + (amount - trailer_v6.
size()));
152 HT_ERRORF(
"Problem deserializing trailer of %s", name.c_str());
156 cellstore = make_shared<CellStoreV6>(
Global::dfs.get());
157 cellstore->open(name, start, end, fd, file_length, &trailer_v6);
159 HT_ERRORF(
"Failed to open CellStore %s [%s..%s], length=%llu",
160 name.c_str(), start.c_str(), end.c_str(), (
Llu)file_length);
163 else if (version == 5) {
166 if (amount < trailer_v5.
size())
168 "Bad length of CellStoreV5 file '%s' - %llu",
169 name.c_str(), (
Llu)file_length);
171 trailer_v5.
deserialize(trailer_buf.get() + (amount - trailer_v5.
size()));
173 cellstore = make_shared<CellStoreV5>(
Global::dfs.get());
174 cellstore->open(name, start, end, fd, file_length, &trailer_v5);
176 HT_ERRORF(
"Failed to open CellStore %s [%s..%s], length=%llu",
177 name.c_str(), start.c_str(), end.c_str(), (
Llu)file_length);
180 else if (version == 4) {
183 if (amount < trailer_v4.
size())
185 "Bad length of CellStoreV4 file '%s' - %llu",
186 name.c_str(), (
Llu)file_length);
188 trailer_v4.
deserialize(trailer_buf.get() + (amount - trailer_v4.
size()));
190 cellstore = make_shared<CellStoreV4>(
Global::dfs.get());
191 cellstore->open(name, start, end, fd, file_length, &trailer_v4);
193 HT_ERRORF(
"Failed to open CellStore %s [%s..%s], length=%llu",
194 name.c_str(), start.c_str(), end.c_str(), (
Llu)file_length);
197 else if (version == 3) {
200 if (amount < trailer_v3.
size())
202 "Bad length of CellStoreV3 file '%s' - %llu",
203 name.c_str(), (
Llu)file_length);
205 trailer_v3.
deserialize(trailer_buf.get() + (amount - trailer_v3.
size()));
207 cellstore = make_shared<CellStoreV3>(
Global::dfs.get());
208 cellstore->open(name, start, end, fd, file_length, &trailer_v3);
210 HT_ERRORF(
"Failed to open CellStore %s [%s..%s], length=%llu",
211 name.c_str(), start.c_str(), end.c_str(), (
Llu)file_length);
214 else if (version == 2) {
217 if (amount < trailer_v2.
size())
219 "Bad length of CellStoreV2 file '%s' - %llu",
220 name.c_str(), (
Llu)file_length);
222 trailer_v2.
deserialize(trailer_buf.get() + (amount - trailer_v2.
size()));
224 cellstore = make_shared<CellStoreV2>(
Global::dfs.get());
225 cellstore->open(name, start, end, fd, file_length, &trailer_v2);
227 HT_ERRORF(
"Failed to open CellStore %s [%s..%s], length=%llu",
228 name.c_str(), start.c_str(), end.c_str(), (
Llu)file_length);
231 else if (version == 1) {
234 if (amount < trailer_v1.
size())
236 "Bad length of CellStoreV1 file '%s' - %llu",
237 name.c_str(), (
Llu)file_length);
239 trailer_v1.
deserialize(trailer_buf.get() + (amount - trailer_v1.
size()));
241 cellstore = make_shared<CellStoreV1>(
Global::dfs.get());
242 cellstore->open(name, start, end, fd, file_length, &trailer_v1);
244 HT_ERRORF(
"Failed to open CellStore %s [%s..%s], length=%llu",
245 name.c_str(), start.c_str(), end.c_str(), (
Llu)file_length);
248 else if (version == 0) {
251 if (amount < trailer_v0.
size())
253 "Bad length of CellStoreV0 file '%s' - %llu",
254 name.c_str(), (
Llu)file_length);
256 trailer_v0.
deserialize(trailer_buf.get() + (amount - trailer_v0.
size()));
258 cellstore = make_shared<CellStoreV0>(
Global::dfs.get());
259 cellstore->open(name, start, end, fd, file_length, &trailer_v0);
261 HT_ERRORF(
"Failed to open CellStore %s [%s..%s], length=%llu",
262 name.c_str(), start.c_str(), end.c_str(), (
Llu)file_length);
273 "Unrecognized cell store version %d", (
int)version);
virtual size_t size()
Returns the serialized size of the trailer.
Declarations for CellStoreFactory.
Abstract base class for a filesystem.
Declarations for CellStoreV7.
std::string String
A String is simply a typedef to std::string.
#define HT_IO_ALIGNED(size)
virtual void deserialize(const uint8_t *buf)
Deserializes the trailer from the given buffer.
virtual void deserialize(const uint8_t *buf)
Deserializes the trailer from the given buffer.
virtual size_t size()
Returns the serialized size of the trailer.
long long unsigned int Llu
Shortcut for printf formats.
virtual size_t size()
Returns the serialized size of the trailer.
virtual size_t size()
Returns the serialized size of the trailer.
virtual void deserialize(const uint8_t *buf)
Deserializes the trailer from the given buffer.
virtual size_t size()
Returns the serialized size of the trailer.
uint16_t decode_i16(const uint8_t **bufp, size_t *remainp)
Decode a 16-bit integer in little-endian order.
virtual size_t size()
Returns the serialized size of the trailer.
Compatibility Macros for C/C++.
Functions to serialize/deserialize primitives to/from a memory buffer.
static Hypertable::FilesystemPtr dfs
virtual void deserialize(const uint8_t *buf)
Deserializes the trailer from the given buffer.
std::shared_ptr< CellStore > CellStorePtr
Smart pointer to CellStore.
virtual void deserialize(const uint8_t *buf)
Deserializes the trailer from the given buffer.
Represents the trailer for CellStore version 7.
#define HT_THROWF(_code_, _fmt_,...)
virtual size_t size()
Returns the serialized size of the trailer.
This is a generic exception class for Hypertable.
virtual void deserialize(const uint8_t *buf)
Deserializes the trailer from the given buffer.
Declarations for CellStoreTrailerV7.
long unsigned int Lu
Shortcut for printf formats.
#define HT_ERRORF(msg,...)
virtual size_t size()
Returns the serialized size of the trailer.
static CellStorePtr open(const String &name, const char *start_row, const char *end_row)
Creates a CellStore object from a given cell store file.
Declarations for CellStoreV6.
virtual void deserialize(const uint8_t *buf)
Deserializes the trailer from the given buffer.
static const char * END_ROW_MARKER
virtual void deserialize(const uint8_t *buf)
Deserializes the trailer from the given buffer.
#define HT_DIRECT_IO_ALIGNMENT
int code() const
Returns the error code.