libfoedus-core
FOEDUS Core Library
foedus::xct::InCommitEpochGuard Struct Reference

Automatically sets in-commit-epoch with appropriate fence during pre-commit protocol. More...

Detailed Description

Automatically sets in-commit-epoch with appropriate fence during pre-commit protocol.

If a transaction is currently committing with some log to publish, in-commit epoch gives the conservative estimate (although usually exact) of the commit epoch.

This class guards the range from a read-write transaction starts committing until it publishes or discards the logs.

This is used by the epoch chime to tell if it can assume that this transaction already got a new epoch or not in commit phase. If it's not the case, the chime will spin on this until this returns 0 or epoch that is enough recent. Without this mechanisim, we will get a too conservative value of "min(ctid_w)" (Sec 4.10 [TU2013]) when there are some threads that are either idle or spending long time before/after commit.

The transaction takes an appropriate fence before updating this value so that followings are guaranteed:

  • When this returns 0, this transaction will not publish any more log without getting recent epoch (see destructor of InCommitEpochGuard).
  • If this returns epoch-X, the transaction will never publish a log whose epoch is less than X. (this is assured by taking InCommitEpochGuard BEFORE the first fence in commit)
  • As an added guarantee, this value will be updated as soon as the commit phase ends, so the chime can safely spin on this value.
Note
A similar protocol seems implemented in MIT SILO, too. See how "txn_logger::advance_system_sync_epoch" updates per_thread_sync_epochs_ and system_sync_epoch_. However, not quite sure about their implementation. Will ask.
See also
foedus::xct::XctManagerPimpl::precommit_xct_readwrite()

Definition at line 58 of file in_commit_epoch_guard.hpp.

#include <in_commit_epoch_guard.hpp>

Collaboration diagram for foedus::xct::InCommitEpochGuard:

Public Member Functions

 InCommitEpochGuard (Epoch *in_commit_epoch_address, Epoch conservative_epoch)
 
 ~InCommitEpochGuard ()
 

Public Attributes

Epoch *const in_commit_epoch_address_
 

Constructor & Destructor Documentation

foedus::xct::InCommitEpochGuard::InCommitEpochGuard ( Epoch in_commit_epoch_address,
Epoch  conservative_epoch 
)
inline

Definition at line 59 of file in_commit_epoch_guard.hpp.

References ASSERT_ND, in_commit_epoch_address_, and foedus::INVALID_EPOCH.

60  : in_commit_epoch_address_(in_commit_epoch_address) {
62  *in_commit_epoch_address_ = conservative_epoch;
63  // We assume the caller of this constructer puts a release or ack_rel fence right after this.
64  // So, we don't bother putting the fence here.
65  // assorted::memory_fence_release();
66  }
const Epoch INVALID_EPOCH
A constant epoch object that represents an invalid epoch.
Definition: epoch.hpp:204
#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
foedus::xct::InCommitEpochGuard::~InCommitEpochGuard ( )
inline

Definition at line 67 of file in_commit_epoch_guard.hpp.

References in_commit_epoch_address_, foedus::INVALID_EPOCH, and foedus::assorted::memory_fence_release().

67  {
68  // prohibit reordering any other change BEFORE the update to in_commit_epoch_.
69  // This is to satisfy the first requirement:
70  // ("When this returns 0, this transaction will not publish any more log without getting
71  // recent epoch").
72  // Without this fence, chime can potentially miss the log that has been just published
73  // with the old epoch.
76  // We can also call another memory_order_release here to immediately publish it,
77  // but it's anyway rare. The spinning chime will eventually get the update, so no need.
78  // In non-TSO architecture, this also saves some overhead in critical path.
79  }
const Epoch INVALID_EPOCH
A constant epoch object that represents an invalid epoch.
Definition: epoch.hpp:204
void memory_fence_release()
Equivalent to std::atomic_thread_fence(std::memory_order_release).

Here is the call graph for this function:

Member Data Documentation

Epoch* const foedus::xct::InCommitEpochGuard::in_commit_epoch_address_

Definition at line 80 of file in_commit_epoch_guard.hpp.

Referenced by InCommitEpochGuard(), and ~InCommitEpochGuard().


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