29 #ifndef Hypertable_RangeServer_CellStoreBlockIndexArray_h
30 #define Hypertable_RangeServer_CellStoreBlockIndexArray_h
51 template <
typename OffsetT>
61 template <
typename OffsetT>
72 template <
typename OffsetT>
75 typedef typename std::vector<CellStoreBlockIndexElementArray<OffsetT> >::iterator
ArrayIteratorT;
80 int64_t
value() {
return (int64_t)(*m_iter).offset; }
100 template <
typename OffsetT>
106 typedef typename std::vector<ElementT>
ArrayT;
113 size_t total_entries = fixed.
fill() /
sizeof(OffsetT);
117 const uint8_t *key_ptr;
118 bool in_scope = (start_row ==
"") ?
true :
false;
119 bool check_for_end_row = end_row !=
"";
120 const uint8_t *variable_start = variable.
base;
121 const uint8_t *variable_end = variable.
ptr;
123 assert(variable.
own);
128 key_ptr = variable.
base;
130 for (
size_t i=0; i<total_entries; ++i) {
137 memcpy(&offset, fixed.
ptr,
sizeof(offset));
138 fixed.
ptr +=
sizeof(offset);
141 if (strcmp(key.
row(), start_row.c_str()) <= 0)
143 variable_start = key.
ptr;
147 if (check_for_end_row && strcmp(key.
row(), end_row.c_str()) > 0) {
151 if (i+1 < total_entries) {
154 variable_end = key_ptr;
167 HT_ASSERT(variable_start < variable_end);
172 memcpy(keydata.
base, variable_start, variable_end-variable_start);
173 for (
auto &element :
m_array) {
174 HT_ASSERT(element.key.ptr < variable_end);
175 uint64_t offset = element.key.ptr - variable_start;
176 element.key.ptr = keydata.
base + offset;
185 size_t mid_point = (m_array.size()==2) ? 0 : m_array.size()/2;
221 int64_t last_offset = 0;
224 for (ArrayIteratorT iter =
m_array.begin(); iter !=
m_array.end(); ++iter) {
226 block_size = (*iter).offset - last_offset;
227 std::cout << i <<
": offset=" << last_offset <<
" size=" << block_size
228 <<
" row=" << last_key.
row() <<
"\n";
231 last_offset = (*iter).offset;
232 last_key = (*iter).key;
236 std::cout << i <<
": offset=" << last_offset <<
" size=" << block_size
237 <<
" row=" << last_key.
row() << std::endl;
239 std::cout <<
"sizeof(OffsetT) = " <<
sizeof(OffsetT) << std::endl;
248 int32_t keys_per_block) {
249 const char *row, *last_row = 0;
250 int64_t last_count = 0;
255 if (strcmp(row, last_row) != 0) {
256 CstrToInt64MapT::iterator iter = split_row_data.find(last_row);
257 if (iter == split_row_data.end())
258 split_row_data[last_row] = last_count;
260 iter->second += last_count;
264 last_count += keys_per_block;
303 int32_t keys_per_block,
304 float compression_ratio) {
311 const char *offset_format = (
sizeof(OffsetT) == 4) ?
"%08llX" :
"%016llX";
315 qualifier.add_unchecked(filename.c_str(), filename.length());
316 qualifier.add_unchecked(
":", 1);
317 offset_ptr = (
char *)qualifier.ptr;
319 for (
size_t i=0; i<
m_array.size(); i++) {
322 next_offset =
m_array[i+1].offset;
327 sprintf(offset_ptr, offset_format, (
long long)
m_array[i].offset);
330 serial_key_buf.clear();
333 (
const char *)qualifier.base, key.timestamp,
337 size = (double)(next_offset -
m_array[i].offset) / (double)compression_ratio;
338 sprintf(buf,
"%lu", (
unsigned long)size);
340 strcpy((
char *)value_buf.
ptr, buf);
345 serial_key_buf.clear();
348 (
const char *)qualifier.base, key.timestamp,
352 sprintf(buf,
"%lu", (
unsigned long)(next_offset -
m_array[i].offset));
354 strcpy((
char *)value_buf.
ptr, buf);
359 serial_key_buf.clear();
362 (
const char *)qualifier.base, key.timestamp,
366 sprintf(buf,
"%lu", (
unsigned long)keys_per_block);
368 strcpy((
char *)value_buf.
ptr, buf);
428 #endif // Hypertable_RangeServer_CellStoreBlockIndexArray_h
void free()
Frees resources.
A memory buffer of static size.
CellStoreBlockIndexIteratorArray operator++(int)
OffsetT m_maximum_entries
CellStoreBlockIndexIteratorArray & operator++()
Cell list scanner over a buffer of cells.
Type declarations for PseudoTables class.
std::string String
A String is simply a typedef to std::string.
bool operator==(const CellStoreBlockIndexIteratorArray &other)
static const uint32_t FLAG_INSERT
CellStoreBlockIndexElementArray(const SerializedKey &key_)
.cellstore.index CompressedSize column family
CellStoreBlockIndexElementArray()
Hypertable::CellStoreBlockIndexElementArray< OffsetT > ElementT
Declarations for CellListScannerBuffer.
iterator upper_bound(const SerializedKey &k)
uint8_t * ptr
Pointer to the end of the used part of the buffer.
A dynamic, resizable and reference counted memory buffer.
.cellstore.index KeyCount column family
SerializedKey m_middle_key
A class managing one or more serializable ByteStrings.
CellStoreBlockIndexIteratorArray(ArrayIteratorT iter)
std::vector< ElementT > ArrayT
std::map< const char *, int64_t, LtCstr, SplitRowDataAlloc > SplitRowDataMapT
bool operator()(const CellStoreBlockIndexElementArray< OffsetT > &x, const CellStoreBlockIndexElementArray< OffsetT > &y) const
std::vector< ElementT >::iterator ArrayIteratorT
double fraction_covered()
uint32_t size
The size of the allocated memory buffer (base)
void add(const SerializedKey key, const ByteString value)
Adds a key/value pair to the buffer.
bool load(const SerializedKey &key)
Parses the opaque key and loads the components into the member variables.
A memory buffer of static size.
size_t length() const
Retrieves the length of the serialized string.
void free()
Clears the data; if this object is owner of the data then the allocated buffer is delete[]d...
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.
Hypertable::CellStoreBlockIndexIteratorArray< OffsetT > iterator
CellStoreBlockIndexArray()
void encode_vi32(uint8_t **bufp, uint32_t val)
Encode a integer (up to 32-bit) in variable length encoding.
void copy(TableDumper &, CellsBuilder &)
void create_key_and_append(DynamicBuffer &dst_buf, const Key &key, bool time_order_asc)
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< CellStoreBlockIndexElementArray< OffsetT > >::iterator ArrayIteratorT
int64_t end_of_last_block()
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.
.cellstore.index Size column family
void populate_pseudo_table_scanner(CellListScannerBuffer *scanner, const String &filename, int32_t keys_per_block, float compression_ratio)
Populates scanner with data for .cellstore.index pseudo table.
OffsetT m_end_of_last_block
CellStoreBlockIndexIteratorArray()
uint8_t * mark
A "bookmark", can be set by the caller.
void rescope(const String &start_row="", const String &end_row="")
Provides an STL-style iterator on CellStoreBlockIndex objects.
uint8_t * add_unchecked(const void *data, size_t len)
Adds additional data without boundary checks.
bool operator!=(const CellStoreBlockIndexIteratorArray &other)
void unique_row_count_estimate(CellList::SplitRowDataMapT &split_row_data, int32_t keys_per_block)
Accumulates unique row estimates from block index entries.
Hypertable::LtCellStoreBlockIndexElementArray< OffsetT > LtT
iterator lower_bound(const SerializedKey &k)