0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
CellStoreTrailerV2.cc
Go to the documentation of this file.
1 
22 #include "Common/Compat.h"
23 #include <cassert>
24 #include <iostream>
25 
26 #include "Common/Serialization.h"
27 #include "Common/Logger.h"
28 
29 #include "Hypertable/Lib/KeySpec.h"
30 #include "Hypertable/Lib/Schema.h"
31 
32 #include "CellStoreTrailerV2.h"
33 
34 using namespace std;
35 using namespace Hypertable;
36 using namespace Serialization;
37 
38 
42 CellStoreTrailerV2::CellStoreTrailerV2() {
43  assert(sizeof(float) == 4);
44  clear();
45 }
46 
47 
50 void CellStoreTrailerV2::clear() {
51  fix_index_offset = 0;
52  var_index_offset = 0;
53  filter_offset = 0;
54  index_entries = 0;
55  total_entries = 0;
56  filter_length = 0;
57  filter_items_estimate = 0;
58  filter_items_actual = 0;
59  blocksize = 0;
60  revision = TIMESTAMP_MIN;
61  timestamp_min = TIMESTAMP_MAX;
62  timestamp_max = TIMESTAMP_MIN;
63  create_time = 0;
64  table_id = 0xffffffff;
65  table_generation = 0;
66  flags = 0;
67  compression_ratio = 0.0;
68  compression_type = 0;
69  bloom_filter_mode = BLOOM_FILTER_DISABLED;
70  bloom_filter_hash_count = 0;
71  version = 2;
72 }
73 
74 
75 
78 void CellStoreTrailerV2::serialize(uint8_t *buf) {
79  uint8_t *base = buf;
80  encode_i64(&buf, fix_index_offset);
81  encode_i64(&buf, var_index_offset);
82  encode_i64(&buf, filter_offset);
83  encode_i64(&buf, index_entries);
84  encode_i64(&buf, total_entries);
85  encode_i64(&buf, filter_length);
86  encode_i64(&buf, filter_items_estimate);
87  encode_i64(&buf, filter_items_actual);
88  encode_i64(&buf, blocksize);
89  encode_i64(&buf, revision);
90  encode_i64(&buf, timestamp_min);
91  encode_i64(&buf, timestamp_max);
92  encode_i64(&buf, create_time);
93  encode_i32(&buf, table_id);
94  encode_i32(&buf, table_generation);
95  encode_i32(&buf, flags);
96  encode_i32(&buf, compression_ratio_i32);
97  encode_i16(&buf, compression_type);
98  encode_i8(&buf, bloom_filter_mode);
99  encode_i8(&buf, bloom_filter_hash_count);
100  encode_i16(&buf, version);
101  assert(version == 2);
102  assert((buf-base) == (int)CellStoreTrailerV2::size());
103  (void)base;
104 }
105 
106 
107 
110 void CellStoreTrailerV2::deserialize(const uint8_t *buf) {
111  HT_TRY("deserializing cellstore trailer",
112  size_t remaining = CellStoreTrailerV2::size();
113  fix_index_offset = decode_i64(&buf, &remaining);
114  var_index_offset = decode_i64(&buf, &remaining);
115  filter_offset = decode_i64(&buf, &remaining);
116  index_entries = decode_i64(&buf, &remaining);
117  total_entries = decode_i64(&buf, &remaining);
118  filter_length = decode_i64(&buf, &remaining);
119  filter_items_estimate = decode_i64(&buf, &remaining);
120  filter_items_actual = decode_i64(&buf, &remaining);
121  blocksize = decode_i64(&buf, &remaining);
122  revision = decode_i64(&buf, &remaining);
123  timestamp_min = decode_i64(&buf, &remaining);
124  timestamp_max = decode_i64(&buf, &remaining);
125  create_time = decode_i64(&buf, &remaining);
126  table_id = decode_i32(&buf, &remaining);
127  table_generation = decode_i32(&buf, &remaining);
128  flags = decode_i32(&buf, &remaining);
129  compression_ratio_i32 = decode_i32(&buf, &remaining);
130  compression_type = decode_i16(&buf, &remaining);
131  bloom_filter_mode = decode_i8(&buf, &remaining);
132  bloom_filter_hash_count = decode_i8(&buf, &remaining);
133  version = decode_i16(&buf, &remaining));
134 }
135 
136 
137 
140 void CellStoreTrailerV2::display(std::ostream &os) {
141  os << "{CellStoreTrailerV2: ";
142  os << "fix_index_offset=" << fix_index_offset;
143  os << ", var_index_offset=" << var_index_offset;
144  os << ", filter_offset=" << filter_offset;
145  os << ", index_entries=" << index_entries;
146  os << ", total_entries=" << total_entries;
147  os << ", filter_length = " << filter_length;
148  os << ", filter_items_estimate = " << filter_items_estimate;
149  os << ", filter_items_actual = " << filter_items_actual;
150  os << ", blocksize=" << blocksize;
151  os << ", revision=" << revision;
152  os << ", timestamp_min=" << timestamp_min;
153  os << ", timestamp_max=" << timestamp_max;
154  os << ", create_time=" << create_time;
155  os << ", table_id=" << table_id;
156  os << ", table_generation=" << table_generation;
157  if (flags & INDEX_64BIT)
158  os << ", flags=64BIT_INDEX";
159  else
160  os << ", flags=" << flags;
161  os << ", compression_ratio=" << compression_ratio;
162  os << ", compression_type=" << compression_type;
163  if (bloom_filter_mode == BLOOM_FILTER_DISABLED)
164  os << ", bloom_filter_mode=DISABLED";
165  else if (bloom_filter_mode == BLOOM_FILTER_ROWS)
166  os << ", bloom_filter_mode=ROWS";
167  else if (bloom_filter_mode == BLOOM_FILTER_ROWS_COLS)
168  os << ", bloom_filter_mode=ROWS_COLS";
169  else
170  os << ", bloom_filter_mode=?(" << bloom_filter_mode << ")";
171  os << ", bloom_filter_hash_count=" << bloom_filter_hash_count;
172  os << ", version=" << version << "}";
173 }
174 
177 void CellStoreTrailerV2::display_multiline(std::ostream &os) {
178  os << "[CellStoreTrailerV2]\n";
179  os << " fix_index_offset: " << fix_index_offset << "\n";
180  os << " var_index_offset: " << var_index_offset << "\n";
181  os << " filter_offset: " << filter_offset << "\n";
182  os << " index_entries: " << index_entries << "\n";
183  os << " total_entries: " << total_entries << "\n";
184  os << " filter_length: " << filter_length << "\n";
185  os << " filter_items_estimate: " << filter_items_estimate << "\n";
186  os << " filter_items_actual: " << filter_items_actual << "\n";
187  os << " blocksize: " << blocksize << "\n";
188  os << " revision: " << revision << "\n";
189  os << " timestamp_min: " << timestamp_min << "\n";
190  os << " timestamp_max: " << timestamp_max << "\n";
191  os << " create_time: " << create_time << "\n";
192  os << " table_id: " << table_id << "\n";
193  os << " table_generation: " << table_generation << "\n";
194  if (flags & INDEX_64BIT)
195  os << " flags: 64BIT_INDEX\n";
196  else
197  os << " flags=" << flags << "\n";
198  os << " compression_ratio: " << compression_ratio << "\n";
199  os << " compression_type: " << compression_type << "\n";
200  if (bloom_filter_mode == BLOOM_FILTER_DISABLED)
201  os << " bloom_filter_mode=DISABLED\n";
202  else if (bloom_filter_mode == BLOOM_FILTER_ROWS)
203  os << " bloom_filter_mode=ROWS\n";
204  else if (bloom_filter_mode == BLOOM_FILTER_ROWS_COLS)
205  os << " bloom_filter_mode=ROWS_COLS\n";
206  else
207  os << " bloom_filter_mode=?(" << bloom_filter_mode << ")\n";
208  os << " bloom_filter_hash_count=" << (int)bloom_filter_hash_count << "\n";
209  os << " version: " << version << std::endl;
210 }
211 
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
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.
Hypertable definitions
static const int64_t TIMESTAMP_MAX
Definition: KeySpec.h:35
#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