libfoedus-core
FOEDUS Core Library
foedus::storage::masstree::GrowFirstLayerRoot Struct Referencefinal

A system transaction to grow a first-layer root. More...

Detailed Description

A system transaction to grow a first-layer root.

See also
Physical-only, short-living system transactions.

The root page of a first-layer in masstree is a bit special. We thus have a separate sysxct.

This does nothing and returns kErrorCodeOk in the following cases:

  • The special lock in control block seems contended.
  • The first-layer root turns out to be not moved (already grown).

Grow is a non-mandatory operation. We can delay it.

Locks taken in this sysxct:

  • A special lock that protects first-layer root pointer in control block.
  • Page-lock of the current first-layer root (will be retired).

Definition at line 49 of file masstree_grow_impl.hpp.

#include <masstree_grow_impl.hpp>

Inheritance diagram for foedus::storage::masstree::GrowFirstLayerRoot:
Collaboration diagram for foedus::storage::masstree::GrowFirstLayerRoot:

Public Member Functions

 GrowFirstLayerRoot (thread::Thread *context, StorageId storage_id)
 
virtual ErrorCode run (xct::SysxctWorkspace *sysxct_workspace) override
 Execute the system transaction. More...
 

Public Attributes

thread::Thread *const context_
 Thread context. More...
 
StorageId storage_id_
 ID of the masstree storage to grow. More...
 

Constructor & Destructor Documentation

foedus::storage::masstree::GrowFirstLayerRoot::GrowFirstLayerRoot ( thread::Thread context,
StorageId  storage_id 
)
inline

Definition at line 55 of file masstree_grow_impl.hpp.

56  : xct::SysxctFunctor(),
57  context_(context),
58  storage_id_(storage_id) {
59  }
thread::Thread *const context_
Thread context.
StorageId storage_id_
ID of the masstree storage to grow.

Member Function Documentation

ErrorCode foedus::storage::masstree::GrowFirstLayerRoot::run ( xct::SysxctWorkspace sysxct_workspace)
overridevirtual

Execute the system transaction.

You should override this method.

Implements foedus::xct::SysxctFunctor.

Definition at line 119 of file masstree_grow_impl.cpp.

References ASSERT_ND, CHECK_ERROR_CODE, context_, foedus::Attachable< CONTROL_BLOCK >::get_control_block(), foedus::thread::Thread::get_engine(), foedus::storage::masstree::MasstreePage::get_foster_fence(), foedus::thread::Thread::get_global_volatile_page_resolver(), foedus::storage::masstree::MasstreePage::get_high_fence(), foedus::storage::masstree::MasstreePage::get_layer(), foedus::storage::masstree::MasstreePage::get_low_fence(), foedus::storage::masstree::grow_case_a_common(), foedus::storage::masstree::grow_case_b_common(), foedus::storage::masstree::MasstreePage::is_layer_root(), foedus::storage::masstree::MasstreePage::is_locked(), foedus::assorted::DumbSpinlock::is_locked_by_me(), foedus::storage::masstree::MasstreePage::is_moved(), foedus::storage::VolatilePagePointer::is_null(), foedus::storage::masstree::MasstreePage::is_retired(), foedus::kErrorCodeOk, storage_id_, foedus::thread::Thread::sysxct_page_lock(), foedus::assorted::DumbSpinlock::try_lock(), and foedus::storage::DualPagePointer::volatile_pointer_.

119  {
120  MasstreeStorage storage(context_->get_engine(), storage_id_);
121  auto* cb = storage.get_control_block();
122 
123  // Take the special lock in control block.
124  // This locking happens outside of the normal lock/commit protocol.
125  // In order to avoid contention, we take the lock only when it looks available.
126  if (cb->first_root_locked_) {
127  DVLOG(0) << "Interesting. other thread seems growing the first-layer. let him do that";
128  return kErrorCodeOk;
129  }
130  // Always a try-lock to avoid deadlock. Remember, this is a special lock!
131  assorted::DumbSpinlock first_root_lock(&cb->first_root_locked_, false);
132  if (!first_root_lock.try_lock()) {
133  DVLOG(0) << "Interesting. other thread is growing the first-layer. let him do that";
134  return kErrorCodeOk;
135  }
136  ASSERT_ND(first_root_lock.is_locked_by_me());
137 
138  const auto& resolver = context_->get_global_volatile_page_resolver();
139  DualPagePointer* pointer = &cb->root_page_pointer_;
140  ASSERT_ND(!pointer->volatile_pointer_.is_null());
141  Page* cur_root_page = resolver.resolve_offset(pointer->volatile_pointer_);
142  MasstreePage* cur_root = reinterpret_cast<MasstreePage*>(cur_root_page);
143  ASSERT_ND(cur_root->is_layer_root());
144  ASSERT_ND(cur_root->get_layer() == 0);
145 
146  CHECK_ERROR_CODE(context_->sysxct_page_lock(sysxct_workspace, cur_root_page));
147  ASSERT_ND(cur_root->is_locked());
148  // After locking the page, check the state of the page
149  if (!cur_root->is_moved()) {
150  DVLOG(0) << "Interesting. concurrent thread has already grown it.";
151  return kErrorCodeOk;
152  }
153 
154  ASSERT_ND(!cur_root->is_retired());
155  if (cur_root->get_foster_fence() == cur_root->get_low_fence()
156  || cur_root->get_foster_fence() == cur_root->get_high_fence()) {
157  DVLOG(0) << "Adopting Empty-range child for first layer root. storage_id=" << storage_id_;
158  grow_case_a_common(context_, pointer, cur_root);
159  } else {
160  LOG(INFO) << "Growing first layer root. storage_id=" << storage_id_;
161  CHECK_ERROR_CODE(grow_case_b_common(context_, pointer, cur_root));
162  }
163 
164  return kErrorCodeOk;
165 }
const memory::GlobalVolatilePageResolver & get_global_volatile_page_resolver() const
Returns the page resolver to convert page ID to page pointer.
Definition: thread.cpp:125
void grow_case_a_common(thread::Thread *context, DualPagePointer *pointer, MasstreePage *cur_root)
Engine * get_engine() const
Definition: thread.cpp:52
0 means no-error.
Definition: error_code.hpp:87
ErrorCode sysxct_page_lock(xct::SysxctWorkspace *sysxct_workspace, storage::Page *page)
Takes a page lock in the same page for a sysxct running under this thread.
ErrorCode grow_case_b_common(thread::Thread *context, DualPagePointer *pointer, MasstreePage *cur_root)
#define CHECK_ERROR_CODE(x)
This macro calls x and checks its returned error code.
Definition: error_code.hpp:155
#define ASSERT_ND(x)
A warning-free wrapper macro of assert() that has no performance effect in release mode even when 'x'...
Definition: assert_nd.hpp:72
thread::Thread *const context_
Thread context.
StorageId storage_id_
ID of the masstree storage to grow.

Here is the call graph for this function:

Member Data Documentation

thread::Thread* const foedus::storage::masstree::GrowFirstLayerRoot::context_

Thread context.

Definition at line 51 of file masstree_grow_impl.hpp.

Referenced by run().

StorageId foedus::storage::masstree::GrowFirstLayerRoot::storage_id_

ID of the masstree storage to grow.

Definition at line 53 of file masstree_grow_impl.hpp.

Referenced by run().


The documentation for this struct was generated from the following files: