libfoedus-core
FOEDUS Core Library
masstree_split_impl.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014-2015, Hewlett-Packard Development Company, LP.
3  * This program is free software; you can redistribute it and/or modify it
4  * under the terms of the GNU General Public License as published by the Free
5  * Software Foundation; either version 2 of the License, or (at your option)
6  * any later version.
7  *
8  * This program is distributed in the hope that it will be useful, but WITHOUT
9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11  * more details. You should have received a copy of the GNU General Public
12  * License along with this program; if not, write to the Free Software
13  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14  *
15  * HP designates this particular file as subject to the "Classpath" exception
16  * as provided by HP in the LICENSE.txt file that accompanied this code.
17  */
18 #ifndef FOEDUS_STORAGE_MASSTREE_MASSTREE_SPLIT_IMPL_HPP_
19 #define FOEDUS_STORAGE_MASSTREE_MASSTREE_SPLIT_IMPL_HPP_
20 
21 #include "foedus/error_code.hpp"
25 #include "foedus/thread/fwd.hpp"
27 #include "foedus/xct/xct_id.hpp"
28 
29 namespace foedus {
30 namespace storage {
31 namespace masstree {
32 
51 struct SplitBorder final : public xct::SysxctFunctor {
77  const bool piggyback_reserve_;
80  const void* piggyback_suffix_;
81 
83  thread::Thread* context,
84  MasstreeBorderPage* target,
85  KeySlice trigger,
86  bool disable_no_record_split = false,
87  bool piggyback_reserve = false,
88  KeyLength piggyback_remainder_length = 0,
89  PayloadLength piggyback_payload_count = 0,
90  const void* piggyback_suffix = nullptr)
91  : xct::SysxctFunctor(),
92  context_(context),
93  target_(target),
94  trigger_(trigger),
95  disable_no_record_split_(disable_no_record_split),
96  piggyback_reserve_(piggyback_reserve),
97  piggyback_remainder_length_(piggyback_remainder_length),
98  piggyback_payload_count_(piggyback_payload_count),
99  piggyback_suffix_(piggyback_suffix) {
100  }
101  virtual ErrorCode run(xct::SysxctWorkspace* sysxct_workspace) override;
102 
103  struct SplitStrategy {
118  };
119 
123  void decide_strategy(SplitStrategy* out) const;
124 
127 
131  void migrate_records(
132  KeySlice inclusive_from,
133  KeySlice inclusive_to,
134  MasstreeBorderPage* dest) const;
135 };
136 
137 
158 struct SplitIntermediate final : public xct::SysxctFunctor {
166 
178 
180  thread::Thread* context,
181  MasstreeIntermediatePage* target,
182  MasstreePage* piggyback_adopt_child = nullptr)
183  : xct::SysxctFunctor(),
184  context_(context),
185  target_(target),
186  piggyback_adopt_child_(piggyback_adopt_child) {
187  }
188 
189  virtual ErrorCode run(xct::SysxctWorkspace* sysxct_workspace) override;
190 
200  void split_impl_no_error(
202 
206  struct SplitStrategy {
207  enum Constants {
208  kMaxSeparators = 170, // must be larger than kMaxIntermediatePointers
209  };
218  uint16_t total_separator_count_; // -> 4090
219  uint16_t mid_index_; // -> 4092
220 
226  bool compact_adopt_; // -> 4093
227  char dummy_[3]; // -> 4096
228  };
229 
233  void decide_strategy(SplitStrategy* out) const;
234 
238  void migrate_pointers(
239  const SplitStrategy& strategy,
240  uint16_t from,
241  uint16_t to,
242  KeySlice expected_last_separator,
243  MasstreeIntermediatePage* dest) const;
244 };
245 
246 } // namespace masstree
247 } // namespace storage
248 } // namespace foedus
249 #endif // FOEDUS_STORAGE_MASSTREE_MASSTREE_SPLIT_IMPL_HPP_
void migrate_records(KeySlice inclusive_from, KeySlice inclusive_to, MasstreeBorderPage *dest) const
Subroutine to construct a new page.
KeySlice separators_[kMaxSeparators]
pointers_[n] points to page that is responsible for keys separators_[n - 1] <= key < separators_[n]...
void decide_strategy(SplitStrategy *out) const
Subroutine to decide how we will split this page.
bool compact_adopt_
When this says true, we create a dummy foster with empty range on right side, and just re-structures ...
void migrate_pointers(const SplitStrategy &strategy, uint16_t from, uint16_t to, KeySlice expected_last_separator, MasstreeIntermediatePage *dest) const
Subroutine to construct a new page.
virtual ErrorCode run(xct::SysxctWorkspace *sysxct_workspace) override
Interior node's Split.
Represents a pointer to another page (usually a child page).
Definition: storage_id.hpp:271
uint16_t PayloadLength
Represents a byte-length of a payload in this package.
Definition: masstree_id.hpp:92
Definitions of IDs in this package and a few related constant values.
MasstreeIntermediatePage *const target_
The page to split.
uint16_t SlotIndex
Index of a record in a (border) page.
Root package of FOEDUS (Fast Optimistic Engine for Data Unification Services).
Definition: assert_nd.hpp:44
Represents one thread running on one NUMA core.
Definition: thread.hpp:48
Represents one border page in Masstree Storage.
uint64_t KeySlice
Each key slice is an 8-byte integer.
Definitions of IDs in this package and a few related constant values.
uint16_t KeyLength
Represents a byte-length of a key in this package.
Definition: masstree_id.hpp:69
Common base of MasstreeIntermediatePage and MasstreeBorderPage.
SplitBorder(thread::Thread *context, MasstreeBorderPage *target, KeySlice trigger, bool disable_no_record_split=false, bool piggyback_reserve=false, KeyLength piggyback_remainder_length=0, PayloadLength piggyback_payload_count=0, const void *piggyback_suffix=nullptr)
Constructed by hierarchically reading all separators and pointers in old page.
ErrorCode lock_existing_records(xct::SysxctWorkspace *sysxct_workspace)
Subroutine to lock existing records in target_.
SplitIntermediate(thread::Thread *context, MasstreeIntermediatePage *target, MasstreePage *piggyback_adopt_child=nullptr)
A functor representing the logic in a system transaction via virtual-function.
Definitions of IDs in this package and a few related constant values.
A system transaction to split a border page in Master-Tree.
bool no_record_split_
whether this page seems to have had sequential insertions, in which case we do "no-record split" as o...
MasstreePage *const piggyback_adopt_child_
An optimization for the common case: splitting the parent page to adopt foster twins of a child page...
A system transaction to split an intermediate page in Master-Tree.
void split_impl_no_error(thread::GrabFreeVolatilePagesScope *free_pages)
The core implementation after locking relevant pages and acquiring free page resource.
const KeySlice trigger_
The key that triggered this split.
KeySlice mid_slice_
This will be the new foster fence.
MasstreeBorderPage *const target_
The page to split.
const bool piggyback_reserve_
An optimization to also make room for a record.
thread::Thread *const context_
Thread context.
Represents one intermediate page in Masstree Storage.
virtual ErrorCode run(xct::SysxctWorkspace *sysxct_workspace) override
Border node's Split.
Forward declarations of classes in masstree storage package.
const bool disable_no_record_split_
If true, we never do no-record-split (NRS).
Forward declarations of classes in thread package.
void decide_strategy(SplitStrategy *out) const
Subroutine to decide how we will split this page.
Obtains multiple free volatile pages at once and releases them automatically when this object gets ou...
Definition: thread.hpp:391
thread::Thread *const context_
Thread context.
ErrorCode
Enum of error codes defined in error_code.xmacro.
Definition: error_code.hpp:85
Per-thread reused work memory for system transactions.