0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
CellStoreV4.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 "CellStoreV4.h"
42 #include "CellStoreTrailerV4.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 CellStoreV4::CellStoreV4(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 
72 
74  try {
75  delete m_compressor;
76  delete m_bloom_filter;
77  delete m_bloom_filter_items;
78  if (m_fd != -1)
80  delete [] m_column_ttl;
81  }
82  catch (Exception &e) {
83  HT_ERROR_OUT << e << HT_END;
84  }
85 
88 
89 }
90 
91 
95 }
96 
98  return new KeyDecompressorPrefix();
99 }
100 
101 
103  bool need_index = m_restricted_range || scan_ctx->restricted_range || scan_ctx->single_row;
104 
105  if (need_index) {
109  }
110 
111  if (m_64bit_index)
112  return make_shared<CellStoreScanner<CellStoreBlockIndexArray<int64_t>>>(shared_from_this(), scan_ctx, need_index ? &m_index_map64 : 0);
113  return make_shared<CellStoreScanner<CellStoreBlockIndexArray<uint32_t>>>(shared_from_this(), scan_ctx, need_index ? &m_index_map32 : 0);
114 }
115 
116 
117 void
118 CellStoreV4::create(const char *fname, size_t max_entries,
119  PropertiesPtr &props, const TableIdentifier *table_id) {
120  int32_t replication = props->get_i32("replication", int32_t(-1));
121  int64_t blocksize = props->get("blocksize", 0);
122  String compressor = props->get("compressor", String());
123 
124  m_key_compressor = make_shared<KeyCompressorPrefix>();
125 
126  assert(Config::properties); // requires Config::init* first
127 
128  if (replication == -1 && Config::has("Hypertable.RangeServer.CellStore.DefaultReplication"))
129  replication = Config::get_i32("Hypertable.RangeServer.CellStore.DefaultReplication");
130 
131  if (blocksize == 0)
132  blocksize = Config::get_i32("Hypertable.RangeServer.CellStore"
133  ".DefaultBlockSize");
134  if (compressor.empty())
135  compressor = Config::get_str("Hypertable.RangeServer.CellStore"
136  ".DefaultCompressor");
137  if (!props->has("bloom-filter-mode")) {
138  // probably not called from AccessGroup
139  AccessGroupOptions::parse_bloom_filter(Config::get_str("Hypertable.RangeServer"
140  ".CellStore.DefaultBloomFilter"), props);
141  }
142 
143  m_buffer.reserve(blocksize*4);
144 
145  m_max_entries = max_entries;
146 
147  m_fd = -1;
148  m_offset = 0;
149 
151  m_index_builder.variable_buf().reserve(1024*1024);
152 
153  m_uncompressed_data = 0.0;
154  m_compressed_data = 0.0;
155 
156  m_trailer.clear();
157  m_trailer.blocksize = blocksize;
158  m_uncompressed_blocksize = blocksize;
159 
160  // set up the "column_ttl" vector
162  ColumnFamilySpecs &column_family_specs = m_schema->get_column_families();
163  for (size_t i=0; i<column_family_specs.size(); i++) {
164  if (column_family_specs[i]->get_option_ttl()) {
165  if (m_column_ttl == 0) {
166  m_column_ttl = new int64_t[256];
167  memset(m_column_ttl, 0, 256*8);
168  }
169  m_column_ttl[ column_family_specs[i]->get_id() ] = column_family_specs[i]->get_option_ttl() * 1000000000LL;
170  }
171  }
172 
173  m_filename = fname;
174 
175  m_start_row = "";
177 
179  compressor, m_compressor_args);
180 
184 
186  m_fd = m_filesys->create(m_filename, oflags, -1, -1, -1);
187 
188  m_bloom_filter_mode = props->get<BloomFilterMode>("bloom-filter-mode");
189  m_max_approx_items = props->get_i32("max-approx-items");
190 
192  bool has_num_hashes = props->has("num-hashes");
193  bool has_bits_per_item = props->has("bits-per-item");
194 
195  if (has_num_hashes || has_bits_per_item) {
196  if (!(has_num_hashes && has_bits_per_item)) {
197  HT_WARN("Bloom filter option --bits-per-item must be used with "
198  "--num-hashes, defaulting to false probability of 0.01");
200  }
201  else {
202  m_trailer.bloom_filter_hash_count = props->get_i32("num-hashes");
203  m_bloom_bits_per_item = props->get_f64("bits-per-item");
204  }
205  }
206  else
207  m_filter_false_positive_prob = props->get_f64("false-positive");
208  m_bloom_filter_items = new BloomFilterItems(); // aproximator items
209  }
210  HT_DEBUG_OUT <<"bloom-filter-mode="<< m_bloom_filter_mode
211  <<" max-approx-items="<< m_max_approx_items <<" false-positive="
213 }
214 
215 
216 void CellStoreV4::create_bloom_filter(bool is_approx) {
218 
219  HT_DEBUG_OUT << "Creating new BloomFilter for CellStore '"
220  << m_filename <<"' for "<< (is_approx ? "estimated " : "")
221  << m_trailer.filter_items_estimate << " items"<< HT_END;
222  try {
223  if (m_filter_false_positive_prob != 0.0)
226  else
230  }
231  catch(Exception &e) {
232  HT_FATAL_OUT << "Error creating new BloomFilter for CellStore '"
233  << m_filename <<"' for "<< (is_approx ? "estimated " : "")
234  << m_trailer.filter_items_estimate << " items - "<< e << HT_END;
235  }
236 
237  for (const auto &blob : *m_bloom_filter_items)
238  m_bloom_filter->insert(blob.start, blob.size);
239 
240  delete m_bloom_filter_items;
241  m_bloom_filter_items = 0;
242 
243  HT_DEBUG_OUT << "Created new BloomFilter for CellStore '"
244  << m_filename <<"'"<< HT_END;
245 }
246 
247 
248 void CellStoreV4::load_bloom_filter() {
249  size_t len;
250 
252 
253  HT_DEBUG_OUT << "Loading BloomFilter for CellStore '"
255  << " items"<< HT_END;
256  try {
261  }
262  catch(Exception &e) {
263  HT_FATAL_OUT << "Error loading BloomFilter for CellStore '"
265  << " items -"<< e << HT_END;
266  }
267 
268  if (m_bloom_filter->total_size() > 0) {
269 
270  bool second_try = false;
271 
272  while (true) {
273  try {
275  m_trailer.filter_offset, second_try);
276  }
277  catch (Exception &e) {
278  if (!second_try) {
279  second_try=true;
280  continue;
281  }
282  HT_THROW2(e.code(), e, format("Error loading BloomFilter for CellStore '%s'",
283  m_filename.c_str()));
284  }
285  break;
286  }
287 
288  if (len != m_bloom_filter->total_size())
289  HT_THROWF(Error::FSBROKER_IO_ERROR, "Problem loading bloomfilter for"
290  "CellStore '%s' : tried to read %lld but only got %lld",
291  m_filename.c_str(), (Lld)m_bloom_filter->total_size(), (Lld)len);
292 
293  m_bytes_read += len;
294 
296  }
297 
300 
301 }
302 
303 
304 
306  uint64_t memory_purged = 0;
307 
309  memory_purged = m_index_stats.bloom_filter_memory;
310  delete m_bloom_filter;
311  m_bloom_filter = 0;
314  }
315 
317  memory_purged += m_index_stats.block_index_memory;
318  if (m_64bit_index)
320  else
324  }
325 
326  return memory_purged;
327 }
328 
329 
330 
331 void CellStoreV4::add(const Key &key, const ByteString value) {
332  EventPtr event_ptr;
333  DynamicBuffer zbuf;
334 
335  if (key.revision > m_trailer.revision)
337 
338  if (key.timestamp != TIMESTAMP_NULL) {
341  else if (key.timestamp > m_trailer.timestamp_max)
343  }
344 
345  if (m_buffer.fill() > (size_t)m_uncompressed_blocksize) {
346  BlockHeaderCellStore header(BLOCK_HEADER_FORMAT, DATA_BLOCK_MAGIC);
347 
349 
350  m_uncompressed_data += (float)m_buffer.fill();
352  m_compressed_data += (float)zbuf.fill();
353  m_buffer.clear();
354 
355  uint64_t llval = ((uint64_t)m_trailer.blocksize
356  * (uint64_t)m_uncompressed_data) / (uint64_t)m_compressed_data;
357  m_uncompressed_blocksize = (int64_t)llval;
358 
359  if (m_outstanding_appends >= MAX_APPENDS_OUTSTANDING) {
360  if (!m_sync_handler.wait_for_reply(event_ptr)) {
361  if (event_ptr->type == Event::MESSAGE)
363  "Problem writing to FS file '%s' : %s", m_filename.c_str(),
365  HT_THROWF(event_ptr->error,
366  "Problem writing to FS file '%s'", m_filename.c_str());
367  }
369  }
370 
371  if (!HT_IO_ALIGNED(zbuf.fill())) {
372  memset(zbuf.ptr, 0, HT_IO_ALIGNMENT_PADDING(zbuf.fill()));
373  zbuf.ptr += HT_IO_ALIGNMENT_PADDING(zbuf.fill());
374  }
375 
376  size_t zlen = zbuf.fill();
377  StaticBuffer send_buf(zbuf);
378 
380  catch (Exception &e) {
381  HT_THROW2F(e.code(), e, "Problem writing to FS file '%s'",
382  m_filename.c_str());
383  }
385  m_offset += zlen;
386  m_key_compressor->reset();
387  }
388 
389  m_key_compressor->add(key);
390 
391  size_t key_len = m_key_compressor->length();
392  size_t value_len = value.length();
393 
394  if (m_column_ttl && m_column_ttl[key.column_family_code] != 0) {
395  m_trailer.expirable_data += key_len + value_len;
398  }
399 
400  m_buffer.ensure(key_len + value_len);
401 
402  m_key_compressor->write(m_buffer.ptr);
403  m_buffer.ptr += key_len;
404 
405  m_buffer.add_unchecked(value.ptr, value_len);
406 
409  m_bloom_filter_items->insert(key.row, key.row_len);
410 
412  m_bloom_filter_items->insert(key.row, key.row_len + 2);
413 
415  m_trailer.filter_items_estimate = (size_t)(((double)m_max_entries
416  / (double)m_max_approx_items) * m_bloom_filter_items->size());
417  if (m_trailer.filter_items_estimate == 0) {
418  HT_INFOF("max_entries = %lld, max_approx_items = %lld, bloom_filter_items_size = %lld",
419  (Lld)m_max_entries, (Lld)m_max_approx_items, (Lld)m_bloom_filter_items->size());
421  }
422  create_bloom_filter(true);
423  }
424  }
425  else {
426  assert(!m_bloom_filter_items && m_bloom_filter);
427 
428  m_bloom_filter->insert(key.row);
429 
431  m_bloom_filter->insert(key.row, key.row_len + 2);
432  }
433  }
434 
436 }
437 
438 
439 void CellStoreV4::finalize(TableIdentifier *table_identifier) {
440  EventPtr event_ptr;
441  size_t zlen;
442  DynamicBuffer zbuf(0);
443  SerializedKey key;
444  StaticBuffer send_buf;
445  int64_t index_memory = 0;
446 
447  if (m_buffer.fill() > 0) {
448  BlockHeaderCellStore header(BLOCK_HEADER_FORMAT, DATA_BLOCK_MAGIC);
449 
451 
452  m_uncompressed_data += (float)m_buffer.fill();
454  m_compressed_data += (float)zbuf.fill();
455 
456  if (!HT_IO_ALIGNED(zbuf.fill())) {
457  memset(zbuf.ptr, 0, HT_IO_ALIGNMENT_PADDING(zbuf.fill()));
458  zbuf.ptr += HT_IO_ALIGNMENT_PADDING(zbuf.fill());
459  }
460  zlen = zbuf.fill();
461  send_buf = zbuf;
462 
463  if (m_outstanding_appends >= MAX_APPENDS_OUTSTANDING) {
464  if (!m_sync_handler.wait_for_reply(event_ptr))
466  "Problem finalizing CellStore file '%s' : %s",
467  m_filename.c_str(),
468  Protocol::string_format_message(event_ptr).c_str());
470  }
471 
473 
475  m_offset += zlen;
476  }
477 
478  m_buffer.free();
479 
481  if (m_uncompressed_data == 0)
483  else
485 
487 
492 
496  {
497  BlockHeaderCellStore header(BLOCK_HEADER_FORMAT, INDEX_FIXED_BLOCK_MAGIC);
499  }
500 
501  if (!HT_IO_ALIGNED(zbuf.fill())) {
502  memset(zbuf.ptr, 0, HT_IO_ALIGNMENT_PADDING(zbuf.fill()));
503  zbuf.ptr += HT_IO_ALIGNMENT_PADDING(zbuf.fill());
504  }
505  zlen = zbuf.fill();
506  send_buf = zbuf;
507 
509 
511  m_offset += zlen;
512 
516  {
517  BlockHeaderCellStore header(BLOCK_HEADER_FORMAT, INDEX_VARIABLE_BLOCK_MAGIC);
520  }
521 
522  if (!HT_IO_ALIGNED(zbuf.fill())) {
523  memset(zbuf.ptr, 0, HT_IO_ALIGNMENT_PADDING(zbuf.fill()));
524  zbuf.ptr += HT_IO_ALIGNMENT_PADDING(zbuf.fill());
525  }
526  zlen = zbuf.fill();
527  send_buf = zbuf;
528 
530 
532  m_offset += zlen;
533 
534  // write filter_offset
536 
537  // if bloom_items haven't been spilled to create a bloom filter yet, do it
540 
541  if (m_bloom_filter_items && m_bloom_filter_items->size() > 0) {
542  m_trailer.filter_items_estimate = m_bloom_filter_items->size();
544  }
545 
546  if (m_bloom_filter) {
551  m_bloom_filter->serialize(send_buf);
555  }
556  }
557 
559 
561  if (m_64bit_index) {
566  index_memory = m_index_map64.memory_used();
568  }
569  else {
574  index_memory = m_index_map32.memory_used();
575  }
576 
577  // deallocate fix index data
579 
580  // Add table information
581  m_trailer.table_id = table_identifier->index();
582  m_trailer.table_generation = table_identifier->generation;
584 
585  // write trailer
586  zbuf.clear();
589  memset(zbuf.base, 0, HT_DIRECT_IO_ALIGNMENT);
590  zbuf.ptr = zbuf.base + (HT_DIRECT_IO_ALIGNMENT-m_trailer.size());
591  m_trailer.serialize(zbuf.ptr);
592  zbuf.ptr += m_trailer.size();
593 
594  zlen = zbuf.fill();
595  send_buf = zbuf;
596 
597  m_filesys->append(m_fd, send_buf);
598 
600  m_offset += zlen;
601 
603  m_filesys->close(m_fd);
604 
607 
610 
611  // If compacting due to a split, estimate the disk usage at 1/2
614  else
616 
617  m_index_stats.block_index_memory = sizeof(CellStoreV4) + index_memory;
618 
619  if (m_bloom_filter)
621 
622  delete [] m_column_ttl;
623  m_column_ttl = 0;
624 
626 }
627 
628 
630  int64_t offset) {
631 
632  // switch to 64-bit offsets if offset being added is >= 2^32
633  if (!m_bigint && offset >= 4294967296LL) {
634  DynamicBuffer tmp_buf(m_fixed.size*2);
635  const uint8_t *src = m_fixed.base;
636  uint8_t *dst = tmp_buf.base;
637  size_t remaining = m_fixed.fill();
638  while (src < m_fixed.ptr)
639  Serialization::encode_i64(&dst, (uint64_t)Serialization::decode_i32(&src, &remaining));
640  delete [] m_fixed.release();
641  m_fixed.base = tmp_buf.base;
642  m_fixed.ptr = dst;
643  m_fixed.size = tmp_buf.size;
644  m_fixed.own = true;
645  tmp_buf.release();
646  m_bigint = true;
647  }
648 
649  // Add key to variable buffer
650  size_t key_len = key_compressor->length_uncompressed();
651  m_variable.ensure(key_len);
652  key_compressor->write_uncompressed(m_variable.ptr);
653  m_variable.ptr += key_len;
654 
655  // Serialize offset into fix index buffer
656  if (m_bigint) {
657  m_fixed.ensure(8);
658  memcpy(m_fixed.ptr, &offset, 8);
659  m_fixed.ptr += 8;
660  }
661  else {
662  m_fixed.ensure(4);
663  memcpy(m_fixed.ptr, &offset, 4);
664  m_fixed.ptr += 4;
665  }
666 }
667 
668 
670  uint8_t *base;
671  size_t len;
672 
673  base = m_fixed.release(&len);
674  m_fixed.reserve(len);
675  m_fixed.add_unchecked(base, len);
676  delete [] base;
677 
678  base = m_variable.release(&len);
679  m_variable.reserve(len);
680  m_variable.add_unchecked(base, len);
681  delete [] base;
682 }
683 
684 
685 
686 void
687 CellStoreV4::open(const String &fname, const String &start_row,
688  const String &end_row, int32_t fd, int64_t file_length,
689  CellStoreTrailer *trailer) {
690  m_filename = fname;
691  m_start_row = start_row;
692  m_end_row = end_row;
693  m_fd = fd;
694  m_file_length = file_length;
695 
697 
698  m_trailer = *static_cast<CellStoreTrailerV4 *>(trailer);
699 
700  // If compacting due to a split, estimate the disk usage at 1/2
703  else
705 
707 
710 
712  m_64bit_index = true;
713 
717  "Bad index offsets in CellStore trailer fd=%u fix=%lld, var=%lld, "
718  "length=%llu, file='%s'", (unsigned)m_fd, (Lld)m_trailer.fix_index_offset,
719  (Lld)m_trailer.var_index_offset, (Llu)m_file_length, fname.c_str());
720 
721 }
722 
723 
725  int64_t amount, index_amount;
726  int64_t len = 0;
727  BlockHeaderCellStore header(BLOCK_HEADER_FORMAT);
728  SerializedKey key;
729  bool inflating_fixed=true;
730  bool second_try = false;
731 
733 
734  if (m_compressor == 0)
736 
737  amount = index_amount = m_trailer.filter_offset - m_trailer.fix_index_offset;
738 
739  try_again:
740 
741  try {
742  DynamicBuffer buf(amount);
743 
745  len = m_filesys->pread(m_fd, buf.ptr, amount, m_trailer.fix_index_offset, second_try);
746 
747  if (len != amount)
748  HT_THROWF(Error::FSBROKER_IO_ERROR, "Error loading index for "
749  "CellStore '%s' : tried to read %lld but only got %lld",
750  m_filename.c_str(), (Lld)amount, (Lld)len);
754 
756 
757  inflating_fixed = false;
758 
761 
763  DynamicBuffer vbuf(0, false);
765  vbuf.base = buf.ptr;
766  vbuf.ptr = buf.ptr + amount;
767 
769 
771 
774  }
775  catch (Exception &e) {
776  String msg;
777  if (inflating_fixed) {
778  msg = String("Error inflating FIXED index for cellstore '")
779  + m_filename + "'";
780  HT_ERROR_OUT << msg << ": "<< e << HT_END;
781  }
782  else {
783  msg = "Error inflating VARIABLE index for cellstore '" + m_filename + "'";
784  HT_ERROR_OUT << msg << ": " << e << HT_END;
785  }
786  HT_ERROR_OUT << "pread(fd=" << m_fd << ", len=" << len << ", amount="
787  << index_amount << ")\n" << HT_END;
789  if (second_try)
790  HT_THROW2(e.code(), e, msg);
791  second_try = true;
792  goto try_again;
793  }
794 
796  if (m_64bit_index) {
800  }
801  else {
805  }
806 
809 
811 
812 }
813 
814 
816 
818  return true;
819  else if (m_trailer.filter_length == 0) // bloom filter is empty
820  return false;
821  else if (m_bloom_filter == 0)
823 
825 
826  switch (m_bloom_filter_mode) {
827  case BLOOM_FILTER_ROWS:
828  return may_contain(scan_ctx->start_row);
830  if (may_contain(scan_ctx->start_row)) {
831  SchemaPtr &schema = scan_ctx->schema;
832  size_t rowlen = scan_ctx->start_row.length();
833  boost::scoped_array<char> rowcol(new char[rowlen + 2]);
834  memcpy(rowcol.get(), scan_ctx->start_row.c_str(), rowlen + 1);
835 
836  for (auto col : scan_ctx->spec->columns) {
837  uint8_t column_family_id = schema->get_column_family(col)->get_id();
838  rowcol[rowlen + 1] = column_family_id;
839 
840  if (may_contain(rowcol.get(), rowlen + 2))
841  return true;
842  }
843  }
844  return false;
845  default:
846  HT_ASSERT(!"unpossible bloom filter mode!");
847  }
848  return false; // silence stupid compilers
849 }
850 
851 
852 bool CellStoreV4::may_contain(const void *ptr, size_t len) {
853 
855  return true;
856  else if (m_trailer.filter_length == 0) // bloom filter is empty
857  return false;
858  else if (m_bloom_filter == 0)
860 
862  bool may_contain = m_bloom_filter->may_contain(ptr, len);
863  return may_contain;
864 }
865 
866 
867 
871  if (m_64bit_index)
873  else
875 }
876 
877 
879  return BLOCK_HEADER_FORMAT;
880 }
size_t get_num_hashes()
Getter for the number of hash functions.
void free()
Frees resources.
size_t get_items_actual()
Getter for the actual number of items.
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 clear()
Clears the contents of this trailer;.
Filesystem * m_filesys
Definition: CellStoreV4.h:137
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
#define HT_IO_ALIGNMENT_PADDING(size)
Definition: Filesystem.h:54
const char * row
Definition: Key.h:129
void create_bloom_filter(bool is_approx=false)
Definition: CellStoreV4.cc:216
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
BloomFilterMode m_bloom_filter_mode
Definition: CellStoreV4.h:160
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
#define HT_IO_ALIGNED(size)
Definition: Filesystem.h:51
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
BlockCompressionCodec * m_compressor
Definition: CellStoreV4.h:145
std::shared_ptr< KeyCompressor > KeyCompressorPtr
Definition: KeyCompressor.h:45
std::string m_start_row
Definition: CellList.h:99
long long unsigned int Llu
Shortcut for printf formats.
Definition: String.h:50
KeyDecompressor * create_key_decompressor() override
Creates a key decompressor suitable for decompressing the keys stored in this cell store...
Definition: CellStoreV4.cc:97
DynamicBuffer m_buffer
Definition: CellStoreV4.h:146
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
BlockCompressionCodec::Args m_compressor_args
Definition: CellStoreV4.h:158
CellStoreBlockIndexArray< uint32_t > m_index_map32
Definition: CellStoreV4.h:141
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.
KeyCompressorPtr m_key_compressor
Definition: CellStoreV4.h:166
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
A class managing one or more serializable ByteStrings.
Definition: ByteString.h:47
#define HT_ASSERT(_e_)
Definition: Logger.h:396
virtual size_t size()
Returns the serialized size of the trailer.
uint32_t row_len
Definition: Key.h:131
void serialize(StaticBuffer &buf)
Serializes the BloomFilter into a static memory buffer.
IndexMemoryStats m_index_stats
Definition: CellStore.h:332
virtual void serialize(uint8_t *buf)
Serializes this trailer to the given buffer;.
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.
size_t total_size()
Getter for the total size (including checksum and metadata)
static Hypertable::MemoryTracker * memory_tracker
Definition: Global.h:94
const ScanSpec * spec
Definition: ScanContext.h:55
CellStoreBlockIndexArray< int64_t > m_index_map64
Definition: CellStoreV4.h:142
bool may_contain(const void *ptr, size_t len)
Definition: CellStoreV4.cc:852
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.
void add_entry(KeyCompressorPtr &key_compressor, int64_t offset)
Definition: CellStoreV4.cc:629
Compatibility Macros for C/C++.
void insert(const void *key, size_t len)
Inserts a new blob into the hash.
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
void add(const Key &key, const ByteString value) override
Inserts a key/value pair into the cell list.
Definition: CellStoreV4.cc:331
Time related declarations.
size_t get_length_bits()
Getter for the number of bits.
void create(const char *fname, size_t max_entries, PropertiesPtr &props, const TableIdentifier *table_id=0) override
Creates a new cell store.
Definition: CellStoreV4.cc:118
BloomFilterItems * m_bloom_filter_items
Definition: CellStoreV4.h:162
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
void finalize(TableIdentifier *table_identifier) override
Finalizes the creation of a cell store, by writing block index and metadata trailer.
Definition: CellStoreV4.cc:439
long long int Lld
Shortcut for printf formats.
Definition: String.h:53
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.
CellListScannerPtr create_scanner(ScanContext *scan_ctx) override
Creates a scanner on this cell list.
Definition: CellStoreV4.cc:102
uint32_t m_outstanding_appends
Definition: CellStoreV4.h:149
DispatchHandlerSynchronizer m_sync_handler
Definition: CellStoreV4.h:148
void validate(String &filename)
Validates the checksum of the BloomFilter.
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
uint8_t * base
Pointer to the allocated memory buffer.
CellStoreV4(Filesystem *filesys)
Definition: CellStoreV4.cc:60
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
This is a generic exception class for Hypertable.
Definition: Error.h:314
CellStoreTrailerV4 m_trailer
Definition: CellStoreV4.h:144
BlockCompressionCodec * create_block_compression_codec() override
Creates a block compression codec suitable for decompressing the cell store's blocks.
Definition: CellStoreV4.cc:92
uint64_t purge_indexes() override
Purges bloom filter and block indexes.
Definition: CellStoreV4.cc:305
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
BloomFilterWithChecksum * m_bloom_filter
Definition: CellStoreV4.h:161
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.
BasicBloomFilterWithChecksum BloomFilterWithChecksum
#define HT_WARN(msg)
Definition: Logger.h:289
BlobHashSet BloomFilterItems
Definition: CellStoreV4.h:135
void display_block_info() override
Displays block information to stdout.
Definition: CellStoreV4.cc:868
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
int64_t m_uncompressed_blocksize
Definition: CellStoreV4.h:157
void add(int64_t amount)
Add to memory used.
Definition: MemoryTracker.h:53
bool may_contain(const void *key, size_t len) const
Checks if the data set "may" contain the key.
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.
uint16_t block_header_format() override
Definition: CellStoreV4.cc:878
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
uint8_t * base()
Getter for the serialized bloom filter data, including metadata and checksums.
int64_t get_ts64()
Returns the current time in nanoseconds as a 64bit number.
Definition: Time.cc:40
#define HT_DIRECT_IO_ALIGNMENT
Definition: Filesystem.h:49
Abstract base class for block compression codecs.
Abstract base class for a filesystem.
Definition: Filesystem.h:72
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: CellStoreV4.cc:687
int code() const
Returns the error code.
Definition: Error.h:391
IndexBuilder m_index_builder
Definition: CellStoreV4.h:147
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