25 #include <boost/algorithm/string.hpp>
26 #include <boost/scoped_array.hpp>
51 const uint32_t MAX_APPENDS_OUTSTANDING = 3;
52 const uint16_t BLOCK_HEADER_FORMAT = 0;
57 : m_filesys(filesys), m_fd(-1), m_filename(), m_compressor(0), m_buffer(0),
58 m_fix_index_buffer(0), m_var_index_buffer(0), m_memory_consumed(0),
59 m_outstanding_appends(0), m_offset(0), m_last_key(0), m_file_length(0),
60 m_disk_usage(0), m_file_id(0), m_uncompressed_blocksize(0),
62 m_bloom_filter_items(0) {
65 assert(
sizeof(
float) == 4);
97 return make_shared<CellStoreScanner<CellStoreBlockIndexArray<uint32_t>>>(shared_from_this(), scan_ctx, &
m_index_map32);
104 int32_t blocksize = props->get(
"blocksize", 0);
110 blocksize = Config::get_i32(
"Hypertable.RangeServer.CellStore"
111 ".DefaultBlockSize");
112 if (compressor.empty())
113 compressor = Config::get_str(
"Hypertable.RangeServer.CellStore"
114 ".DefaultCompressor");
115 if (!props->has(
"bloom-filter-mode")) {
118 ".CellStore.DefaultBloomFilter"), props);
160 <<
" max-approx-items="<< m_max_approx_items <<
" false-positive="
168 HT_DEBUG_OUT <<
"Creating new BloomFilter for CellStore '"
169 <<
m_filename <<
"' for "<< (is_approx ?
"estimated " :
"")
176 HT_FATAL_OUT <<
"Error creating new BloomFilter for CellStore '"
177 << m_filename <<
"' for "<< (is_approx ?
"estimated " :
"")
178 << m_trailer.num_filter_items <<
" items - "<< e <<
HT_END;
181 for (
const auto &blob : *m_bloom_filter_items)
182 m_bloom_filter->insert(blob.start, blob.size);
184 delete m_bloom_filter_items;
185 m_bloom_filter_items = 0;
187 HT_DEBUG_OUT <<
"Created new BloomFilter for CellStore '"
188 << m_filename <<
"'"<<
HT_END;
217 "Problem writing to FS file '%s' : %s",
m_filename.c_str(),
220 "Problem writing to FS file '%s'",
m_filename.c_str());
225 size_t zlen = zbuf.
fill();
237 size_t value_len = value.
length();
246 m_bloom_filter_items->insert(key.
row, key.
row_len);
249 m_bloom_filter_items->insert(key.
row, key.
row_len + 2);
295 "Problem finalizing CellStore file '%s' : %s",
366 if (m_bloom_filter_items) {
431 size_t key_len = key.
length();
447 const String &end_row, int32_t fd, int64_t file_length,
465 "Bad index offsets in CellStore trailer fix=%u, var=%u, "
474 uint32_t amount, index_amount;
478 bool inflating_fixed=
true;
479 bool second_try =
false;
496 "CellStore '%s' : tried to read %d but only got %d",
502 inflating_fixed =
false;
511 vbuf.
ptr = buf.
ptr + amount;
520 if (inflating_fixed) {
521 msg =
String(
"Error inflating FIXED index for cellstore '")
526 msg =
"Error inflating VARIABLE index for cellstore '" +
m_filename +
"'";
530 << index_amount <<
")\n" <<
HT_END;
545 HT_DEBUG_OUT <<
"Creating new BloomFilter for CellStore '"
553 HT_FATAL_OUT <<
"Error loading BloomFilter for CellStore '"
555 <<
" items -"<< e <<
HT_END;
577 "CellStore '%s' : tried to read %d but only got %d",
608 size_t rowlen = scan_ctx->
start_row.length();
609 boost::scoped_array<char> rowcol(
new char[rowlen + 2]);
610 memcpy(rowcol.get(), scan_ctx->
start_row.c_str(), rowlen + 1);
613 uint8_t column_family_id = schema->get_column_family(col)->get_id();
614 rowcol[rowlen + 1] = column_family_id;
624 HT_ASSERT(!
"unpossible bloom filter mode!");
639 uint32_t last_offset = 0;
645 block_size = iter.value() - last_offset;
646 cout << i <<
": offset=" << last_offset <<
" size=" << block_size
647 <<
" row=" << last_key.
row() << endl;
650 last_offset = iter.value();
651 last_key = iter.key();
655 cout << i <<
": offset=" << last_offset <<
" size=" << block_size
656 <<
" row=" << last_key.
row() << endl;
662 return BLOCK_HEADER_FORMAT;
void free()
Frees resources.
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)
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.
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]
static int32_t response_code(const Event *event)
Returns the response code from an event event generated in response to a request message.
virtual void serialize(uint8_t *buf)
Serializes this trailer to the given buffer;.
uint32_t m_outstanding_appends
PropertiesPtr properties
This singleton map stores all options.
std::string String
A String is simply a typedef to std::string.
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...
long long unsigned int Llu
Shortcut for printf formats.
BlockCompressionCodec * create_block_compression_codec() override
Creates a block compression codec suitable for decompressing the cell store's blocks.
CellStoreV0(Filesystem *filesys)
float filter_false_positive_prob
Declarations for CellStoreScanner.
static void parse_bloom_filter(const std::string &spec, PropertiesPtr &props)
Parsers a bloom filter specification and sets properties.
void add_index_entry(const SerializedKey key, uint32_t offset)
std::shared_ptr< Event > EventPtr
Smart pointer to Event.
uint32_t m_uncompressed_blocksize
CellStoreBlockIndexArray< uint32_t > m_index_map32
Scan context information.
uint8_t * ptr()
Getter for the bloom filter data.
DispatchHandlerSynchronizer m_sync_handler
Type
Enumeration for compression type.
uint8_t * ptr
Pointer to the end of the used part of the buffer.
void add(const Key &key, uint8_t flag, const void *value, uint32_t value_len, TableMutatorAsync *value_index_mutator, TableMutatorAsync *qualifier_index_mutator)
bool wait_for_reply(EventPtr &event)
This method is used by a client to synchronize.
void create(const char *fname, size_t max_entries, PropertiesPtr &props, const TableIdentifier *table_id=0) override
Creates a new cell store.
A dynamic, resizable and reference counted memory buffer.
A class managing one or more serializable ByteStrings.
bool may_contain(const void *ptr, size_t len)
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
BloomFilterItems * m_bloom_filter_items
virtual size_t size()
Returns the serialized size of the trailer.
CellStoreTrailerV0 m_trailer
size_t size()
Getter for the bloom filter size.
std::shared_ptr< Properties > PropertiesPtr
Logging routines and macros.
BloomFilterMode
Enumeration for bloom filter modes.
virtual void clear()
Clears the contents of this trailer;.
Compatibility Macros for C/C++.
BasicBloomFilter BloomFilter
void display_block_info() override
Displays block information to stdout.
uint32_t m_max_approx_items
size_t length() const
Retrieves the length of the serialized string.
BlockCompressionCodec::Args m_compressor_args
static BlockCompressionCodec * create_block_codec(BlockCompressionCodec::Type, const BlockCompressionCodec::Args &args=BlockCompressionCodec::Args())
uint16_t compression_type
uint32_t var_index_offset
bool may_contain(const void *key, size_t len) const
Checks if the data set "may" contain the key.
const uint8_t * ptr
The pointer to the serialized data.
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
void finalize(TableIdentifier *table_identifier) override
Finalizes the creation of a cell store, by writing block index and metadata trailer.
uint32_t fix_index_offset
BlockCompressionCodec * m_compressor
uint16_t block_header_format() override
Declarations for Protocol.
#define HT_THROWF(_code_, _fmt_,...)
Provides access to internal components of opaque 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.
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.
CellListScannerPtr create_scanner(ScanContext *scan_ctx) override
Creates a scanner on this cell list.
void serialize(StaticBuffer &buf)
Serializes the BloomFilter into a static memory buffer.
This is a generic exception class for Hypertable.
void create_bloom_filter(bool is_approx=false)
BloomFilter * m_bloom_filter
DynamicBuffer m_fix_index_buffer
uint8_t * release(size_t *lenp=0)
Moves ownership of the buffer to the caller.
std::shared_ptr< Schema > SchemaPtr
Smart pointer to Schema.
std::shared_ptr< CellListScanner > CellListScannerPtr
void insert(const void *key, size_t len)
Inserts a new blob into the hash.
DynamicBuffer m_var_index_buffer
virtual void open(const String &name, uint32_t flags, DispatchHandler *handler)=0
Opens a file asynchronously.
uint32_t num_filter_items
uint32_t table_generation
A space-efficent probabilistic set for membership test, false postives are possible, but false negatives are not.
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
uint32_t m_memory_consumed
void add(int64_t amount)
Add to memory used.
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.
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.
BlobHashSet BloomFilterItems
float m_uncompressed_data
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_)