libfoedus-core
FOEDUS Core Library
Physical-only, short-living system transactions.

Detailed Description

A system transaction is a special transaction that changes nothing logically. It changes only physical structures. For example, it splits a page or expand a physical record without changing their logical data to help normal, user transactions (Xct).

There are several prior work in databases to use system tranasctions. System transactions in FOEDUS differ a bit from others in the following sense:

System transactions are not exposed to users, so the whole file is _impl.

Collaboration diagram for Physical-only, short-living system transactions.:

Classes

struct  foedus::xct::SysxctFunctor
 A functor representing the logic in a system transaction via virtual-function. More...
 
struct  foedus::xct::SysxctLockEntry::LessThan
 for std::binary_search() etc without creating the object More...
 
struct  foedus::xct::SysxctLockEntry
 An entry in CLL/RLL for system transactions. More...
 
struct  foedus::xct::SysxctWorkspace
 Per-thread reused work memory for system transactions. More...
 

Functions

template<typename MCS_ADAPTOR , typename ENCLOSURE_RELEASE_ALL_LOCKS_FUNCTOR >
ErrorCode foedus::xct::run_nested_sysxct_impl (SysxctFunctor *functor, MCS_ADAPTOR mcs_adaptor, uint32_t max_retries, SysxctWorkspace *workspace, UniversalLockId enclosing_max_lock_id, ENCLOSURE_RELEASE_ALL_LOCKS_FUNCTOR enclosure_release_all_locks_functor)
 Runs a system transaction nested in a user transaction. More...
 

Function Documentation

template<typename MCS_ADAPTOR , typename ENCLOSURE_RELEASE_ALL_LOCKS_FUNCTOR >
ErrorCode foedus::xct::run_nested_sysxct_impl ( SysxctFunctor functor,
MCS_ADAPTOR  mcs_adaptor,
uint32_t  max_retries,
SysxctWorkspace workspace,
UniversalLockId  enclosing_max_lock_id,
ENCLOSURE_RELEASE_ALL_LOCKS_FUNCTOR  enclosure_release_all_locks_functor 
)
inline

Runs a system transaction nested in a user transaction.

Parameters
[in]contextthe enclosing user transaction's thread.
[in]functorthe functor content of the system transaction.
[in]mcs_adaptorabstracts MCS interface.
[in]max_retriesHow many times at most to retry the same system transaction if it aborts. 0 means no retries (default behavior). It retries when the return value of the functor was RaceAbort or LockAbort. Other return values are immediately propagated.
[in,out]workspaceResource for system transaction.
[in]enclosing_max_lock_idlargest lock-id held by outer transaction.
[in]enclosure_release_all_locks_functorwhen the system transaction gets a race abort, it might call this back to release all locks in the outer transaction.
Returns
Propagates the return value of the functor.

System transactions are much more casual transactions than user transactions. They are begun/committed for a small function or a few. In order to make sure we release related resources in SysxctWorkspace, we should always use this function.

This function is for the majority of system transaction usecases where a normal user transaction needs to physically change some page/record and invokes a system transaction.

Definition at line 496 of file sysxct_impl.hpp.

References foedus::kErrorCodeXctLockAbort, foedus::kErrorCodeXctRaceAbort, foedus::kErrorCodeXctTwoSysXcts, foedus::xct::kNullUniversalLockId, foedus::xct::SysxctWorkspace::lock_list_, foedus::xct::SysxctFunctor::run(), foedus::xct::SysxctWorkspace::running_sysxct_, and UNLIKELY.

Referenced by foedus::thread::ThreadPimpl::run_nested_sysxct().

502  {
503  if (UNLIKELY(workspace->running_sysxct_)) {
504  // so far each thread can convey only one system transaction.
505  // this is 1) to reuse SysxctWorkspace, and 2) to avoid deadlocks.
507  }
508 
509  workspace->running_sysxct_ = true;
510  uint32_t cur_retries = 0;
511  auto* lock_list = &(workspace->lock_list_);
512  lock_list->clear_entries(enclosing_max_lock_id);
513  while (true) {
514  ErrorCode ret = functor->run(workspace);
515  // In any case, release all locks.
516  lock_list->release_all_locks(mcs_adaptor);
517 
518  // The first run of the system transaction takes locks only in "try" mode
519  // to avoid deadlocks. They thus have higher chance to get aborted.
521  // consider retry
522  if (cur_retries < max_retries) {
523  // When we retry, we release all locks in _outer_ transaction to eliminate the
524  // chance of deadlocks. Then the next run of the system transaction can
525  // take locks unconditionally, waiting for an arbitrary period.
526  if (enclosing_max_lock_id != kNullUniversalLockId) {
527  enclosure_release_all_locks_functor();
528  lock_list->compress_entries(kNullUniversalLockId);
529  enclosing_max_lock_id = kNullUniversalLockId;
530  // Now the next run, helped by inherited entries, should be in unconditional mode
531  }
532  ++cur_retries;
533  continue;
534  }
535  }
536 
537  workspace->running_sysxct_ = false;
538  return ret;
539  }
540 }
0x0AA1 : "XCTION : Lock acquire failed." .
Definition: error_code.hpp:206
#define UNLIKELY(x)
Hints that x is highly likely false.
Definition: compiler.hpp:104
0x0A05 : "XCTION : Aborted a transaction because of a race condition. This is an expected error in hi...
Definition: error_code.hpp:200
ErrorCode
Enum of error codes defined in error_code.xmacro.
Definition: error_code.hpp:85
const UniversalLockId kNullUniversalLockId
This never points to a valid lock, and also evaluates less than any vaild alocks. ...
Definition: xct_id.hpp:137
0x0AA4 : "XCTION : The thread is already running a system transaction. This means an incorrect use of...
Definition: error_code.hpp:209

Here is the call graph for this function:

Here is the caller graph for this function: