0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
CellStoreTrailerV7.cc
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.
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 #include <Common/Compat.h>
28 #include "CellStoreTrailerV7.h"
29 
30 #include <Hypertable/Lib/KeySpec.h>
31 #include <Hypertable/Lib/Schema.h>
32 
33 #include <Common/Checksum.h>
34 #include <Common/Filesystem.h>
35 #include <Common/Serialization.h>
36 #include <Common/Logger.h>
37 
38 #include <cassert>
39 #include <iostream>
40 
41 using namespace std;
42 using namespace Hypertable;
43 using namespace Serialization;
44 
45 
49 CellStoreTrailerV7::CellStoreTrailerV7() {
50  assert(sizeof(float) == 4);
51  clear();
52 }
53 
54 
57 void CellStoreTrailerV7::clear() {
58  trailer_checksum = 0;
59  fix_index_offset = 0;
60  var_index_offset = 0;
61  filter_offset = 0;
62  replaced_files_offset = 0;
63  index_entries = 0;
64  total_entries = 0;
65  filter_length = 0;
66  filter_items_estimate = 0;
67  filter_items_actual = 0;
68  replaced_files_length = 0;
69  replaced_files_entries = 0;
70  blocksize = 0;
71  revision = TIMESTAMP_MIN;
72  timestamp_min = TIMESTAMP_MAX;
73  timestamp_max = TIMESTAMP_MIN;
74  expiration_time = TIMESTAMP_NULL;
75  create_time = 0;
76  expirable_data = 0;
77  delete_count = 0;
78  key_bytes = 0;
79  value_bytes = 0;
80  table_id = 0xffffffff;
81  table_generation = 0;
82  flags = 0;
83  alignment = HT_DIRECT_IO_ALIGNMENT;
84  compression_ratio = 0.0;
85  compression_type = 0;
86  key_compression_scheme = 0;
87  block_header_version = 1;
88  bloom_filter_mode = BLOOM_FILTER_DISABLED;
89  bloom_filter_hash_count = 0;
90  version = 7;
91 }
92 
93 
94 
97 void CellStoreTrailerV7::serialize(uint8_t *buf) {
98  uint8_t *base = buf;
99  encode_i32(&buf, trailer_checksum);
100  encode_i64(&buf, fix_index_offset);
101  encode_i64(&buf, var_index_offset);
102  encode_i64(&buf, filter_offset);
103  encode_i64(&buf, replaced_files_offset);
104  encode_i64(&buf, index_entries);
105  encode_i64(&buf, total_entries);
106  encode_i64(&buf, filter_length);
107  encode_i64(&buf, filter_items_estimate);
108  encode_i64(&buf, filter_items_actual);
109  encode_i64(&buf, replaced_files_length);
110  encode_i32(&buf, replaced_files_entries);
111  encode_i64(&buf, blocksize);
112  encode_i64(&buf, revision);
113  encode_i64(&buf, timestamp_min);
114  encode_i64(&buf, timestamp_max);
115  encode_i64(&buf, expiration_time);
116  encode_i64(&buf, create_time);
117  encode_i64(&buf, expirable_data);
118  encode_i64(&buf, delete_count);
119  encode_i64(&buf, key_bytes);
120  encode_i64(&buf, value_bytes);
121  encode_i32(&buf, table_id);
122  encode_i32(&buf, table_generation);
123  encode_i32(&buf, flags);
124  encode_i32(&buf, alignment);
125  encode_i32(&buf, compression_ratio_i32);
126  encode_i16(&buf, compression_type);
127  encode_i16(&buf, key_compression_scheme);
128  encode_i16(&buf, block_header_version);
129  encode_i8(&buf, bloom_filter_mode);
130  encode_i8(&buf, bloom_filter_hash_count);
131  encode_i16(&buf, version);
132  // compute trailer checksum
133  trailer_checksum = (int32_t)fletcher32(base+4, buf-(base+4));
134  encode_i32(&base, trailer_checksum);
135  base -= 4;
136 
137  assert(version == 7);
138  assert((buf-base) == (int)CellStoreTrailerV7::size());
139  (void)base;
140 }
141 
142 
143 
146 void CellStoreTrailerV7::deserialize(const uint8_t *buf) {
147  const uint8_t *base = buf+4;
148  HT_TRY("deserializing cellstore trailer",
149  size_t remaining = CellStoreTrailerV7::size();
150  trailer_checksum = decode_i32(&buf, &remaining);
151  fix_index_offset = decode_i64(&buf, &remaining);
152  var_index_offset = decode_i64(&buf, &remaining);
153  filter_offset = decode_i64(&buf, &remaining);
154  replaced_files_offset = decode_i64(&buf, &remaining);
155  index_entries = decode_i64(&buf, &remaining);
156  total_entries = decode_i64(&buf, &remaining);
157  filter_length = decode_i64(&buf, &remaining);
158  filter_items_estimate = decode_i64(&buf, &remaining);
159  filter_items_actual = decode_i64(&buf, &remaining);
160  replaced_files_length = decode_i64(&buf, &remaining);
161  replaced_files_entries = decode_i32(&buf, &remaining);
162  blocksize = decode_i64(&buf, &remaining);
163  revision = decode_i64(&buf, &remaining);
164  timestamp_min = decode_i64(&buf, &remaining);
165  timestamp_max = decode_i64(&buf, &remaining);
166  expiration_time = decode_i64(&buf, &remaining);
167  create_time = decode_i64(&buf, &remaining);
168  expirable_data = decode_i64(&buf, &remaining);
169  delete_count = decode_i64(&buf, &remaining);
170  key_bytes = decode_i64(&buf, &remaining);
171  value_bytes = decode_i64(&buf, &remaining);
172  table_id = decode_i32(&buf, &remaining);
173  table_generation = decode_i32(&buf, &remaining);
174  flags = decode_i32(&buf, &remaining);
175  alignment = decode_i32(&buf, &remaining);
176  compression_ratio_i32 = decode_i32(&buf, &remaining);
177  compression_type = decode_i16(&buf, &remaining);
178  key_compression_scheme = decode_i16(&buf, &remaining);
179  block_header_version = decode_i16(&buf, &remaining);
180  bloom_filter_mode = decode_i8(&buf, &remaining);
181  bloom_filter_hash_count = decode_i8(&buf, &remaining);
182  version = decode_i16(&buf, &remaining));
183  int32_t checksum = (int32_t)fletcher32(base, buf-base);
184  if (checksum != trailer_checksum)
185  HT_THROWF(Error::CHECKSUM_MISMATCH, "CellStore trailer checksum = %x (computed = %x",
186  (int)trailer_checksum, (int)checksum);
187 }
188 
189 
190 
193 void CellStoreTrailerV7::display(std::ostream &os) {
194  os << "{CellStoreTrailerV7: ";
195  os << "trailer_checksum=" << std::hex << trailer_checksum << std::dec;
196  os << ", fix_index_offset=" << fix_index_offset;
197  os << ", var_index_offset=" << var_index_offset;
198  os << ", filter_offset=" << filter_offset;
199  os << ", replaced_files_offset=" << replaced_files_offset;
200  os << ", index_entries=" << index_entries;
201  os << ", total_entries=" << total_entries;
202  os << ", filter_length = " << filter_length;
203  os << ", filter_items_estimate = " << filter_items_estimate;
204  os << ", filter_items_actual = " << filter_items_actual;
205  os << ", replaced_files_length=" << replaced_files_length;
206  os << ", replaced_files_entries=" << replaced_files_entries;
207  os << ", blocksize=" << blocksize;
208  os << ", revision=" << revision;
209  os << ", timestamp_min=" << timestamp_min;
210  os << ", timestamp_max=" << timestamp_max;
211  os << ", expiration_time=" << expiration_time;
212  os << ", create_time=" << create_time;
213  os << ", expirable_data=" << expirable_data;
214  os << ", delete_count=" << delete_count;
215  os << ", key_bytes=" << key_bytes;
216  os << ", value_bytes=" << value_bytes;
217  os << ", table_id=" << table_id;
218  os << ", table_generation=" << table_generation;
219  os << ", flags=" << flags << " (";
220  if (flags & INDEX_64BIT)
221  os << " 64BIT_INDEX";
222  if (flags & MAJOR_COMPACTION)
223  os << " MAJOR_COMPACTION";
224  os << " )";
225  os << ", alignment=" << alignment;
226  os << ", compression_ratio=" << compression_ratio;
227  os << ", compression_type=" << compression_type;
228  os << ", key_compression_scheme=" << key_compression_scheme;
229  os << ", block_header_version=" << block_header_version;
230  if (bloom_filter_mode == BLOOM_FILTER_DISABLED)
231  os << ", bloom_filter_mode=DISABLED";
232  else if (bloom_filter_mode == BLOOM_FILTER_ROWS)
233  os << ", bloom_filter_mode=ROWS";
234  else if (bloom_filter_mode == BLOOM_FILTER_ROWS_COLS)
235  os << ", bloom_filter_mode=ROWS_COLS";
236  else
237  os << ", bloom_filter_mode=?(" << bloom_filter_mode << ")";
238  os << ", bloom_filter_hash_count=" << bloom_filter_hash_count;
239  os << ", version=" << version << "}";
240 }
241 
244 void CellStoreTrailerV7::display_multiline(std::ostream &os) {
245  os << "[CellStoreTrailerV7]\n";
246  os << " trailer_checksum: " << std::hex << trailer_checksum << std::dec << "\n";
247  os << " fix_index_offset: " << fix_index_offset << "\n";
248  os << " var_index_offset: " << var_index_offset << "\n";
249  os << " filter_offset: " << filter_offset << "\n";
250  os << " replaced_files_offset: " << replaced_files_offset << "\n";
251  os << " index_entries: " << index_entries << "\n";
252  os << " total_entries: " << total_entries << "\n";
253  os << " filter_length: " << filter_length << "\n";
254  os << " filter_items_estimate: " << filter_items_estimate << "\n";
255  os << " filter_items_actual: " << filter_items_actual << "\n";
256  os << " replaced_files_length: " << replaced_files_length << "\n";
257  os << " replaced_files_entries: " << replaced_files_entries << "\n";
258  os << " blocksize: " << blocksize << "\n";
259  os << " revision: " << revision << "\n";
260  os << " timestamp_min: " << timestamp_min << "\n";
261  os << " timestamp_max: " << timestamp_max << "\n";
262  os << " expiration_time: " << expiration_time << "\n";
263  os << " create_time: " << create_time << "\n";
264  os << " expirable_data: " << expirable_data << "\n";
265  os << " delete_count: " << delete_count << "\n";
266  os << " key_bytes: " << key_bytes << "\n";
267  os << " value_bytes: " << value_bytes << "\n";
268  os << " table_id: " << table_id << "\n";
269  os << " table_generation: " << table_generation << "\n";
270  if (flags & INDEX_64BIT)
271  os << " flags: 64BIT_INDEX\n";
272  else
273  os << " flags=" << flags << "\n";
274  os << " alignment=" << alignment << "\n";
275  os << " compression_ratio: " << compression_ratio << "\n";
276  os << " compression_type: " << compression_type << "\n";
277  os << " key_compression_scheme: " << key_compression_scheme << "\n";
278  os << " block_header_version: " << block_header_version << "\n";
279  if (bloom_filter_mode == BLOOM_FILTER_DISABLED)
280  os << " bloom_filter_mode=DISABLED\n";
281  else if (bloom_filter_mode == BLOOM_FILTER_ROWS)
282  os << " bloom_filter_mode=ROWS\n";
283  else if (bloom_filter_mode == BLOOM_FILTER_ROWS_COLS)
284  os << " bloom_filter_mode=ROWS_COLS\n";
285  else
286  os << " bloom_filter_mode=?(" << bloom_filter_mode << ")\n";
287  os << " bloom_filter_hash_count=" << (int)bloom_filter_hash_count << "\n";
288  os << " version: " << version << std::endl;
289 }
290 
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
Declarations for CellStoreTrailerV7.
#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