18 #ifndef FOEDUS_STORAGE_MASSTREE_MASSTREE_COMPOSER_IMPL_HPP_
19 #define FOEDUS_STORAGE_MASSTREE_MASSTREE_COMPOSER_IMPL_HPP_
98 bool is_updated_pointer(
101 bool is_to_keep_volatile(uint8_t layer, uint16_t btree_level)
const;
106 void drop_all_recurse(
110 void drop_all_recurse_page_only(
227 next_original_ = 0xFFFFU;
228 next_original_mini_ = 0xFFFFU;
244 next_original_slice_ < slice
245 || (next_original_slice_ == slice
247 && key_length > (layer_ + 1U) *
kSliceLen));
299 uint64_t hash = btree_level + (layer * 256U);
300 const uint64_t kMult = 0x7ada20dc734afb6fULL;
301 for (uint8_t i = 0; i < layer; ++i) {
302 hash = hash * kMult + prefixes[i];
304 hash = hash * kMult + low_fence;
305 hash = hash * kMult + high_fence;
306 uint32_t compressed =
static_cast<uint32_t
>(hash >> 32) ^ static_cast<uint32_t>(hash);
311 | static_cast<SnapshotLocalPageId>(local_snapshot_pointer_low_);
327 if (layer != layer_ || btree_level != btree_level_ || removed_) {
330 for (uint8_t i = 0; i <
layer_; ++i) {
331 if (prefixes[i] != slices_[i]) {
335 return low == slices_[
layer_] && high == slices_[layer_ + 1];
350 return hash_ < rhs.hash_;
356 return lhs.hash_ < rhs.hash_;
370 ASSERT_ND(allocated_pages_ < max_pages_);
378 MasstreeIntermediatePage* as_intermdiate(MasstreePage* page)
const ALWAYS_INLINE;
379 MasstreeBorderPage* as_border(MasstreePage* page)
const ALWAYS_INLINE;
380 uint16_t get_cur_prefix_length()
const {
return get_last_layer() *
sizeof(
KeySlice); }
381 uint8_t get_last_level_index()
const {
383 return cur_path_levels_ - 1U;
385 PathLevel* get_last_level() {
return cur_path_ + get_last_level_index(); }
386 const PathLevel* get_last_level()
const {
return cur_path_ + get_last_level_index(); }
387 uint8_t get_last_layer()
const {
388 if (cur_path_levels_ == 0) {
391 return get_last_level()->
layer_;
394 void store_cur_prefix(uint8_t layer,
KeySlice prefix_slice);
396 PathLevel* get_second_last_level() {
398 return cur_path_ + (cur_path_levels_ - 2U);
406 ErrorStack execute_a_log(uint32_t cur);
415 ErrorStack execute_same_key_group(uint32_t from, uint32_t to);
426 ErrorStack execute_insert_group(uint32_t from, uint32_t to);
432 uint32_t execute_insert_group_get_cur_run(
438 ErrorCode execute_insert_group_append_loop(uint32_t from, uint32_t to, uint32_t hint_count);
446 ErrorStack execute_delete_group(uint32_t from, uint32_t to);
455 ErrorStack execute_update_group(uint32_t from, uint32_t to);
463 ErrorStack execute_overwrite_group(uint32_t from, uint32_t to);
466 void write_dummy_page_zero();
469 ErrorStack init_root();
470 ErrorStack open_first_level(
const char* key,
KeyLength key_length);
471 ErrorStack open_next_level(
474 MasstreePage* parent,
477 void open_next_level_create_layer(
480 MasstreeBorderPage* parent,
501 ErrorStack flush_buffer();
502 inline ErrorStack flush_if_nearly_full() {
503 uint64_t threshold = max_pages_ * 8ULL / 10ULL;
504 if (
UNLIKELY(allocated_pages_ >= threshold || allocated_pages_ + 256U >= max_pages_)) {
510 ErrorStack adjust_path(
const char* key,
KeyLength key_length);
512 ErrorStack consume_original_upto_border(
KeySlice slice,
KeyLength key_length, PathLevel* level);
513 ErrorStack consume_original_upto_intermediate(
KeySlice slice, PathLevel* level);
514 ErrorStack consume_original_all();
519 ErrorStack close_level_grow_subtree(
528 ErrorStack pushup_non_root();
540 ErrorStack close_path_layer(uint16_t max_layer);
545 ErrorStack close_last_level();
551 ErrorStack close_first_level();
552 ErrorStack close_all_levels();
562 void append_border_next_layer(
567 void append_border_newpage(
KeySlice slice, PathLevel* level);
568 void append_intermediate(
572 void append_intermediate_newpage_and_pointer(
579 void refresh_page_boundary_info_variables();
580 ErrorCode close_level_register_page_boundaries();
583 ASSERT_ND(pos <= page_boundary_info_cur_pos_);
584 return reinterpret_cast<PageBoundaryInfo*
>(page_boundary_info_ + pos * 8ULL);
587 ASSERT_ND(pos <= page_boundary_info_cur_pos_);
588 return reinterpret_cast<PageBoundaryInfo*
>(page_boundary_info_ + pos * 8ULL);
591 void assert_page_boundary_not_exists(
597 void sort_page_boundary_info();
604 ErrorStack install_snapshot_pointers(uint64_t* installed_count)
const;
605 ErrorCode install_snapshot_pointers_recurse(
606 const memory::GlobalVolatilePageResolver& resolver,
609 MasstreePage* volatile_page,
611 ErrorCode install_snapshot_pointers_recurse_intermediate(
612 const memory::GlobalVolatilePageResolver& resolver,
615 MasstreeIntermediatePage* volatile_page,
616 uint64_t* installed_count)
const;
617 ErrorCode install_snapshot_pointers_recurse_border(
618 const memory::GlobalVolatilePageResolver& resolver,
621 MasstreeBorderPage* volatile_page,
622 uint64_t* installed_count)
const;
624 Engine*
const engine_;
625 snapshot::MergeSort*
const merge_sort_;
627 MasstreeStorage storage_;
628 const Composer::ComposeArguments& args_;
631 const uint16_t numa_node_;
632 const uint32_t max_pages_;
638 MasstreeIntermediatePage*
const root_;
641 Page*
const page_base_;
643 Page*
const original_base_;
660 char* page_boundary_info_;
662 PageBoundarySort* page_boundary_sort_;
667 uint32_t page_boundary_elements_;
672 uint32_t max_page_boundary_elements_;
679 uint32_t allocated_pages_;
690 uint8_t root_index_mini_;
693 uint8_t cur_path_levels_;
707 #endif // FOEDUS_STORAGE_MASSTREE_MASSTREE_COMPOSER_IMPL_HPP_
friend std::ostream & operator<<(std::ostream &o, const PathLevel &v)
memory::PagePoolOffset head_
Offset in page_base_.
bool exact_match(uint8_t btree_level, uint8_t layer, const KeySlice *prefixes, KeySlice low, KeySlice high) const __attribute__((always_inline))
returns whether the entry exactly matches with the page boundaries we look for.
KeyLength next_original_remainder_
for border page.
SnapshotLocalPageId get_local_page_id() const __attribute__((always_inline))
uint64_t SnapshotLocalPageId
Represents a local page ID in each one snapshot file in some NUMA node.
const uint64_t kSliceLen
Shorthand for sizeof(KeySlice).
Represents a pointer to another page (usually a child page).
uint16_t PayloadLength
Represents a byte-length of a payload in this package.
Definitions of IDs in this package and a few related constant values.
KeySlice low_fence_
same as low_fence of head
uint16_t SlotIndex
Index of a record in a (border) page.
MasstreeComposeContext(Engine *engine, snapshot::MergeSort *merge_sort, const Composer::ComposeArguments &args)
MasstreeComposeContext methods.
Typedefs of ID types used in snapshot package.
static uint32_t calculate_hash(uint8_t btree_level, uint8_t layer, const KeySlice *prefixes, KeySlice low_fence, KeySlice high_fence) __attribute__((always_inline))
Represents a logic to compose a new version of data pages for one storage.
uint32_t StorageId
Unique ID for storage.
Root package of FOEDUS (Fast Optimistic Engine for Data Unification Services).
uint32_t dynamic_sizeof() const __attribute__((always_inline))
uint32_t PagePoolOffset
Offset in PagePool that compactly represents the page address (unlike 8 bytes pointer).
std::string to_string() const
uint32_t BufferPosition
Represents a position in some buffer.
void drop_root_volatile(const Composer::DropVolatilesArguments &args)
Represents a pointer to a volatile page with modification count for preventing ABA.
void set_no_more_next_original()
Forward declarations of classes in root package.
bool contains_key(const char *key, KeyLength key_length) const
Represents one border page in Masstree Storage.
Brings error stacktrace information as return value of functions.
Forward declarations of classes in snapshot manager package.
ErrorStack execute()
MasstreeComposeContext::execute() and subroutines for log groups.
uint32_t hash_
Hash value of the entry.
cache::SnapshotFileSet * previous_snapshot_files_
To read existing snapshots.
uint64_t KeySlice
Each key slice is an 8-byte integer.
Holds a set of read-only file objects for snapshot files.
uint32_t local_snapshot_pointer_low_
low 32-bits of SnapshotLocalPageId of the new page.
ErrorStack construct_root(const Composer::ConstructRootArguments &args)
uint16_t KeyLength
Represents a byte-length of a key in this package.
Maximum number of logs execute_xxx_group methods process in one shot.
Common base of MasstreeIntermediatePage and MasstreeBorderPage.
KeySlice next_original_slice_
Slice of next entry.
We assume the path wouldn't be this deep.
SlotIndex next_original_mini_
for intermediate page
MasstreeComposer's compose() implementation separated from the class itself.
Composer::DropResult drop_volatiles(const Composer::DropVolatilesArguments &args)
drop_volatiles and related methods
bool has_next_original() const
MasstreeComposer(Composer *parent)
MasstreeComposer methods.
bool operator<(const PageBoundarySort &rhs) const __attribute__((always_inline))
used by std::sort
SnapshotPagePointer pointer_
uint8_t btree_level_
B-tree level.
PageBoundaryInfo()=delete
This object must be reinterpreted.
static bool static_less_than(const PageBoundarySort &lhs, const PageBoundarySort &rhs) __attribute__((always_inline))
used by std::lower_bound
uint8_t layer_
B-trie layer of the new page.
Receives an arbitrary number of sorted buffers and emits one fully sorted stream of logs...
uint64_t SnapshotPagePointer
Page ID of a snapshot page.
const KeyLength kInitiallyNextLayer
A special key length value that denotes the record in a border page was initially a next-layer pointe...
Database engine object that holds all resources and provides APIs.
uint8_t removed_
set to true when this page is closed/reopened so that only one entry matches exactly ...
Retrun value of drop_volatiles()
Represents a minimal information to install a new snapshot page pointer.
uint16_t SnapshotId
Unique ID of Snapshot.
Represents a Masstree storage.
Composer for an masstree storage.
Forward declarations of classes in memory package.
SlotIndex next_original_
If level is based on an existing snapshot page, the next entry (pointer or record) in the original pa...
Size of the tmp_boundary_array_.
bool needs_to_consume_original(KeySlice slice, KeyLength key_length) const
ErrorStack compose(const Composer::ComposeArguments &args)
KeySlice slices_[2]
actually of layer_+2.
#define CHECK_ERROR(x)
This macro calls x and checks its returned value.
snapshot::SnapshotWriter * snapshot_writer_
Writes out composed pages.
snapshot::BufferPosition info_pos_
Points to PageBoundaryInfo in page_boundary_info_.
uint16_t layer_
B-tri layer of this level.
We assume B-trie depth is at most this (prefix is at most 8*this value)
const ErrorStack kRetOk
Normal return value for no-error case.
memory::PagePoolOffset tail_
Offset in page_base_.
bool is_key_aligned_and_zero_padded(const char *key, KeyLength key_length)
Returns if the given key is 8-bytes aligned and also zero-padded to 8-bytes for easier slicing (which...
const KeySlice kSupremumSlice
Represents one intermediate page in Masstree Storage.
bool contains_slice(KeySlice slice) const
Forward declarations of classes in masstree storage package.
#define UNLIKELY(x)
Hints that x is highly likely false.
#define ASSERT_ND(x)
A warning-free wrapper macro of assert() that has no performance effect in release mode even when 'x'...
~PageBoundaryInfo()=delete
uint32_t page_count_
number of pages in this level including head/tail, without original page (so, initial=1).
Points to PageBoundaryInfo with a sorting information.
#define ALWAYS_INLINE
A function suffix to hint that the function should always be inlined.
ErrorCode
Enum of error codes defined in error_code.xmacro.
KeySlice high_fence_
same as high_fence of tail
KeySlice normalize_be_bytes_full_aligned(const void *be_bytes)
Convert an aligned big-endian byte array of at least 8-bytes-length to KeySlice.
uint8_t local_snapshot_pointer_high_
high 8-bits of SnapshotLocalPageId of the new page.
Arguments for drop_volatiles()
Writes out one snapshot file for all data pages in one reducer.
Arguments for construct_root()