0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
CellStoreTrailerV6.cc
Go to the documentation of this file.
1 
22 #include "Common/Compat.h"
23 #include <cassert>
24 #include <iostream>
25 
26 #include "Common/Checksum.h"
27 #include "Common/Filesystem.h"
28 #include "Common/Serialization.h"
29 #include "Common/Logger.h"
30 
31 #include "Hypertable/Lib/KeySpec.h"
32 #include "Hypertable/Lib/Schema.h"
33 
34 #include "CellStoreTrailerV6.h"
35 
36 using namespace std;
37 using namespace Hypertable;
38 using namespace Serialization;
39 
40 
44 CellStoreTrailerV6::CellStoreTrailerV6() {
45  assert(sizeof(float) == 4);
46  clear();
47 }
48 
49 
52 void CellStoreTrailerV6::clear() {
53  trailer_checksum = 0;
54  fix_index_offset = 0;
55  var_index_offset = 0;
56  filter_offset = 0;
57  replaced_files_offset = 0;
58  index_entries = 0;
59  total_entries = 0;
60  filter_length = 0;
61  filter_items_estimate = 0;
62  filter_items_actual = 0;
63  replaced_files_length = 0;
64  replaced_files_entries = 0;
65  blocksize = 0;
66  revision = TIMESTAMP_MIN;
67  timestamp_min = TIMESTAMP_MAX;
68  timestamp_max = TIMESTAMP_MIN;
69  expiration_time = TIMESTAMP_NULL;
70  create_time = 0;
71  expirable_data = 0;
72  delete_count = 0;
73  key_bytes = 0;
74  value_bytes = 0;
75  table_id = 0xffffffff;
76  table_generation = 0;
77  flags = 0;
78  alignment = HT_DIRECT_IO_ALIGNMENT;
79  compression_ratio = 0.0;
80  compression_type = 0;
81  key_compression_scheme = 0;
82  bloom_filter_mode = BLOOM_FILTER_DISABLED;
83  bloom_filter_hash_count = 0;
84  version = 6;
85 }
86 
87 
88 
91 void CellStoreTrailerV6::serialize(uint8_t *buf) {
92  uint8_t *base = buf;
93  encode_i32(&buf, trailer_checksum);
94  encode_i64(&buf, fix_index_offset);
95  encode_i64(&buf, var_index_offset);
96  encode_i64(&buf, filter_offset);
97  encode_i64(&buf, replaced_files_offset);
98  encode_i64(&buf, index_entries);
99  encode_i64(&buf, total_entries);
100  encode_i64(&buf, filter_length);
101  encode_i64(&buf, filter_items_estimate);
102  encode_i64(&buf, filter_items_actual);
103  encode_i64(&buf, replaced_files_length);
104  encode_i32(&buf, replaced_files_entries);
105  encode_i64(&buf, blocksize);
106  encode_i64(&buf, revision);
107  encode_i64(&buf, timestamp_min);
108  encode_i64(&buf, timestamp_max);
109  encode_i64(&buf, expiration_time);
110  encode_i64(&buf, create_time);
111  encode_i64(&buf, expirable_data);
112  encode_i64(&buf, delete_count);
113  encode_i64(&buf, key_bytes);
114  encode_i64(&buf, value_bytes);
115  encode_i32(&buf, table_id);
116  encode_i32(&buf, table_generation);
117  encode_i32(&buf, flags);
118  encode_i32(&buf, alignment);
119  encode_i32(&buf, compression_ratio_i32);
120  encode_i16(&buf, compression_type);
121  encode_i16(&buf, key_compression_scheme);
122  encode_i8(&buf, bloom_filter_mode);
123  encode_i8(&buf, bloom_filter_hash_count);
124  encode_i16(&buf, version);
125  // compute trailer checksum
126  trailer_checksum = (int32_t)fletcher32(base+4, buf-(base+4));
127  encode_i32(&base, trailer_checksum);
128  base -= 4;
129 
130  assert(version == 6);
131  assert((buf-base) == (int)CellStoreTrailerV6::size());
132  (void)base;
133 }
134 
135 
136 
139 void CellStoreTrailerV6::deserialize(const uint8_t *buf) {
140  const uint8_t *base = buf+4;
141  HT_TRY("deserializing cellstore trailer",
142  size_t remaining = CellStoreTrailerV6::size();
143  trailer_checksum = decode_i32(&buf, &remaining);
144  fix_index_offset = decode_i64(&buf, &remaining);
145  var_index_offset = decode_i64(&buf, &remaining);
146  filter_offset = decode_i64(&buf, &remaining);
147  replaced_files_offset = decode_i64(&buf, &remaining);
148  index_entries = decode_i64(&buf, &remaining);
149  total_entries = decode_i64(&buf, &remaining);
150  filter_length = decode_i64(&buf, &remaining);
151  filter_items_estimate = decode_i64(&buf, &remaining);
152  filter_items_actual = decode_i64(&buf, &remaining);
153  replaced_files_length = decode_i64(&buf, &remaining);
154  replaced_files_entries = decode_i32(&buf, &remaining);
155  blocksize = decode_i64(&buf, &remaining);
156  revision = decode_i64(&buf, &remaining);
157  timestamp_min = decode_i64(&buf, &remaining);
158  timestamp_max = decode_i64(&buf, &remaining);
159  expiration_time = decode_i64(&buf, &remaining);
160  create_time = decode_i64(&buf, &remaining);
161  expirable_data = decode_i64(&buf, &remaining);
162  delete_count = decode_i64(&buf, &remaining);
163  key_bytes = decode_i64(&buf, &remaining);
164  value_bytes = decode_i64(&buf, &remaining);
165  table_id = decode_i32(&buf, &remaining);
166  table_generation = decode_i32(&buf, &remaining);
167  flags = decode_i32(&buf, &remaining);
168  alignment = decode_i32(&buf, &remaining);
169  compression_ratio_i32 = decode_i32(&buf, &remaining);
170  compression_type = decode_i16(&buf, &remaining);
171  key_compression_scheme = decode_i16(&buf, &remaining);
172  bloom_filter_mode = decode_i8(&buf, &remaining);
173  bloom_filter_hash_count = decode_i8(&buf, &remaining);
174  version = decode_i16(&buf, &remaining));
175  int32_t checksum = (int32_t)fletcher32(base, buf-base);
176  if (checksum != trailer_checksum)
177  HT_THROWF(Error::CHECKSUM_MISMATCH, "CellStore trailer checksum = %x (computed = %x",
178  (int)trailer_checksum, (int)checksum);
179 }
180 
181 
182 
185 void CellStoreTrailerV6::display(std::ostream &os) {
186  os << "{CellStoreTrailerV6: ";
187  os << "trailer_checksum=" << std::hex << trailer_checksum << std::dec;
188  os << ", fix_index_offset=" << fix_index_offset;
189  os << ", var_index_offset=" << var_index_offset;
190  os << ", filter_offset=" << filter_offset;
191  os << ", replaced_files_offset=" << replaced_files_offset;
192  os << ", index_entries=" << index_entries;
193  os << ", total_entries=" << total_entries;
194  os << ", filter_length = " << filter_length;
195  os << ", filter_items_estimate = " << filter_items_estimate;
196  os << ", filter_items_actual = " << filter_items_actual;
197  os << ", replaced_files_length=" << replaced_files_length;
198  os << ", replaced_files_entries=" << replaced_files_entries;
199  os << ", blocksize=" << blocksize;
200  os << ", revision=" << revision;
201  os << ", timestamp_min=" << timestamp_min;
202  os << ", timestamp_max=" << timestamp_max;
203  os << ", expiration_time=" << expiration_time;
204  os << ", create_time=" << create_time;
205  os << ", expirable_data=" << expirable_data;
206  os << ", delete_count=" << delete_count;
207  os << ", key_bytes=" << key_bytes;
208  os << ", value_bytes=" << value_bytes;
209  os << ", table_id=" << table_id;
210  os << ", table_generation=" << table_generation;
211  os << ", flags=" << flags << " (";
212  if (flags & INDEX_64BIT)
213  os << " 64BIT_INDEX";
214  if (flags & MAJOR_COMPACTION)
215  os << " MAJOR_COMPACTION";
216  os << " )";
217  os << ", alignment=" << alignment;
218  os << ", compression_ratio=" << compression_ratio;
219  os << ", compression_type=" << compression_type;
220  os << ", key_compression_scheme=" << key_compression_scheme;
221  if (bloom_filter_mode == BLOOM_FILTER_DISABLED)
222  os << ", bloom_filter_mode=DISABLED";
223  else if (bloom_filter_mode == BLOOM_FILTER_ROWS)
224  os << ", bloom_filter_mode=ROWS";
225  else if (bloom_filter_mode == BLOOM_FILTER_ROWS_COLS)
226  os << ", bloom_filter_mode=ROWS_COLS";
227  else
228  os << ", bloom_filter_mode=?(" << bloom_filter_mode << ")";
229  os << ", bloom_filter_hash_count=" << bloom_filter_hash_count;
230  os << ", version=" << version << "}";
231 }
232 
235 void CellStoreTrailerV6::display_multiline(std::ostream &os) {
236  os << "[CellStoreTrailerV6]\n";
237  os << " trailer_checksum: " << std::hex << trailer_checksum << std::dec << "\n";
238  os << " fix_index_offset: " << fix_index_offset << "\n";
239  os << " var_index_offset: " << var_index_offset << "\n";
240  os << " filter_offset: " << filter_offset << "\n";
241  os << " replaced_files_offset: " << replaced_files_offset << "\n";
242  os << " index_entries: " << index_entries << "\n";
243  os << " total_entries: " << total_entries << "\n";
244  os << " filter_length: " << filter_length << "\n";
245  os << " filter_items_estimate: " << filter_items_estimate << "\n";
246  os << " filter_items_actual: " << filter_items_actual << "\n";
247  os << " replaced_files_length: " << replaced_files_length << "\n";
248  os << " replaced_files_entries: " << replaced_files_entries << "\n";
249  os << " blocksize: " << blocksize << "\n";
250  os << " revision: " << revision << "\n";
251  os << " timestamp_min: " << timestamp_min << "\n";
252  os << " timestamp_max: " << timestamp_max << "\n";
253  os << " expiration_time: " << expiration_time << "\n";
254  os << " create_time: " << create_time << "\n";
255  os << " expirable_data: " << expirable_data << "\n";
256  os << " delete_count: " << delete_count << "\n";
257  os << " key_bytes: " << key_bytes << "\n";
258  os << " value_bytes: " << value_bytes << "\n";
259  os << " table_id: " << table_id << "\n";
260  os << " table_generation: " << table_generation << "\n";
261  if (flags & INDEX_64BIT)
262  os << " flags: 64BIT_INDEX\n";
263  else
264  os << " flags=" << flags << "\n";
265  os << " alignment=" << alignment << "\n";
266  os << " compression_ratio: " << compression_ratio << "\n";
267  os << " compression_type: " << compression_type << "\n";
268  os << " key_compression_scheme: " << key_compression_scheme << "\n";
269  if (bloom_filter_mode == BLOOM_FILTER_DISABLED)
270  os << " bloom_filter_mode=DISABLED\n";
271  else if (bloom_filter_mode == BLOOM_FILTER_ROWS)
272  os << " bloom_filter_mode=ROWS\n";
273  else if (bloom_filter_mode == BLOOM_FILTER_ROWS_COLS)
274  os << " bloom_filter_mode=ROWS_COLS\n";
275  else
276  os << " bloom_filter_mode=?(" << bloom_filter_mode << ")\n";
277  os << " bloom_filter_hash_count=" << (int)bloom_filter_hash_count << "\n";
278  os << " version: " << version << std::endl;
279 }
280 
Abstract base class for a filesystem.
STL namespace.
Declarations for Schema.
uint32_t decode_i32(const uint8_t **bufp, size_t *remainp)
Decode a 32-bit integer in little-endian order.
static const int64_t TIMESTAMP_MIN
Definition: KeySpec.h:34
uint32_t fletcher32(const void *data8, size_t len8)
Compute fletcher32 checksum for arbitary data.
Definition: Checksum.cc:42
uint8_t decode_i8(const uint8_t **bufp, size_t *remainp)
Decode a 8-bit integer (a byte/character)
Definition: Serialization.h:60
uint64_t decode_i64(const uint8_t **bufp, size_t *remainp)
Decode a 64-bit integer in little-endian order.
uint16_t decode_i16(const uint8_t **bufp, size_t *remainp)
Decode a 16-bit integer in little-endian order.
Logging routines and macros.
void encode_i32(uint8_t **bufp, uint32_t val)
Encode a 32-bit integer in little-endian order.
Compatibility Macros for C/C++.
void encode_i16(uint8_t **bufp, uint16_t val)
Encode a 16-bit integer in little-endian order.
void encode_i64(uint8_t **bufp, uint64_t val)
Encode a 64-bit integer in little-endian order.
Functions to serialize/deserialize primitives to/from a memory buffer.
static const int64_t TIMESTAMP_NULL
Definition: KeySpec.h:36
Hypertable definitions
Implementation of checksum routines.
static const int64_t TIMESTAMP_MAX
Definition: KeySpec.h:35
#define HT_THROWF(_code_, _fmt_,...)
Definition: Error.h:490
#define HT_TRY(_s_, _code_)
Definition: Error.h:517
void encode_i8(uint8_t **bufp, uint8_t val)
Encodes a byte into the given buffer.
Definition: Serialization.h:49
#define HT_DIRECT_IO_ALIGNMENT
Definition: Filesystem.h:49