libfoedus-core
FOEDUS Core Library
|
A thread-local log buffer. More...
A thread-local log buffer.
This is a private implementation-details of Log Manager, thus file name ends with _impl. Do not include this header from a client program unless you know what you are doing.
Definition at line 266 of file thread_log_buffer.hpp.
#include <thread_log_buffer.hpp>
Classes | |
struct | OffsetRange |
Public Member Functions | |
ThreadLogBuffer (Engine *engine, thread::ThreadId thread_id) | |
ErrorStack | initialize_once () override |
ErrorStack | uninitialize_once () override |
ThreadLogBuffer ()=delete | |
ThreadLogBuffer (const ThreadLogBuffer &other)=delete | |
ThreadLogBuffer & | operator= (const ThreadLogBuffer &other)=delete |
void | assert_consistent () const |
Only for Debug-assertion. More... | |
thread::ThreadId | get_thread_id () const |
char * | reserve_new_log (uint16_t log_length) __attribute__((always_inline)) |
Reserves a space for a new (uncommitted) log entry at the tail. More... | |
uint64_t | head_to_tail_distance () const __attribute__((always_inline)) |
void | publish_committed_log (Epoch commit_epoch) __attribute__((always_inline)) |
Called when the current transaction is successfully committed. More... | |
void | discard_current_xct_log () |
Called when the current transaction aborts. More... | |
Epoch | get_last_epoch () const |
void | wait_for_space (uint16_t required_space) |
Called when we have to wait till offset_head_ advances so that we can put new logs. More... | |
uint64_t | get_offset_head () const |
This marks the position where log entries start. More... | |
uint64_t | get_offset_durable () const |
This marks the position upto which the log writer durably wrote out to log files. More... | |
uint64_t | get_offset_committed () const |
This marks the position upto which transaction logs are committed by the thread. More... | |
uint64_t | get_offset_tail () const |
The current cursor to which next log will be written. More... | |
const ThreadLogBufferMeta & | get_meta () const |
Returns the state of this buffer. More... | |
const char * | get_buffer () const |
OffsetRange | get_logs_to_write (Epoch written_epoch) |
Returns begin/end offsets of logs in the given epoch. More... | |
void | on_log_written (Epoch written_epoch) |
Called when the logger wrote out all logs in the given epoch, advancing oldest_mark_index_. More... | |
![]() | |
DefaultInitializable () | |
virtual | ~DefaultInitializable () |
DefaultInitializable (const DefaultInitializable &)=delete | |
DefaultInitializable & | operator= (const DefaultInitializable &)=delete |
ErrorStack | initialize () override final |
Typical implementation of Initializable::initialize() that provides initialize-once semantics. More... | |
ErrorStack | uninitialize () override final |
Typical implementation of Initializable::uninitialize() that provides uninitialize-once semantics. More... | |
bool | is_initialized () const override final |
Returns whether the object has been already initialized or not. More... | |
![]() | |
virtual | ~Initializable () |
Static Public Member Functions | |
static uint64_t | distance (uint64_t buffer_size, uint64_t from, uint64_t to) __attribute__((always_inline)) |
Subtract operator, considering wrapping around. More... | |
static void | advance (uint64_t buffer_size, uint64_t *target, uint64_t amount) __attribute__((always_inline)) |
Addition operator, considering wrapping around. More... | |
Friends | |
class | Logger |
std::ostream & | operator<< (std::ostream &o, const ThreadLogBuffer &v) |
foedus::log::ThreadLogBuffer::ThreadLogBuffer | ( | Engine * | engine, |
thread::ThreadId | thread_id | ||
) |
Definition at line 104 of file thread_log_buffer.cpp.
References foedus::log::ThreadLogBufferMeta::thread_id_.
|
delete |
|
delete |
|
inlinestatic |
Addition operator, considering wrapping around.
Definition at line 284 of file thread_log_buffer.hpp.
References ASSERT_ND.
Referenced by reserve_new_log().
|
inline |
Only for Debug-assertion.
This method must be called by the worker thread itself. When logger calls it, it must make sure the worker is not modifying anything concurrently.
Definition at line 306 of file thread_log_buffer.hpp.
References foedus::log::ThreadLogBufferMeta::assert_consistent().
Referenced by wait_for_space().
|
inline |
Called when the current transaction aborts.
Definition at line 358 of file thread_log_buffer.hpp.
References foedus::log::ThreadLogBufferMeta::offset_committed_, and foedus::log::ThreadLogBufferMeta::offset_tail_.
Referenced by foedus::xct::XctManagerPimpl::abort_xct(), and foedus::xct::XctManagerPimpl::precommit_xct_readwrite().
|
inlinestatic |
Subtract operator, considering wrapping around.
Definition at line 274 of file thread_log_buffer.hpp.
References ASSERT_ND.
Referenced by head_to_tail_distance().
|
inline |
Definition at line 383 of file thread_log_buffer.hpp.
|
inline |
Definition at line 361 of file thread_log_buffer.hpp.
References foedus::log::ThreadLogBufferMeta::current_mark_index_, foedus::log::ThreadEpockMark::new_epoch_, and foedus::log::ThreadLogBufferMeta::thread_epoch_marks_.
Referenced by publish_committed_log().
ThreadLogBuffer::OffsetRange foedus::log::ThreadLogBuffer::get_logs_to_write | ( | Epoch | written_epoch | ) |
Returns begin/end offsets of logs in the given epoch.
It might be empty (0/0).
Definition at line 234 of file thread_log_buffer.cpp.
References ASSERT_ND, foedus::log::ThreadLogBuffer::OffsetRange::begin_, foedus::log::ThreadLogBufferMeta::current_mark_index_, foedus::log::ThreadLogBuffer::OffsetRange::end_, foedus::log::ThreadLogBufferMeta::increment_mark_index(), foedus::log::ThreadLogBufferMeta::kMaxNonDurableEpochs, foedus::assorted::memory_fence_acq_rel(), foedus::assorted::memory_fence_acquire(), foedus::log::ThreadEpockMark::new_epoch_, foedus::log::ThreadEpockMark::offset_begin_, foedus::log::ThreadLogBufferMeta::offset_committed_, foedus::log::ThreadLogBufferMeta::offset_durable_, foedus::log::ThreadEpockMark::offset_end_, foedus::log::ThreadLogBufferMeta::oldest_mark_index_, and foedus::log::ThreadLogBufferMeta::thread_epoch_marks_.
|
inline |
Returns the state of this buffer.
Definition at line 382 of file thread_log_buffer.hpp.
|
inline |
This marks the position upto which transaction logs are committed by the thread.
Log writers can safely read log entries and write them to log files up to this place. When the transaction commits, this value is advanced by the thread. The only possible update pattern to this variable is advance by this thread. Thus, the log writer can safely read this variable without any fence or lock thanks to regular (either old value or new value, never garbage) read of 64-bit.
Definition at line 375 of file thread_log_buffer.hpp.
References foedus::log::ThreadLogBufferMeta::offset_committed_.
Referenced by foedus::xct::XctManagerPimpl::begin_xct(), and foedus::xct::XctManagerPimpl::precommit_xct_readonly().
|
inline |
This marks the position upto which the log writer durably wrote out to log files.
Everything after this position must not be discarded because they are not yet durable. When the log writer reads log entries after here, writes them to log file, and calls fsync, this variable is advanced by the log writer. This variable is read by this thread to check the end of the circular buffer.
Definition at line 372 of file thread_log_buffer.hpp.
References foedus::log::ThreadLogBufferMeta::offset_durable_.
|
inline |
This marks the position where log entries start.
This private log buffer is a circular buffer where the head is eaten by log gleaner. However, log gleaner is okay to get behind, reading from log file instead (but slower). Thus, offset_head_ is advanced either by log gleaner or this thread. If the latter happens, log gleaner has to give up using in-memory logs and instead read from log files.
Definition at line 369 of file thread_log_buffer.hpp.
References foedus::log::ThreadLogBufferMeta::offset_head_.
|
inline |
The current cursor to which next log will be written.
This is the location the current transaction of this thread is writing to before commit. When the transaction commits, offset_committed_ catches up with this. When the transaction aborts, this value rolls back to offset_committed_. Only this thread reads/writes to this variable. No other threads access this.
Definition at line 378 of file thread_log_buffer.hpp.
References foedus::log::ThreadLogBufferMeta::offset_tail_.
Referenced by foedus::xct::XctManagerPimpl::begin_xct(), and foedus::xct::XctManagerPimpl::precommit_xct_readonly().
|
inline |
Definition at line 311 of file thread_log_buffer.hpp.
References foedus::log::ThreadLogBufferMeta::thread_id_.
|
inline |
Definition at line 338 of file thread_log_buffer.hpp.
References foedus::log::ThreadLogBufferMeta::buffer_size_, distance(), foedus::log::ThreadLogBufferMeta::offset_head_, and foedus::log::ThreadLogBufferMeta::offset_tail_.
Referenced by reserve_new_log(), and wait_for_space().
|
overridevirtual |
Implements foedus::DefaultInitializable.
Definition at line 110 of file thread_log_buffer.cpp.
References foedus::log::ThreadLogBufferMeta::buffer_size_, foedus::log::ThreadLogBufferMeta::buffer_size_safe_, foedus::log::ThreadLogBufferMeta::current_mark_index_, foedus::memory::AlignedMemorySlice::get_block(), foedus::memory::NumaNodeMemory::get_core_memory(), foedus::savepoint::SavepointManager::get_initial_current_epoch(), foedus::savepoint::SavepointManager::get_initial_durable_epoch(), foedus::memory::EngineMemory::get_local_memory(), foedus::memory::NumaCoreMemory::get_log_buffer_memory(), foedus::Engine::get_memory_manager(), foedus::Engine::get_savepoint_manager(), foedus::memory::AlignedMemorySlice::get_size(), foedus::kRetOk, foedus::log::ThreadLogBufferMeta::offset_committed_, foedus::log::ThreadLogBufferMeta::offset_durable_, foedus::log::ThreadLogBufferMeta::offset_head_, foedus::log::ThreadLogBufferMeta::offset_tail_, foedus::log::ThreadLogBufferMeta::oldest_mark_index_, foedus::log::ThreadLogBufferMeta::thread_epoch_marks_, and foedus::log::ThreadLogBufferMeta::thread_id_.
void foedus::log::ThreadLogBuffer::on_log_written | ( | Epoch | written_epoch | ) |
Called when the logger wrote out all logs in the given epoch, advancing oldest_mark_index_.
Definition at line 303 of file thread_log_buffer.cpp.
References ASSERT_ND, foedus::log::ThreadLogBufferMeta::current_mark_index_, foedus::log::ThreadLogBufferMeta::increment_mark_index(), foedus::log::ThreadEpockMark::new_epoch_, foedus::log::ThreadEpockMark::offset_begin_, foedus::log::ThreadLogBufferMeta::offset_durable_, foedus::log::ThreadEpockMark::offset_end_, foedus::log::ThreadLogBufferMeta::oldest_mark_index_, and foedus::log::ThreadLogBufferMeta::thread_epoch_marks_.
|
delete |
|
inline |
Called when the current transaction is successfully committed.
Definition at line 345 of file thread_log_buffer.hpp.
References ASSERT_ND, get_last_epoch(), foedus::log::ThreadLogBufferMeta::offset_committed_, foedus::log::ThreadLogBufferMeta::offset_tail_, and UNLIKELY.
Referenced by foedus::xct::XctManagerPimpl::precommit_xct_readwrite().
|
inline |
Reserves a space for a new (uncommitted) log entry at the tail.
[in] | log_length | byte size of the log. You have to give it beforehand. |
If the circular buffer's tail reaches the head, this method might block. But it will be rare as we release a large region of buffer at each time.
Definition at line 320 of file thread_log_buffer.hpp.
References advance(), ASSERT_ND, foedus::log::ThreadLogBufferMeta::buffer_size_, foedus::log::ThreadLogBufferMeta::buffer_size_safe_, head_to_tail_distance(), foedus::log::ThreadLogBufferMeta::offset_tail_, UNLIKELY, and wait_for_space().
Referenced by foedus::storage::sequential::SequentialStorage::append_record(), foedus::storage::masstree::MasstreeStoragePimpl::delete_general(), foedus::storage::hash::HashStoragePimpl::delete_record(), foedus::storage::masstree::MasstreeStoragePimpl::increment_general(), foedus::storage::array::ArrayStoragePimpl::increment_record(), foedus::storage::hash::HashStoragePimpl::increment_record(), foedus::storage::array::ArrayStoragePimpl::increment_record_oneshot(), foedus::storage::masstree::MasstreeStoragePimpl::insert_general(), foedus::storage::hash::HashStoragePimpl::insert_record(), foedus::storage::masstree::MasstreeStoragePimpl::overwrite_general(), foedus::storage::array::ArrayStoragePimpl::overwrite_record(), foedus::storage::hash::HashStoragePimpl::overwrite_record(), foedus::storage::array::ArrayStoragePimpl::overwrite_record_primitive(), foedus::storage::masstree::MasstreeStoragePimpl::upsert_general(), and foedus::storage::hash::HashStoragePimpl::upsert_record().
|
overridevirtual |
Implements foedus::DefaultInitializable.
Definition at line 131 of file thread_log_buffer.cpp.
References foedus::kRetOk.
void foedus::log::ThreadLogBuffer::wait_for_space | ( | uint16_t | required_space | ) |
Called when we have to wait till offset_head_ advances so that we can put new logs.
Definition at line 136 of file thread_log_buffer.cpp.
References assert_consistent(), ASSERT_ND, foedus::log::ThreadLogBufferMeta::buffer_size_safe_, foedus::log::LogOptions::emulation_, foedus::Engine::get_log_manager(), foedus::Engine::get_options(), head_to_tail_distance(), foedus::EngineOptions::log_, foedus::assorted::memory_fence_acquire(), foedus::assorted::memory_fence_release(), foedus::fs::DeviceEmulationOptions::null_device_, foedus::log::ThreadLogBufferMeta::offset_committed_, foedus::log::ThreadLogBufferMeta::offset_durable_, foedus::log::ThreadLogBufferMeta::offset_head_, foedus::log::ThreadLogBufferMeta::thread_id_, and foedus::log::LogManager::wakeup_loggers().
Referenced by reserve_new_log().
|
friend |
Definition at line 268 of file thread_log_buffer.hpp.
|
friend |
Definition at line 330 of file thread_log_buffer.cpp.