25 #include <boost/algorithm/string.hpp>
26 #include <boost/scoped_array.hpp>
58 const uint32_t MAX_APPENDS_OUTSTANDING = 3;
59 const uint16_t BLOCK_HEADER_FORMAT = 0;
64 : m_filesys(filesys) {
66 assert(
sizeof(
float) == 4);
70 : m_filesys(filesys), m_schema(schema) {
72 assert(
sizeof(
float) == 4);
126 return make_shared<CellStoreScanner<CellStoreBlockIndexArray<int64_t>>>(shared_from_this(), scan_ctx, need_index ? &
m_index_map64 : 0);
127 return make_shared<CellStoreScanner<CellStoreBlockIndexArray<uint32_t>>>(shared_from_this(), scan_ctx, need_index ? &
m_index_map32 : 0);
133 int32_t replication = props->get_i32(
"replication", int32_t(-1));
135 if (replication == -1 && table_id) {
137 if (
Config::has(
"Hypertable.RangeServer.Data.DefaultReplication"))
138 replication = Config::get_i32(
"Hypertable.RangeServer.Data.DefaultReplication");
140 else if (
Config::has(
"Hypertable.Metadata.Replication"))
141 replication = Config::get_i32(
"Hypertable.Metadata.Replication");
151 int64_t blocksize = props->get(
"blocksize", 0);
157 int32_t replication = get_replication(props, table_id);
160 blocksize = Config::get_i32(
"Hypertable.RangeServer.CellStore"
161 ".DefaultBlockSize");
162 if (compressor.empty())
163 compressor = Config::get_str(
"Hypertable.RangeServer.CellStore"
164 ".DefaultCompressor");
165 if (!props->has(
"bloom-filter-mode")) {
168 ".CellStore.DefaultBloomFilter"), props);
191 for (
size_t i=0; i<column_family_specs.size(); i++) {
192 if (column_family_specs[i]->get_option_ttl()) {
197 m_column_ttl[ column_family_specs[i]->get_id() ] = column_family_specs[i]->get_option_ttl() * 1000000000LL;
220 bool has_num_hashes = props->has(
"num-hashes");
221 bool has_bits_per_item = props->has(
"bits-per-item");
223 if (has_num_hashes || has_bits_per_item) {
224 if (!(has_num_hashes && has_bits_per_item)) {
225 HT_WARN(
"Bloom filter option --bits-per-item must be used with "
226 "--num-hashes, defaulting to false probability of 0.01");
239 <<
" max-approx-items="<< m_max_approx_items <<
" false-positive="
247 HT_DEBUG_OUT <<
"Creating new BloomFilter for CellStore '"
248 <<
m_filename <<
"' for "<< (is_approx ?
"estimated " :
"")
260 HT_FATAL_OUT <<
"Error creating new BloomFilter for CellStore '"
261 << m_filename <<
"' for "<< (is_approx ?
"estimated " :
"")
262 << m_trailer.filter_items_estimate <<
" items - "<< e <<
HT_END;
265 for (
const auto &blob : *m_bloom_filter_items)
266 m_bloom_filter->insert(blob.start, blob.size);
268 delete m_bloom_filter_items;
269 m_bloom_filter_items = 0;
271 HT_DEBUG_OUT <<
"Created new BloomFilter for CellStore '"
272 << m_filename <<
"'"<<
HT_END;
275 const std::vector<String> &CellStoreV5::get_replaced_files() {
282 bool second_try =
false;
296 "CellStore '%s' : tried to read %lld but only got %lld",
302 const uint8_t *ptr = buf.
base;
306 "Bad replaced_files_offset in CellStore trailer fd=%u replaced_files_offset=%lld, "
307 "length=%llu, entries=%u, file='%s'", (
unsigned)
m_fd,
310 ptr = decompressor.add(ptr);
311 decompressor.load(filename);
318 << amount <<
")\n" <<
HT_END;
343 HT_FATAL_OUT <<
"Error loading BloomFilter for CellStore '"
345 <<
" items -"<< e <<
HT_END;
350 bool second_try =
false;
370 "CellStore '%s' : tried to read %lld but only got %lld",
386 uint64_t memory_purged = 0;
406 return memory_purged;
443 "Problem writing to FS file '%s' : %s",
m_filename.c_str(),
446 "Problem writing to FS file '%s'",
m_filename.c_str());
456 size_t zlen = zbuf.
fill();
472 size_t value_len = value.
length();
495 m_bloom_filter_items->insert(key.
row, key.
row_len);
498 m_bloom_filter_items->insert(key.
row, key.
row_len + 2);
504 HT_INFOF(
"max_entries = %lld, max_approx_items = %lld, bloom_filter_items_size = %lld",
531 int64_t index_memory = 0;
552 "Problem finalizing CellStore file '%s' : %s",
632 if (m_bloom_filter_items && m_bloom_filter_items->size() > 0) {
652 size_t compressed_len = 0;
654 bool coalesce_with_trailer =
false;
657 compressed_len += compressor.
length();
661 coalesce_with_trailer =
true;
678 if (!coalesce_with_trailer) {
718 if (!coalesce_with_trailer) {
727 memset(zbuf.
ptr, 0, padding);
772 if (!
m_bigint && offset >= 4294967296LL) {
775 uint8_t *dst = tmp_buf.
base;
789 size_t key_len = key_compressor->length_uncompressed();
812 base = m_fixed.release(&len);
813 m_fixed.reserve(len);
814 m_fixed.add_unchecked(base, len);
817 base = m_variable.release(&len);
818 m_variable.reserve(len);
819 m_variable.add_unchecked(base, len);
827 const String &end_row, int32_t fd, int64_t file_length,
856 "Bad index offsets in CellStore trailer fd=%u fix=%lld, var=%lld, "
866 int64_t amount, index_amount;
870 bool inflating_fixed=
true;
871 bool second_try =
false;
889 "CellStore '%s' : tried to read %lld but only got %lld",
897 inflating_fixed =
false;
906 vbuf.
ptr = buf.
ptr + amount;
917 if (inflating_fixed) {
918 msg =
String(
"Error inflating FIXED index for cellstore '")
923 msg =
"Error inflating VARIABLE index for cellstore '" +
m_filename +
"'";
927 << index_amount <<
")\n" <<
HT_END;
972 size_t rowlen = scan_ctx->
start_row.length();
973 boost::scoped_array<char> rowcol(
new char[rowlen + 2]);
974 memcpy(rowcol.get(), scan_ctx->
start_row.c_str(), rowlen + 1);
977 uint8_t column_family_id = schema->get_column_family(col)->get_id();
978 rowcol[rowlen + 1] = column_family_id;
986 HT_ASSERT(!
"unpossible bloom filter mode!");
1019 return BLOCK_HEADER_FORMAT;
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.
DynamicBuffer & fixed_buf()
uint64_t bloom_filter_access_counter
float m_uncompressed_data
static const char INDEX_FIXED_BLOCK_MAGIC[10]
#define HT_THROW2F(_code_, _ex_, _fmt_,...)
A memory buffer of static size.
Retrieves system information (hardware, installation directory, etc)
void create_bloom_filter(bool is_approx=false)
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.
#define HT_IO_ALIGNMENT_PADDING(size)
#define HT_WARNF(msg,...)
void add(const Key &key, const ByteString value) override
Inserts a key/value pair into the cell list.
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.
BlockCompressionCodec * create_block_compression_codec() override
Creates a block compression codec suitable for decompressing the cell store's blocks.
void add_entry(KeyCompressorPtr &key_compressor, int64_t offset)
static const char INDEX_VARIABLE_BLOCK_MAGIC[10]
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.
#define HT_IO_ALIGNED(size)
uint8_t bloom_filter_mode
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...
float m_filter_false_positive_prob
CellStoreV5(Filesystem *filesys)
std::shared_ptr< KeyCompressor > KeyCompressorPtr
A class to decompress prefix-compressed strings.
long long unsigned int Llu
Shortcut for printf formats.
bool may_contain(const void *ptr, size_t len)
Declarations for CellStoreScanner.
int64_t m_max_approx_items
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.
void finalize(TableIdentifier *table_identifier) override
Finalizes the creation of a cell store, by writing block index and metadata trailer.
DispatchHandlerSynchronizer m_sync_handler
std::shared_ptr< Event > EventPtr
Smart pointer to Event.
BloomFilterItems * m_bloom_filter_items
Scan context information.
uint32_t table_generation
Type
Enumeration for compression type.
uint8_t * ptr
Pointer to the end of the used part of the buffer.
DynamicBuffer & variable_buf()
bool m_replaced_files_loaded
bool wait_for_reply(EventPtr &event)
This method is used by a client to synchronize.
A dynamic, resizable and reference counted memory buffer.
virtual void reset()
Clears the internal state.
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.
A class managing one or more serializable ByteStrings.
uint16_t compression_type
CellStoreTrailerV5 m_trailer
int64_t filter_items_actual
void serialize(StaticBuffer &buf)
Serializes the BloomFilter into a static memory buffer.
IndexMemoryStats m_index_stats
void display_block_info() override
Displays block information to stdout.
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)
virtual void serialize(uint8_t *buf)
Serializes this trailer to the given buffer;.
static Hypertable::MemoryTracker * memory_tracker
uint64_t block_index_access_counter
virtual size_t size()
Returns the serialized size of the trailer.
std::map< const char *, int64_t, LtCstr, SplitRowDataAlloc > SplitRowDataMapT
BloomFilterMode m_bloom_filter_mode
virtual void clear()
Clears the contents of this trailer;.
BlockCompressionCodec::Args m_compressor_args
int64_t filter_items_estimate
uint32_t m_outstanding_appends
static uint64_t access_counter
void load_replaced_files()
std::shared_ptr< Properties > PropertiesPtr
uint32_t size
The size of the allocated memory buffer (base)
Logging routines and macros.
KeyCompressorPtr m_key_compressor
BloomFilterMode
Enumeration for bloom filter modes.
CellListScannerPtr create_scanner(ScanContext *scan_ctx) override
Creates a scanner on this cell list.
uint32_t replaced_files_entries
Compatibility Macros for C/C++.
int64_t block_index_memory
uint16_t block_header_format() override
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.
static const int64_t TIMESTAMP_NULL
CellStoreBlockIndexArray< uint32_t > m_index_map32
size_t length() const
Retrieves the length of the serialized string.
static BlockCompressionCodec * create_block_codec(BlockCompressionCodec::Type, const BlockCompressionCodec::Args &args=BlockCompressionCodec::Args())
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.
Time related declarations.
size_t get_length_bits()
Getter for the number of bits.
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.
BlobHashSet BloomFilterItems
void split_row_estimate_data(SplitRowDataMapT &split_row_data) override
Populates split_row_data with unique row and count estimates from block index.
KeyDecompressor * create_key_decompressor() override
Creates a key decompressor suitable for decompressing the keys stored in this cell store...
long long int Lld
Shortcut for printf formats.
void load(DynamicBuffer &fixed, DynamicBuffer &variable, int64_t end_of_data, const String &start_row="", const String &end_row="")
void clear()
Clears the buffer.
std::vector< String > m_replaced_files
virtual void write(uint8_t *buf) const
Writes the compressed string to a buffer.
BloomFilterWithChecksum * m_bloom_filter
A class to decompress prefix-compressed strings.
void validate(String &filename)
Validates the checksum of the BloomFilter.
Declarations for Protocol.
#define HT_INFOF(msg,...)
virtual size_t length() const
Retrieves the length of the compressed string.
#define HT_THROWF(_code_, _fmt_,...)
BlockCompressionCodec * m_compressor
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.
static const char DATA_BLOCK_MAGIC[10]
Request/response message event.
void subtract(int64_t amount)
Subtract to memory used.
virtual void add(const char *str)
Adds (and compresses) a string.
This is a generic exception class for Hypertable.
uint64_t purge_indexes() override
Purges bloom filter and block indexes.
float m_bloom_bits_per_item
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
int64_t replaced_files_length
virtual void open(const String &name, uint32_t flags, DispatchHandler *handler)=0
Opens a file asynchronously.
std::vector< ColumnFamilySpec * > ColumnFamilySpecs
Vector of ColumnFamilySpec pointers.
IndexBuilder m_index_builder
CellStoreBlockIndexArray< int64_t > m_index_map64
A class to prefix-compress strings.
BasicBloomFilterWithChecksum BloomFilterWithChecksum
int64_t bloom_filter_memory
int64_t m_uncompressed_blocksize
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
int64_t replaced_files_offset
uint16_t key_compression_scheme
static const uint32_t FLAG_DELETE_CELL_VERSION
void add(int64_t amount)
Add to memory used.
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...
static int get_next_file_id()
uint8_t * add_unchecked(const void *data, size_t len)
Adds additional data without boundary checks.
A class to prefix-compress strings.
void unique_row_count_estimate(CellList::SplitRowDataMapT &split_row_data, int32_t keys_per_block)
Accumulates unique row estimates from block index entries.
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.
uint8_t bloom_filter_hash_count
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.
#define HT_DIRECT_IO_ALIGNMENT
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_)