0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
CellStoreV1.cc
Go to the documentation of this file.
1 /*
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, or any later version.
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 
22 #include "Common/Compat.h"
23 #include <cassert>
24 
25 #include <boost/algorithm/string.hpp>
26 #include <boost/scoped_array.hpp>
27 
28 #include "Common/Config.h"
29 #include "Common/Error.h"
30 #include "Common/Logger.h"
31 #include "Common/System.h"
32 #include "Common/Time.h"
33 
34 #include "AsyncComm/Protocol.h"
35 
38 #include "Hypertable/Lib/Key.h"
39 #include "Hypertable/Lib/Schema.h"
40 
41 #include "CellStoreV1.h"
42 #include "CellStoreTrailerV1.h"
43 #include "CellStoreScanner.h"
44 
45 #include "FileBlockCache.h"
46 #include "Global.h"
47 #include "Config.h"
48 
49 using namespace std;
50 using namespace Hypertable;
51 
52 namespace {
53  const uint32_t MAX_APPENDS_OUTSTANDING = 3;
54  const uint16_t BLOCK_HEADER_FORMAT = 0;
55 }
56 
57 
58 CellStoreV1::CellStoreV1(Filesystem *filesys)
59  : m_filesys(filesys), m_fd(-1), m_filename(), m_64bit_index(false),
60  m_compressor(0), m_buffer(0), m_outstanding_appends(0), m_offset(0),
61  m_last_key(0), m_file_length(0), m_disk_usage(0), m_file_id(0),
62  m_uncompressed_blocksize(0), m_bloom_filter_mode(BLOOM_FILTER_DISABLED),
63  m_bloom_filter(0), m_bloom_filter_items(0), m_restricted_range(false) {
65  assert(sizeof(float) == 4);
66 }
67 
68 
70  try {
71  delete m_compressor;
72  delete m_bloom_filter;
73  delete m_bloom_filter_items;
74  if (m_fd != -1)
76  }
77  catch (Exception &e) {
78  HT_ERROR_OUT << e << HT_END;
79  }
80 
83 
84 }
85 
86 
90 }
91 
92 
94  bool need_index = m_restricted_range || scan_ctx->restricted_range || scan_ctx->single_row;
95 
96  if (need_index) {
100  }
101 
102  if (m_64bit_index)
103  return make_shared<CellStoreScanner<CellStoreBlockIndexArray<int64_t>>>(shared_from_this(), scan_ctx, need_index ? &m_index_map64 : 0);
104  return make_shared<CellStoreScanner<CellStoreBlockIndexArray<uint32_t>>>(shared_from_this(), scan_ctx, need_index ? &m_index_map32 : 0);
105 }
106 
107 
108 void
109 CellStoreV1::create(const char *fname, size_t max_entries,
110  PropertiesPtr &props, const TableIdentifier *table_id) {
111  int64_t blocksize = props->get("blocksize", 0);
112  String compressor = props->get("compressor", String());
113 
114  assert(Config::properties); // requires Config::init* first
115 
116  if (blocksize == 0)
117  blocksize = Config::get_i32("Hypertable.RangeServer.CellStore"
118  ".DefaultBlockSize");
119  if (compressor.empty())
120  compressor = Config::get_str("Hypertable.RangeServer.CellStore"
121  ".DefaultCompressor");
122  if (!props->has("bloom-filter-mode")) {
123  // probably not called from AccessGroup
124  AccessGroupOptions::parse_bloom_filter(Config::get_str("Hypertable.RangeServer"
125  ".CellStore.DefaultBloomFilter"), props);
126  }
127 
128  m_buffer.reserve(blocksize*4);
129 
130  m_max_entries = max_entries;
131 
132  m_fd = -1;
133  m_offset = 0;
134  m_last_key = 0;
135 
137  m_index_builder.variable_buf().reserve(1024*1024);
138 
139  m_uncompressed_data = 0.0;
140  m_compressed_data = 0.0;
141 
142  m_trailer.clear();
143  m_trailer.blocksize = blocksize;
144  m_uncompressed_blocksize = blocksize;
145 
146  m_filename = fname;
147 
148  m_start_row = "";
150 
152  compressor, m_compressor_args);
153 
157 
159 
160  m_bloom_filter_mode = props->get<BloomFilterMode>("bloom-filter-mode");
161  m_max_approx_items = props->get_i32("max-approx-items");
162  m_trailer.filter_false_positive_prob = props->get_f64("false-positive");
163 
165  m_bloom_filter_items = new BloomFilterItems(); // aproximator items
166  }
167  HT_DEBUG_OUT <<"bloom-filter-mode="<< m_bloom_filter_mode
168  <<" max-approx-items="<< m_max_approx_items <<" false-positive="
170 }
171 
172 
173 void CellStoreV1::create_bloom_filter(bool is_approx) {
175 
176  HT_DEBUG_OUT << "Creating new BloomFilter for CellStore '"
177  << m_filename <<"' for "<< (is_approx ? "estimated " : "")
178  << m_trailer.num_filter_items << " items"<< HT_END;
179  try {
182  }
183  catch(Exception &e) {
184  HT_FATAL_OUT << "Error creating new BloomFilter for CellStore '"
185  << m_filename <<"' for "<< (is_approx ? "estimated " : "")
186  << m_trailer.num_filter_items << " items - "<< e << HT_END;
187  }
188 
189  for (const auto &blob : *m_bloom_filter_items)
190  m_bloom_filter->insert(blob.start, blob.size);
191 
192  delete m_bloom_filter_items;
193  m_bloom_filter_items = 0;
194 
195  HT_DEBUG_OUT << "Created new BloomFilter for CellStore '"
196  << m_filename <<"'"<< HT_END;
197 }
198 
199 
200 void CellStoreV1::load_bloom_filter() {
201  size_t len, amount;
202 
204 
205  HT_DEBUG_OUT << "Loading BloomFilter for CellStore '"
206  << m_filename <<"' with "<< m_trailer.num_filter_items
207  << " items"<< HT_END;
208  try {
211  }
212  catch(Exception &e) {
213  HT_FATAL_OUT << "Error loading BloomFilter for CellStore '"
214  << m_filename <<"' with "<< m_trailer.num_filter_items
215  << " items -"<< e << HT_END;
216  }
217 
219 
220  HT_ASSERT(amount == m_bloom_filter->size());
221 
222  if (amount > 0) {
223 
224  bool second_try = false;
225 
226  while (true) {
227  try {
228  len = m_filesys->pread(m_fd, m_bloom_filter->ptr(), amount,
229  m_trailer.filter_offset, second_try);
230  }
231  catch (Exception &e) {
232  if (!second_try) {
233  second_try=true;
234  continue;
235  }
236  HT_THROW2(e.code(), e, format("Error loading BloomFilter for CellStore '%s'",
237  m_filename.c_str()));
238  }
239  break;
240  }
241 
242  if (len != amount)
243  HT_THROWF(Error::FSBROKER_IO_ERROR, "Problem loading bloomfilter for"
244  "CellStore '%s' : tried to read %lld but only got %lld",
245  m_filename.c_str(), (Lld)amount, (Lld)len);
246  }
247 
250 
251 }
252 
253 
254 
256  uint64_t memory_purged = 0;
257 
259  memory_purged = m_index_stats.bloom_filter_memory;
260  delete m_bloom_filter;
261  m_bloom_filter = 0;
264  }
265 
267  memory_purged += m_index_stats.block_index_memory;
268  if (m_64bit_index)
270  else
274  }
275 
276  return memory_purged;
277 }
278 
279 
280 
281 void CellStoreV1::add(const Key &key, const ByteString value) {
282  EventPtr event_ptr;
283  DynamicBuffer zbuf;
284 
285  if (key.revision > m_trailer.revision)
287 
288  if (key.timestamp != TIMESTAMP_NULL) {
291  else if (key.timestamp > m_trailer.timestamp_max)
293  }
294 
295  if (m_buffer.fill() > (size_t)m_uncompressed_blocksize) {
296  BlockHeaderCellStore header(BLOCK_HEADER_FORMAT, DATA_BLOCK_MAGIC);
297 
299 
300  m_uncompressed_data += (float)m_buffer.fill();
301  m_compressor->deflate(m_buffer, zbuf, header);
302  m_compressed_data += (float)zbuf.fill();
303  m_buffer.clear();
304 
305  uint64_t llval = ((uint64_t)m_trailer.blocksize
306  * (uint64_t)m_uncompressed_data) / (uint64_t)m_compressed_data;
307  m_uncompressed_blocksize = (int64_t)llval;
308 
309  if (m_outstanding_appends >= MAX_APPENDS_OUTSTANDING) {
310  if (!m_sync_handler.wait_for_reply(event_ptr)) {
311  if (event_ptr->type == Event::MESSAGE)
313  "Problem writing to FS file '%s' : %s", m_filename.c_str(),
315  HT_THROWF(event_ptr->error,
316  "Problem writing to FS file '%s'", m_filename.c_str());
317  }
319  }
320 
321  size_t zlen = zbuf.fill();
322  StaticBuffer send_buf(zbuf);
323 
325  catch (Exception &e) {
326  HT_THROW2F(e.code(), e, "Problem writing to FS file '%s'",
327  m_filename.c_str());
328  }
330  m_offset += zlen;
331  }
332 
333  size_t value_len = value.length();
334 
335  m_buffer.ensure(key.length + value_len);
336 
338  m_buffer.add_unchecked(value.ptr, value_len);
339 
342  m_bloom_filter_items->insert(key.row, key.row_len);
343 
345  m_bloom_filter_items->insert(key.row, key.row_len + 2);
346 
348  m_trailer.num_filter_items = (size_t)(((double)m_max_entries
349  / (double)m_max_approx_items) * m_bloom_filter_items->size());
350  if (m_trailer.num_filter_items == 0) {
351  HT_INFOF("max_entries = %lld, max_approx_items = %lld, bloom_filter_items_size = %lld",
352  (Lld)m_max_entries, (Lld)m_max_approx_items, (Lld)m_bloom_filter_items->size());
354  }
355  create_bloom_filter(true);
356  }
357  }
358  else {
359  assert(!m_bloom_filter_items && m_bloom_filter);
360 
361  m_bloom_filter->insert(key.row);
362 
364  m_bloom_filter->insert(key.row, key.row_len + 2);
365  }
366  }
367 
369 }
370 
371 
372 void CellStoreV1::finalize(TableIdentifier *table_identifier) {
373  EventPtr event_ptr;
374  size_t zlen;
375  DynamicBuffer zbuf(0);
376  SerializedKey key;
377  StaticBuffer send_buf;
378  int64_t index_memory = 0;
379 
380  if (m_buffer.fill() > 0) {
381  BlockHeaderCellStore header(BLOCK_HEADER_FORMAT, DATA_BLOCK_MAGIC);
382 
384 
385  m_uncompressed_data += (float)m_buffer.fill();
386  m_compressor->deflate(m_buffer, zbuf, header);
387  m_compressed_data += (float)zbuf.fill();
388 
389  zlen = zbuf.fill();
390  send_buf = zbuf;
391 
392  if (m_outstanding_appends >= MAX_APPENDS_OUTSTANDING) {
393  if (!m_sync_handler.wait_for_reply(event_ptr))
395  "Problem finalizing CellStore file '%s' : %s",
396  m_filename.c_str(),
397  Protocol::string_format_message(event_ptr).c_str());
399  }
400 
402 
404  m_offset += zlen;
405  }
406 
407  m_buffer.free();
408 
410  if (m_uncompressed_data == 0)
412  else
414 
419 
423  {
424  BlockHeaderCellStore header(BLOCK_HEADER_FORMAT, INDEX_FIXED_BLOCK_MAGIC);
425  m_compressor->deflate(m_index_builder.fixed_buf(), zbuf, header);
426  }
427 
428  zlen = zbuf.fill();
429  send_buf = zbuf;
430 
432 
434  m_offset += zlen;
435 
439  {
440  BlockHeaderCellStore header(BLOCK_HEADER_FORMAT, INDEX_VARIABLE_BLOCK_MAGIC);
443  }
444 
445  zlen = zbuf.fill();
446  send_buf = zbuf;
447 
449 
451  m_offset += zlen;
452 
453  // write filter_offset
455 
456  // if bloom_items haven't been spilled to create a bloom filter yet, do it
458 
459  if (m_bloom_filter_items && m_bloom_filter_items->size() > 0) {
460  m_trailer.num_filter_items = m_bloom_filter_items->size();
462  }
463 
464  if (m_bloom_filter) {
465  m_bloom_filter->serialize(send_buf);
469  }
470  }
471 
473 
475  if (m_64bit_index) {
479  index_memory = m_index_map64.memory_used();
481  }
482  else {
486  index_memory = m_index_map32.memory_used();
487  }
488 
489  // deallocate fix index data
491 
492  // Add table information
493  m_trailer.table_id = table_identifier->index();
494  m_trailer.table_generation = table_identifier->generation;
496 
497  // write trailer
498  zbuf.clear();
499  zbuf.reserve(m_trailer.size());
500  m_trailer.serialize(zbuf.ptr);
501  zbuf.ptr += m_trailer.size();
502 
503  zlen = zbuf.fill();
504  send_buf = zbuf;
505 
506  m_filesys->append(m_fd, send_buf);
507 
509  m_offset += zlen;
510 
512  m_filesys->close(m_fd);
513 
516 
518  m_fd = m_filesys->open(m_filename, 0);
519 
521  if (m_disk_usage < 0)
522  HT_WARN_OUT << "[Issue 339] Disk usage for " << m_filename << "=" << m_disk_usage
523  << HT_END;
524  m_index_stats.block_index_memory = sizeof(CellStoreV1) + index_memory;
525 
526  if (m_bloom_filter)
528 
530 }
531 
532 
534  int64_t offset) {
535 
536  // switch to 64-bit offsets if offset being added is >= 2^32
537  if (!m_bigint && offset >= 4294967296LL) {
538  DynamicBuffer tmp_buf(m_fixed.size*2);
539  const uint8_t *src = m_fixed.base;
540  uint8_t *dst = tmp_buf.base;
541  size_t remaining = m_fixed.fill();
542  while (src < m_fixed.ptr)
543  Serialization::encode_i64(&dst, (uint64_t)Serialization::decode_i32(&src, &remaining));
544  delete [] m_fixed.release();
545  m_fixed.base = tmp_buf.base;
546  m_fixed.ptr = dst;
547  m_fixed.size = tmp_buf.size;
548  m_fixed.own = true;
549  tmp_buf.release();
550  m_bigint = true;
551  }
552 
553  // Add key to variable buffer
554  size_t key_len = key.length();
555  m_variable.ensure(key_len);
556  memcpy(m_variable.ptr, key.ptr, key_len);
557  m_variable.ptr += key_len;
558 
559  // Serialize offset into fix index buffer
560  if (m_bigint) {
561  m_fixed.ensure(8);
562  memcpy(m_fixed.ptr, &offset, 8);
563  m_fixed.ptr += 8;
564  }
565  else {
566  m_fixed.ensure(4);
567  memcpy(m_fixed.ptr, &offset, 4);
568  m_fixed.ptr += 4;
569  }
570 }
571 
572 
574  uint8_t *base;
575  size_t len;
576 
577  base = m_fixed.release(&len);
578  m_fixed.reserve(len);
579  m_fixed.add_unchecked(base, len);
580  delete [] base;
581 
582  base = m_variable.release(&len);
583  m_variable.reserve(len);
584  m_variable.add_unchecked(base, len);
585  delete [] base;
586 }
587 
588 
589 
590 void
591 CellStoreV1::open(const String &fname, const String &start_row,
592  const String &end_row, int32_t fd, int64_t file_length,
593  CellStoreTrailer *trailer) {
594  m_filename = fname;
595  m_start_row = start_row;
596  m_end_row = end_row;
597  m_fd = fd;
598  m_file_length = file_length;
599 
601 
602  m_trailer = *static_cast<CellStoreTrailerV1 *>(trailer);
603 
606 
608  m_64bit_index = true;
609 
613  "Bad index offsets in CellStore trailer fix=%lld, var=%lld, "
614  "length=%llu, file='%s'", (Lld)m_trailer.fix_index_offset,
615  (Lld)m_trailer.var_index_offset, (Llu)m_file_length, fname.c_str());
616 
617  if (!(start_row == "" && end_row == Key::END_ROW_MARKER))
619 
620 }
621 
622 
624  int64_t amount, index_amount;
625  int64_t len = 0;
626  BlockHeaderCellStore header(BLOCK_HEADER_FORMAT);
627  SerializedKey key;
628  bool inflating_fixed=true;
629  bool second_try = false;
630 
632 
633  if (m_compressor == 0)
635 
636  amount = index_amount = m_trailer.filter_offset - m_trailer.fix_index_offset;
637 
638  try_again:
639 
640  try {
641  DynamicBuffer buf(amount);
642 
644  len = m_filesys->pread(m_fd, buf.ptr, amount, m_trailer.fix_index_offset, second_try);
645 
646  if (len != amount)
647  HT_THROWF(Error::FSBROKER_IO_ERROR, "Error loading index for "
648  "CellStore '%s' : tried to read %lld but only got %lld",
649  m_filename.c_str(), (Lld)amount, (Lld)len);
653 
654  inflating_fixed = false;
655 
658 
660  DynamicBuffer vbuf(0, false);
662  vbuf.base = buf.ptr;
663  vbuf.ptr = buf.ptr + amount;
664 
666 
669  }
670  catch (Exception &e) {
671  String msg;
672  if (inflating_fixed) {
673  msg = String("Error inflating FIXED index for cellstore '")
674  + m_filename + "'";
675  HT_ERROR_OUT << msg << ": "<< e << HT_END;
676  }
677  else {
678  msg = "Error inflating VARIABLE index for cellstore '" + m_filename + "'";
679  HT_ERROR_OUT << msg << ": " << e << HT_END;
680  }
681  HT_ERROR_OUT << "pread(fd=" << m_fd << ", len=" << len << ", amount="
682  << index_amount << ")\n" << HT_END;
684  if (second_try)
685  HT_THROW2(e.code(), e, msg);
686  second_try = true;
687  goto try_again;
688  }
689 
691  if (m_64bit_index) {
695  }
696  else {
700  }
701 
703  if (m_disk_usage < 0)
704  HT_WARN_OUT << "[Issue 339] Disk usage for " << m_filename << "=" << m_disk_usage
705  << HT_END;
706 
709 
711 
712 }
713 
714 
716 
718  return true;
719  else if (m_trailer.num_filter_items == 0) // bloom filter is empty
720  return false;
721  else if (m_bloom_filter == 0)
723 
725 
726  switch (m_bloom_filter_mode) {
727  case BLOOM_FILTER_ROWS:
728  return may_contain(scan_ctx->start_row);
730  if (may_contain(scan_ctx->start_row)) {
731  SchemaPtr &schema = scan_ctx->schema;
732  size_t rowlen = scan_ctx->start_row.length();
733  boost::scoped_array<char> rowcol(new char[rowlen + 2]);
734  memcpy(rowcol.get(), scan_ctx->start_row.c_str(), rowlen + 1);
735 
736  for (auto col : scan_ctx->spec->columns) {
737  uint8_t column_family_id = schema->get_column_family(col)->get_id();
738  rowcol[rowlen + 1] = column_family_id;
739 
740  if (may_contain(rowcol.get(), rowlen + 2))
741  return true;
742  }
743  }
744  return false;
745  default:
746  HT_ASSERT(!"unpossible bloom filter mode!");
747  }
748  return false; // silence stupid compilers
749 }
750 
751 
752 bool CellStoreV1::may_contain(const void *ptr, size_t len) {
753 
755  return true;
756  else if (m_trailer.num_filter_items == 0) // bloom filter is empty
757  return false;
758  else if (m_bloom_filter == 0)
760 
762  bool may_contain = m_bloom_filter->may_contain(ptr, len);
763  return may_contain;
764 }
765 
766 
767 
771  if (m_64bit_index)
773  else
775 }
776 
778  return BLOCK_HEADER_FORMAT;
779 }
void free()
Frees resources.
static const char INDEX_FIXED_BLOCK_MAGIC[10]
Definition: CellStore.h:326
#define HT_THROW2F(_code_, _ex_, _fmt_,...)
Definition: Error.h:494
A memory buffer of static size.
Definition: StaticBuffer.h:45
Retrieves system information (hardware, installation directory, etc)
virtual void append(int fd, StaticBuffer &buffer, Flags flags, DispatchHandler *handler)=0
Appends data to a file asynchronously.
Abstract base class for cell store trailer.
virtual void close(int fd, DispatchHandler *handler)=0
Closes a file asynchronously.
int64_t timestamp
Definition: Key.h:134
void display_block_info() override
Displays block information to stdout.
Definition: CellStoreV1.cc:768
const char * row
Definition: Key.h:129
CellListScannerPtr create_scanner(ScanContext *scan_ctx) override
Creates a scanner on this cell list.
Definition: CellStoreV1.cc:93
virtual void pread(int fd, size_t amount, uint64_t offset, bool verify_checksum, DispatchHandler *handler)=0
Reads data from a file at the specified position asynchronously.
void add(const Key &key, const ByteString value) override
Inserts a key/value pair into the cell list.
Definition: CellStoreV1.cc:281
static const char INDEX_VARIABLE_BLOCK_MAGIC[10]
Definition: CellStore.h:327
static int32_t response_code(const Event *event)
Returns the response code from an event event generated in response to a request message.
Definition: Protocol.cc:39
PropertiesPtr properties
This singleton map stores all options.
Definition: Config.cc:47
std::string String
A String is simply a typedef to std::string.
Definition: String.h:44
IndexBuilder m_index_builder
Definition: CellStoreV1.h:143
uint32_t length
Definition: Key.h:124
bool check_magic(const char *magic)
Compares a given character sequence with the magic field.
Definition: BlockHeader.h:86
static String string_format_message(const Event *event)
Returns error message decoded standard error MESSAGE generated in response to a request message...
Definition: Protocol.cc:51
String format(const char *fmt,...)
Returns a String using printf like format facilities Vanilla snprintf is about 1.5x faster than this...
Definition: String.cc:37
std::string m_start_row
Definition: CellList.h:99
long long unsigned int Llu
Shortcut for printf formats.
Definition: String.h:50
BlockCompressionCodec::Args m_compressor_args
Definition: CellStoreV1.h:154
Declarations for CellStoreScanner.
static void parse_bloom_filter(const std::string &spec, PropertiesPtr &props)
Parsers a bloom filter specification and sets properties.
void create(const char *fname, size_t max_entries, PropertiesPtr &props, const TableIdentifier *table_id=0) override
Creates a new cell store.
Definition: CellStoreV1.cc:109
virtual void serialize(uint8_t *buf)
Serializes this trailer to the given buffer;.
std::shared_ptr< Event > EventPtr
Smart pointer to Event.
Definition: Event.h:228
STL namespace.
Scan context information.
Definition: ScanContext.h:52
uint8_t * ptr()
Getter for the bloom filter data.
Definition: BloomFilter.h:226
std::string m_end_row
Definition: CellList.h:100
Type
Enumeration for compression type.
uint8_t * ptr
Pointer to the end of the used part of the buffer.
void open(const String &fname, const String &start_row, const String &end_row, int32_t fd, int64_t file_length, CellStoreTrailer *trailer) override
Opens a cell store with possibly a restricted view.
Definition: CellStoreV1.cc:591
void add_entry(const SerializedKey key, int64_t offset)
Definition: CellStoreV1.cc:533
bool wait_for_reply(EventPtr &event)
This method is used by a client to synchronize.
A dynamic, resizable and reference counted memory buffer.
Definition: DynamicBuffer.h:42
Declarations for Schema.
uint32_t decode_i32(const uint8_t **bufp, size_t *remainp)
Decode a 32-bit integer in little-endian order.
uint64_t purge_indexes() override
Purges bloom filter and block indexes.
Definition: CellStoreV1.cc:255
uint32_t m_outstanding_appends
Definition: CellStoreV1.h:145
A class managing one or more serializable ByteStrings.
Definition: ByteString.h:47
#define HT_ASSERT(_e_)
Definition: Logger.h:396
uint32_t row_len
Definition: Key.h:131
BlockCompressionCodec * m_compressor
Definition: CellStoreV1.h:141
IndexMemoryStats m_index_stats
Definition: CellStore.h:332
static BlockCompressionCodec::Type parse_block_codec_spec(const std::string &spec, BlockCompressionCodec::Args &args)
Given a block codec config string return its type and put config.
static Hypertable::MemoryTracker * memory_tracker
Definition: Global.h:94
CellStoreTrailerV1 m_trailer
Definition: CellStoreV1.h:140
bool may_contain(const void *ptr, size_t len)
Definition: CellStoreV1.cc:752
CellStoreBlockIndexArray< int64_t > m_index_map64
Definition: CellStoreV1.h:138
const ScanSpec * spec
Definition: ScanContext.h:55
size_t size()
Getter for the bloom filter size.
Definition: BloomFilter.h:232
static uint64_t access_counter
Definition: Global.h:106
std::shared_ptr< Properties > PropertiesPtr
Definition: Properties.h:447
uint32_t size
The size of the allocated memory buffer (base)
Logging routines and macros.
BloomFilterMode
Enumeration for bloom filter modes.
virtual size_t size()
Returns the serialized size of the trailer.
Compatibility Macros for C/C++.
BasicBloomFilter BloomFilter
Definition: BloomFilter.h:284
void encode_i64(uint8_t **bufp, uint64_t val)
Encode a 64-bit integer in little-endian order.
int64_t m_uncompressed_blocksize
Definition: CellStoreV1.h:153
#define HT_END
Definition: Logger.h:220
static const int64_t TIMESTAMP_NULL
Definition: KeySpec.h:36
size_t length() const
Retrieves the length of the serialized string.
Definition: ByteString.h:62
static BlockCompressionCodec * create_block_codec(BlockCompressionCodec::Type, const BlockCompressionCodec::Args &args=BlockCompressionCodec::Args())
#define HT_ERROR_OUT
Definition: Logger.h:301
virtual void clear()
Clears the contents of this trailer;.
Time related declarations.
bool may_contain(const void *key, size_t len) const
Checks if the data set "may" contain the key.
Definition: BloomFilter.h:188
#define HT_WARN_OUT
Definition: Logger.h:291
bool own
If true then the buffer (base) will be released when going out of scope; if false then the caller has...
const uint8_t * ptr
The pointer to the serialized data.
Definition: ByteString.h:121
CellStoreV1(Filesystem *filesys)
Definition: CellStoreV1.cc:58
Hypertable definitions
SerializedKey serial
Definition: Key.h:123
long long int Lld
Shortcut for printf formats.
Definition: String.h:53
BlobHashSet BloomFilterItems
Definition: CellStoreV1.h:132
void load(DynamicBuffer &fixed, DynamicBuffer &variable, int64_t end_of_data, const String &start_row="", const String &end_row="")
void clear()
Clears the buffer.
BloomFilterMode m_bloom_filter_mode
Definition: CellStoreV1.h:157
Declarations for BlockHeaderCellStore.
BloomFilter * m_bloom_filter
Definition: CellStoreV1.h:158
Declarations for Protocol.
#define HT_INFOF(msg,...)
Definition: Logger.h:272
#define HT_THROWF(_code_, _fmt_,...)
Definition: Error.h:490
Provides access to internal components of opaque key.
Definition: Key.h:40
uint16_t block_header_format() override
Definition: CellStoreV1.cc:777
uint8_t * base
Pointer to the allocated memory buffer.
size_t fill() const
Returns the size of the used portion.
Definition: DynamicBuffer.h:70
virtual void deflate(const DynamicBuffer &input, DynamicBuffer &output, BlockHeader &header, size_t reserve=0)=0
Compresses a buffer.
static const char DATA_BLOCK_MAGIC[10]
Definition: CellStore.h:325
Request/response message event.
Definition: Event.h:63
void subtract(int64_t amount)
Subtract to memory used.
Definition: MemoryTracker.h:60
void create_bloom_filter(bool is_approx=false)
Definition: CellStoreV1.cc:173
void serialize(StaticBuffer &buf)
Serializes the BloomFilter into a static memory buffer.
Definition: BloomFilter.h:218
This is a generic exception class for Hypertable.
Definition: Error.h:314
BloomFilterItems * m_bloom_filter_items
Definition: CellStoreV1.h:159
DynamicBuffer m_buffer
Definition: CellStoreV1.h:142
int64_t revision
Definition: Key.h:135
uint8_t * release(size_t *lenp=0)
Moves ownership of the buffer to the caller.
std::shared_ptr< Schema > SchemaPtr
Smart pointer to Schema.
Definition: Schema.h:465
std::shared_ptr< CellListScanner > CellListScannerPtr
Definition: CellList.h:35
void insert(const void *key, size_t len)
Inserts a new blob into the hash.
Definition: BloomFilter.h:159
virtual void open(const String &name, uint32_t flags, DispatchHandler *handler)=0
Opens a file asynchronously.
Configuration settings.
Filesystem * m_filesys
Definition: CellStoreV1.h:134
CellStoreBlockIndexArray< uint32_t > m_index_map32
Definition: CellStoreV1.h:137
A space-efficent probabilistic set for membership test, false postives are possible, but false negatives are not.
Definition: BloomFilter.h:50
virtual void inflate(const DynamicBuffer &input, DynamicBuffer &output, BlockHeader &header)=0
Decompresses a buffer.
Error codes, Exception handling, error logging.
#define HT_THROW(_code_, _msg_)
Definition: Error.h:478
static const char * END_ROW_MARKER
Definition: Key.h:49
#define HT_FATAL_OUT
Definition: Logger.h:347
void add(int64_t amount)
Add to memory used.
Definition: MemoryTracker.h:53
void ensure(size_t len)
Ensure space for additional data Will grow the space to 1.5 of the needed space with existing data un...
Definition: DynamicBuffer.h:82
uint8_t * add_unchecked(const void *data, size_t len)
Adds additional data without boundary checks.
BlockCompressionCodec * create_block_compression_codec() override
Creates a block compression codec suitable for decompressing the cell store's blocks.
Definition: CellStoreV1.cc:87
virtual void create(const String &name, uint32_t flags, int32_t bufsz, int32_t replication, int64_t blksz, DispatchHandler *handler)=0
Creates a file asynchronously.
#define HT_DEBUG_OUT
Definition: Logger.h:261
void finalize(TableIdentifier *table_identifier) override
Finalizes the creation of a cell store, by writing block index and metadata trailer.
Definition: CellStoreV1.cc:372
DispatchHandlerSynchronizer m_sync_handler
Definition: CellStoreV1.h:144
int64_t get_ts64()
Returns the current time in nanoseconds as a 64bit number.
Definition: Time.cc:40
Abstract base class for block compression codecs.
Abstract base class for a filesystem.
Definition: Filesystem.h:72
int code() const
Returns the error code.
Definition: Error.h:391
void reserve(size_t len, bool nocopy=false)
Reserve space for additional data Will grow the space to exactly what's needed.
Definition: DynamicBuffer.h:95
#define HT_THROW2(_code_, _ex_, _msg_)
Definition: Error.h:484