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