25 #include <boost/algorithm/string.hpp>
26 #include <boost/scoped_array.hpp>
55 const uint32_t MAX_APPENDS_OUTSTANDING = 3;
56 const uint16_t BLOCK_HEADER_FORMAT = 0;
61 : m_filesys(filesys) {
63 assert(
sizeof(
float) == 4);
67 : m_filesys(filesys), m_schema(schema) {
69 assert(
sizeof(
float) == 4);
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);
119 int32_t replication = props->get_i32(
"replication", int32_t(-1));
120 int64_t blocksize = props->get(
"blocksize", 0);
127 if (replication == -1 &&
Config::has(
"Hypertable.RangeServer.CellStore.DefaultReplication"))
128 replication = Config::get_i32(
"Hypertable.RangeServer.CellStore.DefaultReplication");
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")) {
139 ".CellStore.DefaultBloomFilter"), props);
162 for (
size_t i=0; i<column_family_specs.size(); i++) {
163 if (column_family_specs[i]->get_option_ttl()) {
168 m_column_ttl[ column_family_specs[i]->get_id() ] = column_family_specs[i]->get_option_ttl() * 1000000000LL;
190 bool has_num_hashes = props->has(
"num-hashes");
191 bool has_bits_per_item = props->has(
"bits-per-item");
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");
209 <<
" max-approx-items="<< m_max_approx_items <<
" false-positive="
217 HT_DEBUG_OUT <<
"Creating new BloomFilter for CellStore '"
218 <<
m_filename <<
"' for "<< (is_approx ?
"estimated " :
"")
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;
235 for (
const auto &blob : *m_bloom_filter_items)
236 m_bloom_filter->insert(blob.start, blob.size);
238 delete m_bloom_filter_items;
239 m_bloom_filter_items = 0;
241 HT_DEBUG_OUT <<
"Created new BloomFilter for CellStore '"
242 << m_filename <<
"'"<<
HT_END;
246 void CellStoreV3::load_bloom_filter() {
261 HT_FATAL_OUT <<
"Error loading BloomFilter for CellStore '"
263 <<
" items -"<< e <<
HT_END;
272 bool second_try =
false;
292 "CellStore '%s' : tried to read %lld but only got %lld",
307 uint64_t memory_purged = 0;
327 return memory_purged;
364 "Problem writing to FS file '%s' : %s",
m_filename.c_str(),
367 "Problem writing to FS file '%s'",
m_filename.c_str());
372 size_t zlen = zbuf.
fill();
388 size_t value_len = value.
length();
405 m_bloom_filter_items->insert(key.
row, key.
row_len);
408 m_bloom_filter_items->insert(key.
row, key.
row_len + 2);
414 HT_INFOF(
"max_entries = %lld, max_approx_items = %lld, bloom_filter_items_size = %lld",
441 int64_t index_memory = 0;
458 "Problem finalizing CellStore file '%s' : %s",
525 if (m_bloom_filter_items && m_bloom_filter_items->size() > 0) {
610 if (!
m_bigint && offset >= 4294967296LL) {
613 uint8_t *dst = tmp_buf.
base;
627 size_t key_len = key_compressor->length_uncompressed();
650 base = m_fixed.release(&len);
651 m_fixed.reserve(len);
652 m_fixed.add_unchecked(base, len);
655 base = m_variable.release(&len);
656 m_variable.reserve(len);
657 m_variable.add_unchecked(base, len);
665 const String &end_row, int32_t fd, int64_t file_length,
688 "Bad index offsets in CellStore trailer fix=%lld, var=%lld, "
696 int64_t amount, index_amount;
700 bool inflating_fixed=
true;
701 bool second_try =
false;
720 "CellStore '%s' : tried to read %lld but only got %lld",
728 inflating_fixed =
false;
737 vbuf.
ptr = buf.
ptr + amount;
748 if (inflating_fixed) {
749 msg =
String(
"Error inflating FIXED index for cellstore '")
754 msg =
"Error inflating VARIABLE index for cellstore '" +
m_filename +
"'";
758 << index_amount <<
")\n" <<
HT_END;
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);
813 uint8_t column_family_id = schema->get_column_family(col)->get_id();
814 rowcol[rowlen + 1] = column_family_id;
822 HT_ASSERT(!
"unpossible bloom filter mode!");
855 return BLOCK_HEADER_FORMAT;
void free()
Frees resources.
BlockCompressionCodec * m_compressor
uint64_t bloom_filter_access_counter
size_t get_num_hashes()
Getter for the number of hash functions.
static const char INDEX_FIXED_BLOCK_MAGIC[10]
#define HT_THROW2F(_code_, _ex_, _fmt_,...)
bool may_contain(const void *ptr, size_t len)
A memory buffer of static size.
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.
BlockCompressionCodec * create_block_compression_codec() override
Creates a block compression codec suitable for decompressing the cell store's blocks.
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]
size_t get_items_actual()
Getter for the actual number of items.
static int32_t response_code(const Event *event)
Returns the response code from an event event generated in response to a request message.
PropertiesPtr properties
This singleton map stores all options.
std::string String
A String is simply a typedef to std::string.
float m_filter_false_positive_prob
void finalize(TableIdentifier *table_identifier) override
Finalizes the creation of a cell store, by writing block index and metadata trailer.
static String string_format_message(const Event *event)
Returns error message decoded standard error MESSAGE generated in response to a request message...
String format(const char *fmt,...)
Returns a String using printf like format facilities Vanilla snprintf is about 1.5x faster than this...
BloomFilterMode m_bloom_filter_mode
std::shared_ptr< KeyCompressor > KeyCompressorPtr
size_t get_length_bits()
Getter for the number of bits.
uint16_t key_compression_scheme
KeyDecompressor * create_key_decompressor() override
Creates a key decompressor suitable for decompressing the keys stored in this cell store...
void add_entry(KeyCompressorPtr &key_compressor, int64_t offset)
long long unsigned int Llu
Shortcut for printf formats.
CellStoreV3(Filesystem *filesys)
uint16_t block_header_format() override
BlockCompressionCodec::Args m_compressor_args
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.
Scan context information.
uint8_t * ptr()
Getter for the bloom filter data.
uint32_t table_generation
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.
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.
void create_bloom_filter(bool is_approx=false)
A class managing one or more serializable ByteStrings.
int64_t filter_items_actual
IndexMemoryStats m_index_stats
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
uint64_t block_index_access_counter
int64_t m_max_approx_items
size_t size()
Getter for the bloom filter size.
static uint64_t access_counter
uint32_t m_outstanding_appends
std::shared_ptr< Properties > PropertiesPtr
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++.
float m_bloom_bits_per_item
BasicBloomFilter BloomFilter
int64_t block_index_memory
IndexBuilder m_index_builder
void encode_i64(uint8_t **bufp, uint64_t val)
Encode a 64-bit integer in little-endian order.
static const int64_t TIMESTAMP_NULL
uint8_t bloom_filter_hash_count
size_t length() const
Retrieves the length of the serialized string.
static BlockCompressionCodec * create_block_codec(BlockCompressionCodec::Type, const BlockCompressionCodec::Args &args=BlockCompressionCodec::Args())
uint16_t compression_type
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.
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.
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.
long long int Lld
Shortcut for printf formats.
int64_t m_uncompressed_blocksize
uint64_t purge_indexes() override
Purges bloom filter and block indexes.
void load(DynamicBuffer &fixed, DynamicBuffer &variable, int64_t end_of_data, const String &start_row="", const String &end_row="")
void clear()
Clears the buffer.
CellStoreTrailerV3 m_trailer
void add(const Key &key, const ByteString value) override
Inserts a key/value pair into the cell list.
BlobHashSet BloomFilterItems
Declarations for Protocol.
#define HT_INFOF(msg,...)
#define HT_THROWF(_code_, _fmt_,...)
DynamicBuffer & variable_buf()
Provides access to internal components of opaque key.
uint8_t * base
Pointer to the allocated memory buffer.
size_t fill() const
Returns the size of the used portion.
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]
DynamicBuffer & fixed_buf()
CellStoreBlockIndexArray< int64_t > m_index_map64
Request/response message event.
void subtract(int64_t amount)
Subtract to memory used.
void serialize(StaticBuffer &buf)
Serializes the BloomFilter into a static memory buffer.
This is a generic exception class for Hypertable.
CellStoreBlockIndexArray< uint32_t > m_index_map32
BloomFilterItems * m_bloom_filter_items
DispatchHandlerSynchronizer m_sync_handler
void display_block_info() override
Displays block information to stdout.
int64_t filter_items_estimate
uint8_t * release(size_t *lenp=0)
Moves ownership of the buffer to the caller.
std::shared_ptr< Schema > SchemaPtr
Smart pointer to Schema.
uint8_t column_family_code
std::shared_ptr< CellListScanner > CellListScannerPtr
void insert(const void *key, size_t len)
Inserts a new blob into the hash.
float m_uncompressed_data
uint8_t bloom_filter_mode
virtual void open(const String &name, uint32_t flags, DispatchHandler *handler)=0
Opens a file asynchronously.
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.
int64_t bloom_filter_memory
BloomFilter * m_bloom_filter
CellListScannerPtr create_scanner(ScanContext *scan_ctx) override
Creates a scanner on this cell list.
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_)
static const char * END_ROW_MARKER
void add(int64_t amount)
Add to memory used.
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...
static int get_next_file_id()
uint8_t * add_unchecked(const void *data, size_t len)
Adds additional data without boundary checks.
KeyCompressorPtr m_key_compressor
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.
int64_t get_ts64()
Returns the current time in nanoseconds as a 64bit number.
Abstract base class for block compression codecs.
Abstract base class for a filesystem.
int code() const
Returns the error code.
void reserve(size_t len, bool nocopy=false)
Reserve space for additional data Will grow the space to exactly what's needed.
#define HT_THROW2(_code_, _ex_, _msg_)