|
Zero
0.1.0
|
Page handle for B-Tree data page. More...
#include <btree_page_h.h>
Classes | |
| union | record_info_int16_convert |
| union | record_info_shpid_convert |
Public Member Functions | |
| btree_page_h () | |
| btree_page_h (const btree_page_h &p) | |
| ~btree_page_h () | |
| btree_page_h & | operator= (btree_page_h &p) |
| PageID | btree_root () const |
| smsize_t | used_space () const |
| smsize_t | usable_space () const |
| int | level () const |
| Returns 1 if leaf, >1 if non-leaf. More... | |
| PageID | pid0 () const |
| Returns left-most ptr (used only in non-leaf nodes). More... | |
| PageID | pid0_opaqueptr () const |
| Returns left-most opaque pointer (used only in non-leaf nodes). More... | |
| PageID | root () const |
| Returns root page; used for recovery. More... | |
| bool | is_leaf () const |
| Is associated page a leaf? More... | |
| bool | is_node () const |
| Returns if this page is NOT a leaf. More... | |
| bool | is_leaf_parent () const |
| PageID | get_foster () const |
| Returns ID of B-link page (0 if not linked). More... | |
| PageID | get_foster_opaqueptr () const |
| Returns opaque pointer of B-link page (0 if not linked). More... | |
| const char * | get_prefix_key () const |
| Returns the prefix which is removed from all entries in this page. More... | |
| int16_t | get_prefix_length () const |
| Returns the length of prefix key (0 means no prefix compression). More... | |
| const char * | get_fence_low_key () const |
| Returns the low fence key, which is same OR smaller than all entries in this page and its descendants. More... | |
| int16_t | get_fence_low_length () const |
| Returns the length of low fence key. More... | |
| void | copy_fence_low_key (w_keystr_t &buffer) const |
| Constructs w_keystr_t object containing the low-fence key of this page. More... | |
| bool | is_fence_low_infimum () const |
| Returns if the low-fence key is infimum. More... | |
| const char * | get_fence_high_key_noprefix () const |
| int16_t | get_fence_high_length () const |
| Returns the length of high fence key with prefix. More... | |
| int16_t | get_fence_high_length_noprefix () const |
| Returns the length of high fence key without prefix. More... | |
| void | copy_fence_high_key (w_keystr_t &buffer) const |
| Constructs w_keystr_t object containing the low-fence key of this page. More... | |
| bool | is_fence_high_supremum () const |
| Returns if the high-fence key is supremum. More... | |
| const char * | get_chain_fence_high_key () const |
| Returns the high fence key of foster chain. More... | |
| int16_t | get_chain_fence_high_length () const |
| Returns the length of high fence key of foster chain. More... | |
| void | copy_chain_fence_high_key (w_keystr_t &buffer) const |
| Constructs w_keystr_t object containing the low-fence key of this page. More... | |
| bool | fence_contains (const w_keystr_t &key) const |
| int | compare_with_fence_low (const w_keystr_t &key) const |
| int | compare_with_fence_low (const char *key, size_t key_len) const |
| overload for char*. More... | |
| int | compare_with_fence_low_noprefix (const char *key, size_t key_len) const |
| used when the prefix part is already checked key/key_len must be WITHOUT prefix. More... | |
| int | compare_with_fence_high (const w_keystr_t &key) const |
| int | compare_with_fence_high (const char *key, size_t key_len) const |
| overload for char*. More... | |
| int | compare_with_fence_high_noprefix (const char *key, size_t key_len) const |
| used when the prefix part is already checked key/key_len must be WITHOUT prefix. More... | |
| int | compare_with_chain_fence_high (const w_keystr_t &key) const |
| int | compare_with_chain_fence_high (const char *key, size_t key_len) const |
| overload for char*. More... | |
| void | accept_empty_child (lsn_t new_lsn, PageID new_page_id, const bool f_redo) |
| rc_t | format_foster_child (btree_page_h &parent, const PageID &new_page_id, const w_keystr_t &triggering_key, w_keystr_t &split_key, int &move_count) |
| Initialize the page as a foster child of the given parent. More... | |
| bool | set_foster_child (PageID foster_child_pid, const w_keystr_t &new_fence_high, const w_keystr_t &child_fence_chain) |
| Sets the given page ID as foster child of this page. More... | |
| void | delete_range (int from, int to) |
| rc_t | format_steal (lsn_t new_lsn, const PageID &pid, StoreID store, PageID root, int level, PageID pid0, lsn_t pid0_emlsn, PageID foster, lsn_t foster_emlsn, const w_keystr_t &fence_low, const w_keystr_t &fence_high, const w_keystr_t &chain_fence_high, bool log_it=true, btree_page_h *steal_src1=nullptr, int steal_from1=0, int steal_to1=0, btree_page_h *steal_src2=nullptr, int steal_from2=0, int steal_to2=0, bool steal_src2_pid0=false, const bool full_logging=false, const bool log_src_1=false, const bool ghost=false) |
| Initializes the associated page, stealing records from other pages as specified. More... | |
| void | _steal_records (btree_page_h *steal_src, int steal_from, int steal_to, const bool full_logging) |
| Steal records from steal_src. Called by format_steal. More... | |
| rc_t | init_fence_keys (const bool set_low, const w_keystr_t &low, const bool set_high, const w_keystr_t &high, const bool set_chain, const w_keystr_t &chain_fence_high, const bool set_pid0, const PageID new_pid0, const bool set_emlsn, const lsn_t new_pid0_emlsn, const bool set_foster, const PageID foster_pid0, const bool set_foster_emlsn, const lsn_t foster_emlsn, const int remove_count=0) |
| rc_t | norecord_split (PageID foster, lsn_t foster_emlsn, const w_keystr_t &fence_high, const w_keystr_t &chain_fence_high) |
| bool | check_chance_for_norecord_split (const w_keystr_t &key_to_insert) const |
| Returns if whether we can do norecord insert now. More... | |
| int | nrecs () const |
| Returns the number of records in this page. More... | |
| int | nghosts () const |
| Returns the number of ghosts records in this page. More... | |
| bool | is_ghost (slotid_t slot) const |
| Returns if the specified record is a ghost record. More... | |
| void | get_key (slotid_t slot, w_keystr_t &key) const |
| Retrieves key from given record #. More... | |
| const char * | element (int slot, smsize_t &len, bool &ghost) const |
| bool | copy_element (int slot, char *out_buffer, smsize_t &len, bool &ghost) const |
| PageID | child (slotid_t slot) const |
| Return the (non-opaque) child pointer of record in slot. More... | |
| PageID | child_opaqueptr (slotid_t slot) const |
| Return the opaque child pointer of record in slot. More... | |
| PageID * | page_pointer_address (int offset) |
| size_t | get_rec_space (int slot) const |
| int16_t | calculate_prefix_length (int16_t existing_prefix_len, w_keystr_t low_key, w_keystr_t high_key) |
| rc_t | copy_records (const int rec_count, char *data_buffer, smsize_t &len) |
| rc_t | insert_records_dest_redo (const int16_t prefix_len, const int32_t move_count, const int16_t record_data_len, const char *record_data) |
| void | search (const w_keystr_t &key, bool &found_key, slotid_t &return_slot) const |
| void | search (const char *key_raw, size_t key_raw_len, bool &found_key, slotid_t &return_slot) const |
| void | search_node (const w_keystr_t &key, slotid_t &return_slot) const |
| rc_t | insert_node (const w_keystr_t &key, slotid_t slot, PageID child, const lsn_t &child_emlsn) |
| void | mark_ghost (slotid_t slot) |
| void | unmark_ghost (slotid_t slot) |
| rc_t | replace_ghost (const w_keystr_t &key, const cvec_t &elem, bool redo=false) |
| rc_t | replace_fence_rec_nolog_may_defrag (const w_keystr_t &low, const w_keystr_t &high, const w_keystr_t &chain, int new_prefix_length=-1) |
| Replaces the special fence record with the given new data, expanding the slot length if needed. More... | |
| rc_t | replace_fence_rec_nolog_no_defrag (const w_keystr_t &low, const w_keystr_t &high, const w_keystr_t &chain, int new_prefix_length) |
| rc_t | remove_shift_nolog (slotid_t slot) |
| rc_t | replace_el_nolog (slotid_t slot, const cvec_t &elem) |
| void | overwrite_el_nolog (slotid_t slot, smsize_t offset, const char *new_el, smsize_t elen) |
| void | reserve_ghost (const w_keystr_t &key, size_t element_length) |
| void | reserve_ghost (const char *key_raw, size_t key_raw_len, size_t element_length) |
| void | insert_nonghost (const w_keystr_t &key, const cvec_t &elem) |
| bool | _is_enough_spacious_ghost (const w_keystr_t &key, slotid_t slot, const cvec_t &el) |
| bool | check_space_for_insert_leaf (const w_keystr_t &trunc_key, const cvec_t &el) |
| bool | check_space_for_insert_leaf (size_t trunc_key_length, size_t element_length) |
| bool | check_space_for_insert_node (const w_keystr_t &key) |
| for intermediate node (no element). More... | |
| void | suggest_fence_for_split (w_keystr_t &mid, slotid_t &right_begins_from, const w_keystr_t &triggering_key) const |
| Suggests a new fence key, assuming this page is being split. More... | |
| w_keystr_t | recalculate_fence_for_split (slotid_t right_begins_from) const |
| For recovering the separator key from boundary place. More... | |
| bool | is_insertion_extremely_skewed_right () const |
| bool | is_insertion_skewed_right () const |
| bool | is_insertion_skewed_left () const |
| rc_t | defrag (const bool full_logging_redo=false) |
| Defrags this page to remove holes and ghost records in the page. More... | |
| rc_t | compress (const w_keystr_t &low, const w_keystr_t &high, const w_keystr_t &chain, bool redo=false) |
| Compress page by trying to expand the prefix and truncate keys even further. More... | |
| rc_t | leaf_stats (btree_lf_stats_t &btree_lf) |
| stats for leaf nodes. More... | |
| rc_t | int_stats (btree_int_stats_t &btree_int) |
| stats for interior nodes. More... | |
| void | print (bool print_elem=false) |
| Debugs out the contents of this page. More... | |
| bool | is_consistent (bool check_keyorder=false, bool check_space=false) const |
| lsn_t * | emlsn_address (general_recordid_t pos) |
| const lsn_t & | get_emlsn_general (general_recordid_t pos) const |
| void | set_emlsn_general (general_recordid_t pos, const lsn_t &lsn) |
| Sets the Expected Child LSN of pid0, foster-child, or real child. More... | |
| const lsn_t & | get_foster_emlsn () const |
| const lsn_t & | get_pid0_emlsn () const |
Public Member Functions inherited from fixable_page_h | |
| fixable_page_h () | |
| Create handle not yet fixed to a page. More... | |
| ~fixable_page_h () | |
| fixable_page_h & | operator= (fixable_page_h &p) |
| bool | is_fixed () const |
| Do we have an associated page? More... | |
| void | unfix (bool evict=false) |
| bool | is_bufferpool_managed () const |
| Is this page really fixed in bufferpool or a psuedo-fix? More... | |
| w_rc_t | fix_nonroot (const fixable_page_h &parent, PageID pid, latch_mode_t mode, bool conditional=false, bool virgin_page=false, bool only_if_hit=false) |
| w_rc_t | fix_direct (PageID pid, latch_mode_t mode, bool conditional=false, bool virgin_page=false, bool only_if_hit=false, bool do_recovery=true) |
| bf_idx | pin_for_refix () |
| w_rc_t | refix_direct (bf_idx idx, latch_mode_t mode, bool conditional=false) |
| w_rc_t | fix_root (StoreID store, latch_mode_t mode, bool conditional=false, bool virgin=false) |
| void | fix_nonbufferpool_page (generic_page *s) |
| bool | is_dirty () const |
| void | update_page_lsn (const lsn_t &lsn) const |
| Updates page_lsn field stored in CB of buffered page. More... | |
| lsn_t | get_page_lsn () const |
| uint32_t | get_log_volume () |
| returns log volume in the CB More... | |
| void | increment_log_volume (uint32_t) |
| void | reset_log_volume () |
| bool | has_check_recovery () |
| return value of _check_recovery flag on CB More... | |
| void | set_img_page_lsn (const lsn_t &lsn) |
| Updates lsn field inside generic_page (i.e., in the page image) More... | |
| bool | is_to_be_deleted () |
| w_rc_t | set_to_be_deleted (bool log_it) |
| void | unset_to_be_deleted () |
| void | set_check_recovery (bool) |
| void | set_tag (page_tag_t tag) |
| latch_mode_t | latch_mode () const |
| bool | is_latched () const |
| Do we hold our page's latch in SH or EX mode? More... | |
| bool | change_possible_after_fix () const |
| bool | upgrade_latch_conditional (latch_mode_t mode=LATCH_EX) |
| bool | has_children () const |
| int | max_child_slot () const |
| PageID * | child_slot_address (int child_slot) const |
| PageID | root () const |
| void | setup_for_restore (generic_page *pp) |
| bool | is_pinned_for_restore () |
Public Member Functions inherited from generic_page_h | |
| generic_page_h (generic_page *s) | |
| virtual | ~generic_page_h () |
| generic_page * | get_generic_page () const |
| return pointer to underlying page More... | |
| PageID | pid () const |
| StoreID | store () const |
| page_tag_t | tag () const |
| const lsn_t & | lsn () const |
Static Public Attributes | |
| static smsize_t | max_entry_size |
Static Public Attributes inherited from fixable_page_h | |
| static int | force_Q_fixing = 0 |
Private Types | |
| enum | { data_sz = btree_page::data_sz, hdr_sz = btree_page::hdr_sz } |
| enum | _internal { max_key_length = (1 << (sizeof(key_length_t) * 8 - 1)) - 1 } |
| typedef uint16_t | key_length_t |
| A field to hold a B-tree key length. More... | |
| typedef key_length_t | pack_scratch_t |
| type of scratch space needed by _pack_leaf_record More... | |
| typedef uint16_t | poor_man_key |
| Poor man's normalized key type. More... | |
Private Member Functions | |
| btree_page * | page () const |
| void | _pack_node_record (cvec_t &out, const cvec_t &trunc_key, const lsn_t &emlsn) const |
| void | _pack_leaf_record (cvec_t &out, pack_scratch_t &out_scratch, const cvec_t &trunc_key, const char *element, size_t element_len) const |
| void | _pack_leaf_record_prefix (cvec_t &out, pack_scratch_t &out_scratch, const cvec_t &trunc_key) const |
| int | _pack_fence_rec (cvec_t &out, const w_keystr_t &low, const w_keystr_t &high, const w_keystr_t &chain, int new_prefix_len) const |
| size_t | _predict_leaf_data_length (int trunc_key_length, int element_length) const |
| poor_man_key | _extract_poor_man_key (const void *trunc_key, size_t trunc_key_len) const |
| Returns the value of poor-man's normalized key for the given key string WITHOUT prefix. More... | |
| poor_man_key | _extract_poor_man_key (const cvec_t &trunc_key) const |
| Returns the value of poor-man's normalized key for the given key string WITHOUT prefix. More... | |
| poor_man_key | _extract_poor_man_key (const void *key_with_prefix, size_t key_len_with_prefix, size_t prefix_len) const |
| Returns the value of poor-man's normalized key for the given key string WITH prefix. More... | |
| poor_man_key | _poor (int slot) const |
| Return poor man's key data for given slot. More... | |
| const char * | _leaf_key_noprefix (slotid_t slot, size_t &len) const |
| const char * | _node_key_noprefix (slotid_t slot, size_t &len) const |
| size_t | _element_offset (int slot) const |
| int | _compare_key_noprefix (slotid_t slot, const void *key_noprefix, size_t key_len) const |
| returns compare(specified-key, key_noprefix) More... | |
| int | _compare_slot_with_key (int slot, const void *key_noprefix, size_t key_len, poor_man_key poor) const |
| bool | _is_consistent_keyorder () const |
| internal method used from is_consistent() to check keyorder correctness. More... | |
| bool | _is_consistent_poormankey () const |
| checks if the poor-man's normalized keys are valid. More... | |
| void | _update_btree_consecutive_skewed_insertions (slotid_t slot) |
| Given the place to insert, update btree_consecutive_skewed_insertions. More... | |
| bool | _check_space_for_insert (size_t data_length) |
| void | _init (lsn_t lsn, PageID page_id, StoreID store, PageID root_pid, PageID pid0, lsn_t pid0_emlsn, PageID foster_pid, lsn_t foster_emlsn, int16_t btree_level, const w_keystr_t &low, const w_keystr_t &high, const w_keystr_t &chain_fence_high, const bool ghost) |
Friends | |
| class | btree_impl |
| template<class T > | |
| class | btree_ghost_t |
| class | btree_ghost_mark_log |
| class | btree_ghost_reclaim_log |
| template<class T > | |
| class | page_img_format_t |
| class | btree_split_log |
| std::ostream & | operator<< (std::ostream &os, btree_page_h &b) |
Additional Inherited Members | |
Static Public Member Functions inherited from fixable_page_h | |
| static general_recordid_t | find_page_id_slot (generic_page *page, PageID pid) |
Protected Member Functions inherited from generic_page_h | |
| generic_page_h (generic_page *s, const PageID &pid, page_tag_t tag, StoreID store) | |
Protected Attributes inherited from fixable_page_h | |
| bool | _bufferpool_managed |
| is our associated page managed by the buffer pool? More... | |
| latch_mode_t | _mode |
| q_ticket_t | _Q_ticket |
Protected Attributes inherited from generic_page_h | |
| generic_page * | _pp |
| The actual page we are handling; may be NULL for fixable pages. More... | |
Page handle for B-Tree data page.
Our version of B-Tree header contains low-high fence keys and pointers as a b-link tree. Fence keys are NEVER changed once the page is created until the page gets splitted. Prefix compression in this scheme utilizes it by storing the common leading bytes of the two fence keys and simply getting rid of them from all entries in this page. See btree_page for the header definitions.
The page layout of a B-Tree page is as follows:
[common-headers from generic_page_header] [B-tree-specific-headers in btree_page] (item area in btree_page: [item storage part that is growing forwards] [(contiguous) free area] [item storage part that is growing backwards] )
The first item contains the fence keys and foster key, if any: [low-fence-key data (including prefix) + high-fence-key data (without prefix) + chain-fence-high-key data (complete string; chain-fence-high doesn't share prefix!)]. The other items contain the B-tree page's records, one each. These locations are called slots; slot 0 corresponds to item 1 and so on.
We use poor-man's normalized key to speed up searches. Each slot has a field, _poor, that holds the first few bytes of that slot's key as an unsigned integer (poor_man_key) so that comparison with most slot keys can be done without going to the key itself, avoiding L1 cache misses. The whole point of poor_man_key is avoiding cache misses!
NOTE So far, poor-man's normalied key is 2 byte integer (uint16_t) and the corresponding bytes are NOT eliminated from the key string in the record. This is to speed up the retrieval of the (truncated) complete key at the cost of an additional 2 bytes to store it. I admit this is arguable, but deserilizing the first part everytime (it's likely little-endian, so we need to flip it) will slow down retrieval.
Also associated with each slot is a ghost bit (is this record a ghost record?), a variable-size data portion used to hold the record details (i.e., key and element if a leaf node), and in the case of interior nodes, a child pointer.
Internally, record data is stored in the item variable-size data part as follows:
(If the page is leaf page)
(If the page is interior node page)
Opaque pointers:
|
private |
A field to hold a B-tree key length.
|
private |
type of scratch space needed by _pack_leaf_record
|
private |
Poor man's normalized key type.
To speed up comparison this should be an integer type, not char[].
|
private |
|
inline |
|
inline |
|
inline |
|
private |
Returns if there is enough free space to accomodate the given item.
|
inlineprivate |
returns compare(specified-key, key_noprefix)
|
inlineprivate |
compare slot slot's key with given key (as key_noprefix,key_len,poor tuple) result <0 if slot's key is before given key
|
inlineprivate |
Calculate offset within slot's variable-sized data to its element data. All data from that point onwards makes up the element data.
|
inlineprivate |
Returns the value of poor-man's normalized key for the given key string WITHOUT prefix.
|
inlineprivate |
Returns the value of poor-man's normalized key for the given key string WITHOUT prefix.
|
inlineprivate |
Returns the value of poor-man's normalized key for the given key string WITH prefix.
|
private |
Initialize the whole image of this page as an empty page.
|
private |
internal method used from is_consistent() to check keyorder correctness.
|
private |
checks if the poor-man's normalized keys are valid.
| bool btree_page_h::_is_enough_spacious_ghost | ( | const w_keystr_t & | key, |
| slotid_t | slot, | ||
| const cvec_t & | el | ||
| ) |
Tell if the slot is a ghost record and enough spacious to store the given key/data.
|
inlineprivate |
Retrieves the key WITHOUT prefix of specified slot in a leaf
|
inlineprivate |
Retrieves the key WITHOUT prefix of specified slot in an interior node
|
inlineprivate |
Pack a B-tree page's fence and foster key information into out, suitable for use with insert_item.
All input keys are uncompressed. During packing, prefix elimination is used. The prefix length to truncate is new_prefix_len if non-negative; otherwise, the prefix length to use is computed as the maximum number of common prefix bytes of the low and high fence keys. The prefix length used is returned either way.
The caller is responsible for ensuring that btree_fence_low_length, btree_fence_high_length, btree_chain_fence_high_length are set to the lengths of the corresponding keys and that btree_prefix_length is set to the returned prefix length.
|
inlineprivate |
Pack a leaf record's information into out, suitable for use with insert_item.
trunc_key is the record's key (including its w_keystr_t sign byte) without its prefix; element is the record's associated value.
out_scratch is a scratch work area that the caller must provide; it must remain in scope in order for out to be used (i.e., out will point to part(s) of out_scratch).
|
inlineprivate |
Pack a leaf record's key information only into out, suitable for use with insert_item with variable-size–data length computed by _predict_leaf_data_length using in addition the expected element length. (This is used by reserve_ghost to set only the key information leaving reserved space for the future element.)
trunc_key is the record's key (including its w_keystr_t sign byte) without its prefix.
out_scratch is a scratch work area that the caller must provide; it must remain in scope in order for out to be used (i.e., out will point to part(s) of out_scratch).
|
inlineprivate |
Pack a node record's information into out, suitable for use with insert_item.
trunc_key is the record's key (including its w_keystr_t sign byte) without its prefix.
emlsn is the expected minimum LSN for the pointed child page. Be VERY careful because both data in trunk_key and emlsn are stored as references. You must keep the original variables until the resulting cvec_t gets out of scope.
|
inlineprivate |
Return poor man's key data for given slot.
|
inlineprivate |
Compute needed length of variable-size data to store a leaf record with the given truncated key and element lengths.
| void btree_page_h::_steal_records | ( | btree_page_h * | steal_src, |
| int | steal_from, | ||
| int | steal_to, | ||
| const bool | full_logging | ||
| ) |
Steal records from steal_src. Called by format_steal.
|
private |
Given the place to insert, update btree_consecutive_skewed_insertions.
| [in] | new_lsn | LSN of the operation that creates the foster-child page. |
| [in] | new_page_id | Page ID of the new page. |
| [in] | f_redo | true if caller is from redo logic. |
|
inline |
| int16_t btree_page_h::calculate_prefix_length | ( | int16_t | existing_prefix_len, |
| w_keystr_t | low_key, | ||
| w_keystr_t | high_key | ||
| ) |
| bool btree_page_h::check_chance_for_norecord_split | ( | const w_keystr_t & | key_to_insert | ) | const |
Returns if whether we can do norecord insert now.
| bool btree_page_h::check_space_for_insert_leaf | ( | const w_keystr_t & | trunc_key, |
| const cvec_t & | el | ||
| ) |
Returns if there is enough free space to accomodate the given new record.
| bool btree_page_h::check_space_for_insert_leaf | ( | size_t | trunc_key_length, |
| size_t | element_length | ||
| ) |
| bool btree_page_h::check_space_for_insert_node | ( | const w_keystr_t & | key | ) |
for intermediate node (no element).
Return the (non-opaque) child pointer of record in slot.
Return the opaque child pointer of record in slot.
|
inline |
Return value : 0 if equal. : <0 if key < fence-high. : >0 if key > fence-high.
|
inline |
overload for char*.
|
inline |
Return value : 0 if equal. : <0 if key < fence-high. : >0 if key > fence-high.
|
inline |
overload for char*.
|
inline |
used when the prefix part is already checked key/key_len must be WITHOUT prefix.
|
inline |
Return value : 0 if equal. : <0 if key < fence-low. : >0 if key > fence-low.
|
inline |
overload for char*.
|
inline |
used when the prefix part is already checked key/key_len must be WITHOUT prefix.
| rc_t btree_page_h::compress | ( | const w_keystr_t & | low, |
| const w_keystr_t & | high, | ||
| const w_keystr_t & | chain, | ||
| bool | redo = false |
||
| ) |
Compress page by trying to expand the prefix and truncate keys even further.
|
inline |
Constructs w_keystr_t object containing the low-fence key of this page.
| bool btree_page_h::copy_element | ( | int | slot, |
| char * | out_buffer, | ||
| smsize_t & | len, | ||
| bool & | ghost | ||
| ) | const |
Attempt to copy element of given record to provided buffer (out_buffer[0..len-1]). Returns false iff failed due to insufficient buffer size.
Sets len to actual element size in all cases. Also returns ghost status of given record.
|
inline |
Constructs w_keystr_t object containing the low-fence key of this page.
|
inline |
Constructs w_keystr_t object containing the low-fence key of this page.
| rc_t btree_page_h::defrag | ( | const bool | full_logging_redo = false | ) |
Defrags this page to remove holes and ghost records in the page.
A page can have unused holes between records and ghost records as a result of inserts and deletes. This method removes those dead spaces to compress the page. The best thing of this is that we have to log only the slot numbers of ghost records that are removed because there are 'logically' no changes. Context: System transaction.
| void btree_page_h::delete_range | ( | int | from, |
| int | to | ||
| ) |
| const char * btree_page_h::element | ( | int | slot, |
| smsize_t & | len, | ||
| bool & | ghost | ||
| ) | const |
Return pointer to, length of element of given record. Also returns ghost status of given record.
|
inline |
Returns if the given key can exist in the range specified by fence keys, which is low-fence <= key < high-fence.
| rc_t btree_page_h::format_foster_child | ( | btree_page_h & | parent, |
| const PageID & | new_page_id, | ||
| const w_keystr_t & | triggering_key, | ||
| w_keystr_t & | split_key, | ||
| int & | move_count | ||
| ) |
Initialize the page as a foster child of the given parent.
Moves records from the given (foster) parent page based on the given split-triggering key. Initializes the fence keys accordingly.
| rc_t btree_page_h::format_steal | ( | lsn_t | new_lsn, |
| const PageID & | pid, | ||
| StoreID | store, | ||
| PageID | root, | ||
| int | level, | ||
| PageID | pid0, | ||
| lsn_t | pid0_emlsn, | ||
| PageID | foster, | ||
| lsn_t | foster_emlsn, | ||
| const w_keystr_t & | fence_low, | ||
| const w_keystr_t & | fence_high, | ||
| const w_keystr_t & | chain_fence_high, | ||
| bool | log_it = true, |
||
| btree_page_h * | steal_src1 = nullptr, |
||
| int | steal_from1 = 0, |
||
| int | steal_to1 = 0, |
||
| btree_page_h * | steal_src2 = nullptr, |
||
| int | steal_from2 = 0, |
||
| int | steal_to2 = 0, |
||
| bool | steal_src2_pid0 = false, |
||
| const bool | full_logging = false, |
||
| const bool | log_src_1 = false, |
||
| const bool | ghost = false |
||
| ) |
Initializes the associated page, stealing records from other pages as specified.
This sets all headers, fence/prefix keys, and initial records altogether. Steals records from steal_src1 if non-null. Then steal records from steal_src2 if non-null (this is used only when merging). If steal_src2_pid0 is true, it also steals src2's pid0 with low-fence key.
| [in] | new_lsn | LSN of the operation that creates this page. |
| [in] | pid | Page ID of the new page; this must match pid used to fix this page if a buffer pool-manage page. |
| [in] | root | Page ID of the root page of the B-tree this page belongs to. |
| [in] | level | Level of the new page. |
| [in] | pid0 | New pid0 value |
| [in] | foster | Page ID of the (if exists) foster-child of the parent. |
| [in] | fence_low | The fence low key of the new page. |
| [in] | fence_high | The fence high key of the new page. |
| [in] | chain_fence_high | Highest key in the foster chain. |
| [in] | log_it | Should we log this change? ... |
|
inline |
Returns the high fence key of foster chain.
|
inline |
Returns the length of high fence key of foster chain.
|
inline |
Returns the Expected Child LSN of pid0, foster-child, or real child.
|
inline |
Returns the high fence key (without prefix), which is larger than all entries in this page and its descendants. NOTE we don't provide get_fence_high_key() with prefix because the page eliminates prefix from fence-high.
|
inline |
Returns the length of high fence key with prefix.
|
inline |
Returns the length of high fence key without prefix.
|
inline |
Returns the low fence key, which is same OR smaller than all entries in this page and its descendants.
|
inline |
Returns the length of low fence key.
| PageID btree_page_h::get_foster | ( | ) | const |
Returns ID of B-link page (0 if not linked).
|
inline |
Returns opaque pointer of B-link page (0 if not linked).
| void btree_page_h::get_key | ( | slotid_t | slot, |
| w_keystr_t & | key | ||
| ) | const |
Retrieves key from given record #.
|
inline |
Returns the prefix which is removed from all entries in this page.
|
inline |
Returns the length of prefix key (0 means no prefix compression).
|
inline |
Returns physical space used by the record currently in the given slot (including padding and other overhead due to that slot being occupied).
| rc_t btree_page_h::init_fence_keys | ( | const bool | set_low, |
| const w_keystr_t & | low, | ||
| const bool | set_high, | ||
| const w_keystr_t & | high, | ||
| const bool | set_chain, | ||
| const w_keystr_t & | chain_fence_high, | ||
| const bool | set_pid0, | ||
| const PageID | new_pid0, | ||
| const bool | set_emlsn, | ||
| const lsn_t | new_pid0_emlsn, | ||
| const bool | set_foster, | ||
| const PageID | foster_pid0, | ||
| const bool | set_foster_emlsn, | ||
| const lsn_t | foster_emlsn, | ||
| const int | remove_count = 0 |
||
| ) |
| rc_t btree_page_h::insert_node | ( | const w_keystr_t & | key, |
| slotid_t | slot, | ||
| PageID | child, | ||
| const lsn_t & | child_emlsn | ||
| ) |
Insert a new entry at "slot". This is used only for non-leaf pages. For leaf pages, always use replace_ghost() and reserve_ghost().
| [in] | child | child pointer to add |
| [in] | child_emlsn | Expected child LSN of the pointed page |
| void btree_page_h::insert_nonghost | ( | const w_keystr_t & | key, |
| const cvec_t & | elem | ||
| ) |
Creates a non-ghost record with the given key and data. If the record already exists as a ghost, we reuse it. This is logically a combination of reserve_ghost() and replace_ghost(), but this does the two in one-go. This function itself does NOT log, so the caller is responsible for it.
| [in] | key | inserted key |
| [in] | elem | record data |
| rc_t btree_page_h::insert_records_dest_redo | ( | const int16_t | prefix_len, |
| const int32_t | move_count, | ||
| const int16_t | record_data_len, | ||
| const char * | record_data | ||
| ) |
| rc_t btree_page_h::int_stats | ( | btree_int_stats_t & | btree_int | ) |
stats for interior nodes.
| bool btree_page_h::is_consistent | ( | bool | check_keyorder = false, |
| bool | check_space = false |
||
| ) | const |
Checks integrity of this page. This function does NOT check integrity across multiple pages. For that purpose, use btree_m::verify_tree(). If the two arguments are both false (which is default), this function should be very efficient.
| [in] | check_keyorder | whether to check the sortedness and uniqueness of the keys in this page. setting this to true makes this function expensive. |
| [in] | check_space | whether to check any overlaps of records and integrity of space offset. setting this to true makes this function expensive. |
|
inline |
Returns if the high-fence key is supremum.
|
inline |
Returns if the low-fence key is infimum.
|
inline |
Returns if the specified record is a ghost record.
|
inline |
|
inline |
|
inline |
|
inline |
Is associated page a leaf?
|
inline |
return true if this node is the lowest interior node, * i.e., the parent of a leaf. Used to tell how we should * latch a child page : EX or SH *
|
inline |
Returns if this page is NOT a leaf.
| rc_t btree_page_h::leaf_stats | ( | btree_lf_stats_t & | btree_lf | ) |
stats for leaf nodes.
|
inline |
Returns 1 if leaf, >1 if non-leaf.
| void btree_page_h::mark_ghost | ( | slotid_t | slot | ) |
Mark the given slot to be a ghost record. If the record is already a ghost, does nothing. This is used by delete and insert (UNDO). This function itself does NOT log, so the caller is responsible for it.
|
inline |
Returns the number of ghosts records in this page.
| rc_t btree_page_h::norecord_split | ( | PageID | foster, |
| lsn_t | foster_emlsn, | ||
| const w_keystr_t & | fence_high, | ||
| const w_keystr_t & | chain_fence_high | ||
| ) |
Called when we did a split from this page but didn't move any record to new page. This method can't be undone. Use this only for REDO-only system transactions.
|
inline |
Returns the number of records in this page.
|
inline |
| void btree_page_h::overwrite_el_nolog | ( | slotid_t | slot, |
| smsize_t | offset, | ||
| const char * | new_el, | ||
| smsize_t | elen | ||
| ) |
Similar to replace_el_nolog(), but this overwrites specific part of the element and never changes the size of record, so it's simpler, faster and can't throw error.
|
inlineprivate |
|
inline |
Returns a pointer to given page pointer (e.g., PageID).
Offset may be -2 for leaf nodes or [-2,nrecs()-1] for internal nodes. It denotes:
-2: the foster pointer -1: pid0 0..nrec()-1: the child pointer of the record in the corresponding slot
The page pointer will be at a 4-byte aligned address and opaque.
(This method is used to implement swizzling of page pointers atomically.)
| PageID btree_page_h::pid0 | ( | ) | const |
Returns left-most ptr (used only in non-leaf nodes).
|
inline |
Returns left-most opaque pointer (used only in non-leaf nodes).
| void btree_page_h::print | ( | bool | print_elem = false | ) |
Debugs out the contents of this page.
| w_keystr_t btree_page_h::recalculate_fence_for_split | ( | slotid_t | right_begins_from | ) | const |
For recovering the separator key from boundary place.
Remove the slot and up-shift slots after the hole to fill it up.
| slot | the slot to remove. |
Replaces the given slot with the new data. key is not changed. If we need to expand the record and the page doesn't have enough space, eRECWONTFIT is thrown.
| rc_t btree_page_h::replace_fence_rec_nolog_may_defrag | ( | const w_keystr_t & | low, |
| const w_keystr_t & | high, | ||
| const w_keystr_t & | chain, | ||
| int | new_prefix_length = -1 |
||
| ) |
Replaces the special fence record with the given new data, expanding the slot length if needed.
This method also updates fence_low/high/chain-high_length. Also, this method may defrag the page to squeeze out space for the fence keys if needed (returns eRECWONTFIT if it still doesn't fit).
| rc_t btree_page_h::replace_fence_rec_nolog_no_defrag | ( | const w_keystr_t & | low, |
| const w_keystr_t & | high, | ||
| const w_keystr_t & | chain, | ||
| int | new_prefix_length | ||
| ) |
| rc_t btree_page_h::replace_ghost | ( | const w_keystr_t & | key, |
| const cvec_t & | elem, | ||
| bool | redo = false |
||
| ) |
Replace an existing ghost record to insert the given tuple. This assumes the ghost record is enough spacious.
| [in] | key | inserted key |
| [in] | elem | record data |
|
inline |
Creates a dummy ghost record with the given key and element length as a preparation for subsequent insertion. This is used by insertion (its nested system transaction). This function itself does NOT log, so the caller is responsible for it.
| void btree_page_h::reserve_ghost | ( | const char * | key_raw, |
| size_t | key_raw_len, | ||
| size_t | element_length | ||
| ) |
|
inline |
Returns root page; used for recovery.
|
inline |
Search for given key in this B-tree page. Stores in found_key the key found status and in return_slot the slot where the key was found or (if not found) the slot where the key should go if inserted. Note in the latter case that return_slot may be nrecs().
| void btree_page_h::search | ( | const char * | key_raw, |
| size_t | key_raw_len, | ||
| bool & | found_key, | ||
| slotid_t & | return_slot | ||
| ) | const |
Search for given key in this B-tree page. Stores in found_key the key found status and in return_slot the slot where the key was found or (if not found) the slot where the key should go if inserted. Note in the latter case that return_slot may be nrecs().
| void btree_page_h::search_node | ( | const w_keystr_t & | key, |
| slotid_t & | return_slot | ||
| ) | const |
Search for given key in this interior node, determining which child pointer should be taken to continue searching down the B-tree.
Stores in return_slot the slot whose child pointer should be followed, with -1 denoting that the pid0 child pointer should be followed.
Note: keys in interior nodes are separator keys. Like fence keys, a separator key is exclusive for left and inclusive for right. For example, a separator key "AB" sends "AA" to left, "AAZ" to left, "AB" to right, "ABA" to right, and "AC" to right.
| bool btree_page_h::set_foster_child | ( | PageID | foster_child_pid, |
| const w_keystr_t & | new_fence_high, | ||
| const w_keystr_t & | child_fence_chain | ||
| ) |
Sets the given page ID as foster child of this page.
Adjusts not only the foster child pointer, but also the high fence key – which must change to the separator key that caused the split – and the chain fence key, which must be copied from the foster child.
| void btree_page_h::suggest_fence_for_split | ( | w_keystr_t & | mid, |
| slotid_t & | right_begins_from, | ||
| const w_keystr_t & | triggering_key | ||
| ) | const |
Suggests a new fence key, assuming this page is being split.
The new "mid" fence key will be the new left sibling's high fence key and also the right sibling's low fence key after split. right_begins_from returns the slot id from which (including it) the new right sibling steal the entires.
| [out] | mid | suggested fence key in the middle |
| [out] | right_begins_from | slot id from which (including it) the new right sibling steal the entires |
| [in] | triggering_key | the key to be inserted after this split. used to determine split policy. |
| void btree_page_h::unmark_ghost | ( | slotid_t | slot | ) |
Un-Mark the given slot to be a regular record. If the record is already a non-ghost, does nothing. This is only used by delete (UNDO). This function itself does NOT log, so the caller is responsible for it.
|
inline |
|
inline |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
static |
1.8.12