0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
CellStoreV3.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.
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 "CellStoreV3.h"
42 #include "CellStoreTrailerV3.h"
43 #include "CellStoreScanner.h"
44 
45 #include "FileBlockCache.h"
46 #include "Global.h"
47 #include "Config.h"
48 #include "KeyCompressorPrefix.h"
49 #include "KeyDecompressorPrefix.h"
50 
51 using namespace std;
52 using namespace Hypertable;
53 
54 namespace {
55  const uint32_t MAX_APPENDS_OUTSTANDING = 3;
56  const uint16_t BLOCK_HEADER_FORMAT = 0;
57 }
58 
59 
60 CellStoreV3::CellStoreV3(Filesystem *filesys)
61  : m_filesys(filesys) {
63  assert(sizeof(float) == 4);
64 }
65 
67  : m_filesys(filesys), m_schema(schema) {
69  assert(sizeof(float) == 4);
70 }
71 
73  try {
74  delete m_compressor;
75  delete m_bloom_filter;
76  delete m_bloom_filter_items;
77  if (m_fd != -1)
79  delete [] m_column_ttl;
80  }
81  catch (Exception &e) {
82  HT_ERROR_OUT << e << HT_END;
83  }
84 
87 
88 }
89 
90 
94 }
95 
97  return new KeyDecompressorPrefix();
98 }
99 
100 
102  bool need_index = m_restricted_range || scan_ctx->restricted_range || scan_ctx->single_row;
103 
104  if (need_index) {
108  }
109 
110  if (m_64bit_index)
111  return make_shared<CellStoreScanner<CellStoreBlockIndexArray<int64_t>>>(shared_from_this(), scan_ctx, need_index ? &m_index_map64 : 0);
112  return make_shared<CellStoreScanner<CellStoreBlockIndexArray<uint32_t>>>(shared_from_this(), scan_ctx, need_index ? &m_index_map32 : 0);
113 }
114 
115 
116 void
117 CellStoreV3::create(const char *fname, size_t max_entries,
118  PropertiesPtr &props, const TableIdentifier *table_id) {
119  int32_t replication = props->get_i32("replication", int32_t(-1));
120  int64_t blocksize = props->get("blocksize", 0);
121  String compressor = props->get("compressor", String());
122 
123  m_key_compressor = make_shared<KeyCompressorPrefix>();
124 
125  assert(Config::properties); // requires Config::init* first
126 
127  if (replication == -1 && Config::has("Hypertable.RangeServer.CellStore.DefaultReplication"))
128  replication = Config::get_i32("Hypertable.RangeServer.CellStore.DefaultReplication");
129 
130  if (blocksize == 0)
131  blocksize = Config::get_i32("Hypertable.RangeServer.CellStore"
132  ".DefaultBlockSize");
133  if (compressor.empty())
134  compressor = Config::get_str("Hypertable.RangeServer.CellStore"
135  ".DefaultCompressor");
136  if (!props->has("bloom-filter-mode")) {
137  // probably not called from AccessGroup
138  AccessGroupOptions::parse_bloom_filter(Config::get_str("Hypertable.RangeServer"
139  ".CellStore.DefaultBloomFilter"), props);
140  }
141 
142  m_buffer.reserve(blocksize*4);
143 
144  m_max_entries = max_entries;
145 
146  m_fd = -1;
147  m_offset = 0;
148 
150  m_index_builder.variable_buf().reserve(1024*1024);
151 
152  m_uncompressed_data = 0.0;
153  m_compressed_data = 0.0;
154 
155  m_trailer.clear();
156  m_trailer.blocksize = blocksize;
157  m_uncompressed_blocksize = blocksize;
158 
159  // set up the "column_ttl" vector
161  ColumnFamilySpecs &column_family_specs = m_schema->get_column_families();
162  for (size_t i=0; i<column_family_specs.size(); i++) {
163  if (column_family_specs[i]->get_option_ttl()) {
164  if (m_column_ttl == 0) {
165  m_column_ttl = new int64_t[256];
166  memset(m_column_ttl, 0, 256*8);
167  }
168  m_column_ttl[ column_family_specs[i]->get_id() ] = column_family_specs[i]->get_option_ttl() * 1000000000LL;
169  }
170  }
171 
172  m_filename = fname;
173 
174  m_start_row = "";
176 
178  compressor, m_compressor_args);
179 
183 
185 
186  m_bloom_filter_mode = props->get<BloomFilterMode>("bloom-filter-mode");
187  m_max_approx_items = props->get_i32("max-approx-items");
188 
190  bool has_num_hashes = props->has("num-hashes");
191  bool has_bits_per_item = props->has("bits-per-item");
192 
193  if (has_num_hashes || has_bits_per_item) {
194  if (!(has_num_hashes && has_bits_per_item)) {
195  HT_WARN("Bloom filter option --bits-per-item must be used with "
196  "--num-hashes, defaulting to false probability of 0.01");
198  }
199  else {
200  m_trailer.bloom_filter_hash_count = props->get_i32("num-hashes");
201  m_bloom_bits_per_item = props->get_f64("bits-per-item");
202  }
203  }
204  else
205  m_filter_false_positive_prob = props->get_f64("false-positive");
206  m_bloom_filter_items = new BloomFilterItems(); // aproximator items
207  }
208  HT_DEBUG_OUT <<"bloom-filter-mode="<< m_bloom_filter_mode
209  <<" max-approx-items="<< m_max_approx_items <<" false-positive="
211 }
212 
213 
214 void CellStoreV3::create_bloom_filter(bool is_approx) {
216 
217  HT_DEBUG_OUT << "Creating new BloomFilter for CellStore '"
218  << m_filename <<"' for "<< (is_approx ? "estimated " : "")
219  << m_trailer.filter_items_estimate << " items"<< HT_END;
220  try {
221  if (m_filter_false_positive_prob != 0.0)
224  else
228  }
229  catch(Exception &e) {
230  HT_FATAL_OUT << "Error creating new BloomFilter for CellStore '"
231  << m_filename <<"' for "<< (is_approx ? "estimated " : "")
232  << m_trailer.filter_items_estimate << " items - "<< e << HT_END;
233  }
234 
235  for (const auto &blob : *m_bloom_filter_items)
236  m_bloom_filter->insert(blob.start, blob.size);
237 
238  delete m_bloom_filter_items;
239  m_bloom_filter_items = 0;
240 
241  HT_DEBUG_OUT << "Created new BloomFilter for CellStore '"
242  << m_filename <<"'"<< HT_END;
243 }
244 
245 
246 void CellStoreV3::load_bloom_filter() {
247  size_t len, amount;
248 
250 
251  HT_DEBUG_OUT << "Loading BloomFilter for CellStore '"
253  << " items"<< HT_END;
254  try {
259  }
260  catch(Exception &e) {
261  HT_FATAL_OUT << "Error loading BloomFilter for CellStore '"
263  << " items -"<< e << HT_END;
264  }
265 
267 
268  HT_ASSERT(amount == m_bloom_filter->size());
269 
270  if (amount > 0) {
271 
272  bool second_try = false;
273 
274  while (true) {
275  try {
276  len = m_filesys->pread(m_fd, m_bloom_filter->ptr(), amount,
277  m_trailer.filter_offset, second_try);
278  }
279  catch (Exception &e) {
280  if (!second_try) {
281  second_try=true;
282  continue;
283  }
284  HT_THROW2(e.code(), e, format("Error loading BloomFilter for CellStore '%s'",
285  m_filename.c_str()));
286  }
287  break;
288  }
289 
290  if (len != amount)
291  HT_THROWF(Error::FSBROKER_IO_ERROR, "Problem loading bloomfilter for"
292  "CellStore '%s' : tried to read %lld but only got %lld",
293  m_filename.c_str(), (Lld)amount, (Lld)len);
294 
295  m_bytes_read += len;
296 
297  }
298 
301 
302 }
303 
304 
305 
307  uint64_t memory_purged = 0;
308 
310  memory_purged = m_index_stats.bloom_filter_memory;
311  delete m_bloom_filter;
312  m_bloom_filter = 0;
315  }
316 
318  memory_purged += m_index_stats.block_index_memory;
319  if (m_64bit_index)
321  else
325  }
326 
327  return memory_purged;
328 }
329 
330 
331 
332 void CellStoreV3::add(const Key &key, const ByteString value) {
333  EventPtr event_ptr;
334  DynamicBuffer zbuf;
335 
336  if (key.revision > m_trailer.revision)
338 
339  if (key.timestamp != TIMESTAMP_NULL) {
342  else if (key.timestamp > m_trailer.timestamp_max)
344  }
345 
346  if (m_buffer.fill() > (size_t)m_uncompressed_blocksize) {
347  BlockHeaderCellStore header(BLOCK_HEADER_FORMAT, DATA_BLOCK_MAGIC);
348 
350 
351  m_uncompressed_data += (float)m_buffer.fill();
352  m_compressor->deflate(m_buffer, zbuf, header);
353  m_compressed_data += (float)zbuf.fill();
354  m_buffer.clear();
355 
356  uint64_t llval = ((uint64_t)m_trailer.blocksize
357  * (uint64_t)m_uncompressed_data) / (uint64_t)m_compressed_data;
358  m_uncompressed_blocksize = (int64_t)llval;
359 
360  if (m_outstanding_appends >= MAX_APPENDS_OUTSTANDING) {
361  if (!m_sync_handler.wait_for_reply(event_ptr)) {
362  if (event_ptr->type == Event::MESSAGE)
364  "Problem writing to FS file '%s' : %s", m_filename.c_str(),
366  HT_THROWF(event_ptr->error,
367  "Problem writing to FS file '%s'", m_filename.c_str());
368  }
370  }
371 
372  size_t zlen = zbuf.fill();
373  StaticBuffer send_buf(zbuf);
374 
376  catch (Exception &e) {
377  HT_THROW2F(e.code(), e, "Problem writing to FS file '%s'",
378  m_filename.c_str());
379  }
381  m_offset += zlen;
382  m_key_compressor->reset();
383  }
384 
385  m_key_compressor->add(key);
386 
387  size_t key_len = m_key_compressor->length();
388  size_t value_len = value.length();
389 
390  if (m_column_ttl && m_column_ttl[key.column_family_code] != 0) {
391  m_trailer.expirable_data += key_len + value_len;
394  }
395 
396  m_buffer.ensure(key_len + value_len);
397 
398  m_key_compressor->write(m_buffer.ptr);
399  m_buffer.ptr += key_len;
400 
401  m_buffer.add_unchecked(value.ptr, value_len);
402 
405  m_bloom_filter_items->insert(key.row, key.row_len);
406 
408  m_bloom_filter_items->insert(key.row, key.row_len + 2);
409 
411  m_trailer.filter_items_estimate = (size_t)(((double)m_max_entries
412  / (double)m_max_approx_items) * m_bloom_filter_items->size());
413  if (m_trailer.filter_items_estimate == 0) {
414  HT_INFOF("max_entries = %lld, max_approx_items = %lld, bloom_filter_items_size = %lld",
415  (Lld)m_max_entries, (Lld)m_max_approx_items, (Lld)m_bloom_filter_items->size());
417  }
418  create_bloom_filter(true);
419  }
420  }
421  else {
422  assert(!m_bloom_filter_items && m_bloom_filter);
423 
424  m_bloom_filter->insert(key.row);
425 
427  m_bloom_filter->insert(key.row, key.row_len + 2);
428  }
429  }
430 
432 }
433 
434 
435 void CellStoreV3::finalize(TableIdentifier *table_identifier) {
436  EventPtr event_ptr;
437  size_t zlen;
438  DynamicBuffer zbuf(0);
439  SerializedKey key;
440  StaticBuffer send_buf;
441  int64_t index_memory = 0;
442 
443  if (m_buffer.fill() > 0) {
444  BlockHeaderCellStore header(BLOCK_HEADER_FORMAT, DATA_BLOCK_MAGIC);
445 
447 
448  m_uncompressed_data += (float)m_buffer.fill();
449  m_compressor->deflate(m_buffer, zbuf, header);
450  m_compressed_data += (float)zbuf.fill();
451 
452  zlen = zbuf.fill();
453  send_buf = zbuf;
454 
455  if (m_outstanding_appends >= MAX_APPENDS_OUTSTANDING) {
456  if (!m_sync_handler.wait_for_reply(event_ptr))
458  "Problem finalizing CellStore file '%s' : %s",
459  m_filename.c_str(),
460  Protocol::string_format_message(event_ptr).c_str());
462  }
463 
465 
467  m_offset += zlen;
468  }
469 
470  m_buffer.free();
471 
473  if (m_uncompressed_data == 0)
475  else
477 
479 
484 
488  {
489  BlockHeaderCellStore header(BLOCK_HEADER_FORMAT, INDEX_FIXED_BLOCK_MAGIC);
490  m_compressor->deflate(m_index_builder.fixed_buf(), zbuf, header);
491  }
492 
493  zlen = zbuf.fill();
494  send_buf = zbuf;
495 
497 
499  m_offset += zlen;
500 
504  {
505  BlockHeaderCellStore header(BLOCK_HEADER_FORMAT, INDEX_VARIABLE_BLOCK_MAGIC);
508  }
509 
510  zlen = zbuf.fill();
511  send_buf = zbuf;
512 
514 
516  m_offset += zlen;
517 
518  // write filter_offset
520 
521  // if bloom_items haven't been spilled to create a bloom filter yet, do it
524 
525  if (m_bloom_filter_items && m_bloom_filter_items->size() > 0) {
526  m_trailer.filter_items_estimate = m_bloom_filter_items->size();
528  }
529 
530  if (m_bloom_filter) {
535  m_bloom_filter->serialize(send_buf);
539  }
540  }
541 
543 
545  if (m_64bit_index) {
549  index_memory = m_index_map64.memory_used();
551  }
552  else {
556  index_memory = m_index_map32.memory_used();
557  }
558 
559  // deallocate fix index data
561 
562  // Add table information
563  m_trailer.table_id = table_identifier->index();
564  m_trailer.table_generation = table_identifier->generation;
566 
567  // write trailer
568  zbuf.clear();
569  zbuf.reserve(m_trailer.size());
570  m_trailer.serialize(zbuf.ptr);
571  zbuf.ptr += m_trailer.size();
572 
573  zlen = zbuf.fill();
574  send_buf = zbuf;
575 
576  m_filesys->append(m_fd, send_buf);
577 
579  m_offset += zlen;
580 
582  m_filesys->close(m_fd);
583 
586 
588  m_fd = m_filesys->open(m_filename, 0);
589 
591  if (m_disk_usage < 0)
592  HT_WARN_OUT << "[Issue 339] Disk usage for " << m_filename << "=" << m_disk_usage
593  << HT_END;
594  m_index_stats.block_index_memory = sizeof(CellStoreV3) + index_memory;
595 
596  if (m_bloom_filter)
598 
599  delete [] m_column_ttl;
600  m_column_ttl = 0;
601 
603 }
604 
605 
607  int64_t offset) {
608 
609  // switch to 64-bit offsets if offset being added is >= 2^32
610  if (!m_bigint && offset >= 4294967296LL) {
611  DynamicBuffer tmp_buf(m_fixed.size*2);
612  const uint8_t *src = m_fixed.base;
613  uint8_t *dst = tmp_buf.base;
614  size_t remaining = m_fixed.fill();
615  while (src < m_fixed.ptr)
616  Serialization::encode_i64(&dst, (uint64_t)Serialization::decode_i32(&src, &remaining));
617  delete [] m_fixed.release();
618  m_fixed.base = tmp_buf.base;
619  m_fixed.ptr = dst;
620  m_fixed.size = tmp_buf.size;
621  m_fixed.own = true;
622  tmp_buf.release();
623  m_bigint = true;
624  }
625 
626  // Add key to variable buffer
627  size_t key_len = key_compressor->length_uncompressed();
628  m_variable.ensure(key_len);
629  key_compressor->write_uncompressed(m_variable.ptr);
630  m_variable.ptr += key_len;
631 
632  // Serialize offset into fix index buffer
633  if (m_bigint) {
634  m_fixed.ensure(8);
635  memcpy(m_fixed.ptr, &offset, 8);
636  m_fixed.ptr += 8;
637  }
638  else {
639  m_fixed.ensure(4);
640  memcpy(m_fixed.ptr, &offset, 4);
641  m_fixed.ptr += 4;
642  }
643 }
644 
645 
647  uint8_t *base;
648  size_t len;
649 
650  base = m_fixed.release(&len);
651  m_fixed.reserve(len);
652  m_fixed.add_unchecked(base, len);
653  delete [] base;
654 
655  base = m_variable.release(&len);
656  m_variable.reserve(len);
657  m_variable.add_unchecked(base, len);
658  delete [] base;
659 }
660 
661 
662 
663 void
664 CellStoreV3::open(const String &fname, const String &start_row,
665  const String &end_row, int32_t fd, int64_t file_length,
666  CellStoreTrailer *trailer) {
667  m_filename = fname;
668  m_start_row = start_row;
669  m_end_row = end_row;
670  m_fd = fd;
671  m_file_length = file_length;
672 
674 
675  m_trailer = *static_cast<CellStoreTrailerV3 *>(trailer);
676 
678 
681 
683  m_64bit_index = true;
684 
688  "Bad index offsets in CellStore trailer fix=%lld, var=%lld, "
689  "length=%llu, file='%s'", (Lld)m_trailer.fix_index_offset,
690  (Lld)m_trailer.var_index_offset, (Llu)m_file_length, fname.c_str());
691 
692 }
693 
694 
696  int64_t amount, index_amount;
697  int64_t len = 0;
698  BlockHeaderCellStore header(BLOCK_HEADER_FORMAT);
699  SerializedKey key;
700  bool inflating_fixed=true;
701  bool second_try = false;
702 
704 
705  if (m_compressor == 0)
707 
708  amount = index_amount = m_trailer.filter_offset - m_trailer.fix_index_offset;
709 
710  try_again:
711 
712  try {
713  DynamicBuffer buf(amount);
714 
716  len = m_filesys->pread(m_fd, buf.ptr, amount, m_trailer.fix_index_offset, second_try);
717 
718  if (len != amount)
719  HT_THROWF(Error::FSBROKER_IO_ERROR, "Error loading index for "
720  "CellStore '%s' : tried to read %lld but only got %lld",
721  m_filename.c_str(), (Lld)amount, (Lld)len);
725 
727 
728  inflating_fixed = false;
729 
732 
734  DynamicBuffer vbuf(0, false);
736  vbuf.base = buf.ptr;
737  vbuf.ptr = buf.ptr + amount;
738 
740 
742 
745  }
746  catch (Exception &e) {
747  String msg;
748  if (inflating_fixed) {
749  msg = String("Error inflating FIXED index for cellstore '")
750  + m_filename + "'";
751  HT_ERROR_OUT << msg << ": "<< e << HT_END;
752  }
753  else {
754  msg = "Error inflating VARIABLE index for cellstore '" + m_filename + "'";
755  HT_ERROR_OUT << msg << ": " << e << HT_END;
756  }
757  HT_ERROR_OUT << "pread(fd=" << m_fd << ", len=" << len << ", amount="
758  << index_amount << ")\n" << HT_END;
760  if (second_try)
761  HT_THROW2(e.code(), e, msg);
762  second_try = true;
763  goto try_again;
764  }
765 
767  if (m_64bit_index) {
771  }
772  else {
776  }
777 
779  if (m_disk_usage < 0)
780  HT_WARN_OUT << "[Issue 339] Disk usage for " << m_filename << "=" << m_disk_usage
781  << HT_END;
782 
785 
787 
788 }
789 
790 
792 
794  return true;
795  else if (m_trailer.filter_length == 0) // bloom filter is empty
796  return false;
797  else if (m_bloom_filter == 0)
799 
801 
802  switch (m_bloom_filter_mode) {
803  case BLOOM_FILTER_ROWS:
804  return may_contain(scan_ctx->start_row);
806  if (may_contain(scan_ctx->start_row)) {
807  SchemaPtr &schema = scan_ctx->schema;
808  size_t rowlen = scan_ctx->start_row.length();
809  boost::scoped_array<char> rowcol(new char[rowlen + 2]);
810  memcpy(rowcol.get(), scan_ctx->start_row.c_str(), rowlen + 1);
811 
812  for (auto col : scan_ctx->spec->columns) {
813  uint8_t column_family_id = schema->get_column_family(col)->get_id();
814  rowcol[rowlen + 1] = column_family_id;
815 
816  if (may_contain(rowcol.get(), rowlen + 2))
817  return true;
818  }
819  }
820  return false;
821  default:
822  HT_ASSERT(!"unpossible bloom filter mode!");
823  }
824  return false; // silence stupid compilers
825 }
826 
827 
828 bool CellStoreV3::may_contain(const void *ptr, size_t len) {
829 
831  return true;
832  else if (m_trailer.filter_length == 0) // bloom filter is empty
833  return false;
834  else if (m_bloom_filter == 0)
836 
838  bool may_contain = m_bloom_filter->may_contain(ptr, len);
839  return may_contain;
840 }
841 
842 
843 
847  if (m_64bit_index)
849  else
851 }
852 
853 
855  return BLOCK_HEADER_FORMAT;
856 }
void free()
Frees resources.
BlockCompressionCodec * m_compressor
Definition: CellStoreV3.h:146
Filesystem * m_filesys
Definition: CellStoreV3.h:138
size_t get_num_hashes()
Getter for the number of hash functions.
Definition: BloomFilter.h:238
static const char INDEX_FIXED_BLOCK_MAGIC[10]
Definition: CellStore.h:326
#define HT_THROW2F(_code_, _ex_, _fmt_,...)
Definition: Error.h:494
bool may_contain(const void *ptr, size_t len)
Definition: CellStoreV3.cc:828
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
BlockCompressionCodec * create_block_compression_codec() override
Creates a block compression codec suitable for decompressing the cell store's blocks.
Definition: CellStoreV3.cc:91
const char * row
Definition: Key.h:129
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.
static const char INDEX_VARIABLE_BLOCK_MAGIC[10]
Definition: CellStore.h:327
size_t get_items_actual()
Getter for the actual number of items.
Definition: BloomFilter.h:256
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
bool check_magic(const char *magic)
Compares a given character sequence with the magic field.
Definition: BlockHeader.h:86
void finalize(TableIdentifier *table_identifier) override
Finalizes the creation of a cell store, by writing block index and metadata trailer.
Definition: CellStoreV3.cc:435
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
BloomFilterMode m_bloom_filter_mode
Definition: CellStoreV3.h:161
std::shared_ptr< KeyCompressor > KeyCompressorPtr
Definition: KeyCompressor.h:45
size_t get_length_bits()
Getter for the number of bits.
Definition: BloomFilter.h:244
std::string m_start_row
Definition: CellList.h:99
KeyDecompressor * create_key_decompressor() override
Creates a key decompressor suitable for decompressing the keys stored in this cell store...
Definition: CellStoreV3.cc:96
void add_entry(KeyCompressorPtr &key_compressor, int64_t offset)
Definition: CellStoreV3.cc:606
long long unsigned int Llu
Shortcut for printf formats.
Definition: String.h:50
CellStoreV3(Filesystem *filesys)
Definition: CellStoreV3.cc:60
uint16_t block_header_format() override
Definition: CellStoreV3.cc:854
BlockCompressionCodec::Args m_compressor_args
Definition: CellStoreV3.h:159
Declarations for CellStoreScanner.
static void parse_bloom_filter(const std::string &spec, PropertiesPtr &props)
Parsers a bloom filter specification and sets properties.
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.
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.
bool has(const String &name)
Check existence of a configuration value.
Definition: Config.h:57
void create_bloom_filter(bool is_approx=false)
Definition: CellStoreV3.cc:214
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
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
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
uint32_t m_outstanding_appends
Definition: CellStoreV3.h:150
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.
Compatibility Macros for C/C++.
BasicBloomFilter BloomFilter
Definition: BloomFilter.h:284
IndexBuilder m_index_builder
Definition: CellStoreV3.h:148
void encode_i64(uint8_t **bufp, uint64_t val)
Encode a 64-bit integer in little-endian order.
#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
Time related declarations.
virtual void serialize(uint8_t *buf)
Serializes this trailer to the given buffer;.
bool may_contain(const void *key, size_t len) const
Checks if the data set "may" contain the key.
Definition: BloomFilter.h:188
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: CellStoreV3.cc:664
#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
Hypertable definitions
long long int Lld
Shortcut for printf formats.
Definition: String.h:53
int64_t m_uncompressed_blocksize
Definition: CellStoreV3.h:158
uint64_t purge_indexes() override
Purges bloom filter and block indexes.
Definition: CellStoreV3.cc:306
void load(DynamicBuffer &fixed, DynamicBuffer &variable, int64_t end_of_data, const String &start_row="", const String &end_row="")
void clear()
Clears the buffer.
Declarations for BlockHeaderCellStore.
CellStoreTrailerV3 m_trailer
Definition: CellStoreV3.h:145
void add(const Key &key, const ByteString value) override
Inserts a key/value pair into the cell list.
Definition: CellStoreV3.cc:332
BlobHashSet BloomFilterItems
Definition: CellStoreV3.h:136
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
DynamicBuffer m_buffer
Definition: CellStoreV3.h:147
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.
virtual size_t size()
Returns the serialized size of the trailer.
static const char DATA_BLOCK_MAGIC[10]
Definition: CellStore.h:325
CellStoreBlockIndexArray< int64_t > m_index_map64
Definition: CellStoreV3.h:143
Request/response message event.
Definition: Event.h:63
void subtract(int64_t amount)
Subtract to memory used.
Definition: MemoryTracker.h:60
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
CellStoreBlockIndexArray< uint32_t > m_index_map32
Definition: CellStoreV3.h:142
BloomFilterItems * m_bloom_filter_items
Definition: CellStoreV3.h:163
DispatchHandlerSynchronizer m_sync_handler
Definition: CellStoreV3.h:149
void display_block_info() override
Displays block information to stdout.
Definition: CellStoreV3.cc:844
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
uint8_t column_family_code
Definition: Key.h:127
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.
std::vector< ColumnFamilySpec * > ColumnFamilySpecs
Vector of ColumnFamilySpec pointers.
void create(const char *fname, size_t max_entries, PropertiesPtr &props, const TableIdentifier *table_id=0) override
Creates a new cell store.
Definition: CellStoreV3.cc:117
#define HT_WARN(msg)
Definition: Logger.h:289
BloomFilter * m_bloom_filter
Definition: CellStoreV3.h:162
CellListScannerPtr create_scanner(ScanContext *scan_ctx) override
Creates a scanner on this cell list.
Definition: CellStoreV3.cc:101
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
virtual void clear()
Clears the contents of this trailer;.
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.
KeyCompressorPtr m_key_compressor
Definition: CellStoreV3.h:167
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
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