libfoedus-core
FOEDUS Core Library
foedus::log::MetaLogBuffer Class Reference

A single log buffer for metadata (eg create/drop storage). More...

Detailed Description

A single log buffer for metadata (eg create/drop storage).

Per-engine/storage operations such as CREATE/DROP STORAGE are logged differently. They are always separated from usual transactions and also written to a separate log file. Metadata operation is rare, so we don't optimize the code here. Instead, this class is much simpler than ThreadLogBuffer. More precisely:

  • Metadata operation is always the only operation in the transaction.
  • Metadata operation never gets aborted.
  • Every epoch has at most one metadata operation; for each metadata operation, we immediately advance epoch.
  • Each metadata log is immediately synched to log file.
Shared log buffer
Unlike ThreadLogBuffer, this buffer is placed in shared memory and every thread in every SOC can write to this log buffer with mutex.

Definition at line 91 of file meta_log_buffer.hpp.

#include <meta_log_buffer.hpp>

Inheritance diagram for foedus::log::MetaLogBuffer:
Collaboration diagram for foedus::log::MetaLogBuffer:

Public Member Functions

 MetaLogBuffer ()
 
 MetaLogBuffer (Engine *engine, MetaLogControlBlock *block)
 
void commit (BaseLogType *metalog, Epoch *commit_epoch)
 Synchronously writes out the given log to metadata log file. More...
 
- Public Member Functions inherited from foedus::Attachable< MetaLogControlBlock >
 Attachable ()
 
 Attachable (Engine *engine)
 
 Attachable (Engine *engine, MetaLogControlBlock *control_block)
 
 Attachable (MetaLogControlBlock *control_block)
 
 Attachable (const Attachable &other)
 
virtual ~Attachable ()
 
Attachableoperator= (const Attachable &other)
 
virtual void attach (MetaLogControlBlock *control_block)
 Attaches to the given shared memory. More...
 
bool is_attached () const
 Returns whether the object has been already attached to some shared memory. More...
 
MetaLogControlBlock * get_control_block () const
 
Engineget_engine () const
 
void set_engine (Engine *engine)
 

Friends

std::ostream & operator<< (std::ostream &o, const MetaLogBuffer &v)
 

Additional Inherited Members

- Protected Attributes inherited from foedus::Attachable< MetaLogControlBlock >
Engineengine_
 Most attachable object stores an engine pointer (local engine), so we define it here. More...
 
MetaLogControlBlock * control_block_
 The shared data on shared memory that has been initialized in some SOC or master engine. More...
 

Constructor & Destructor Documentation

foedus::log::MetaLogBuffer::MetaLogBuffer ( )
inline

Definition at line 93 of file meta_log_buffer.hpp.

93 : Attachable<MetaLogControlBlock>() {}
foedus::log::MetaLogBuffer::MetaLogBuffer ( Engine engine,
MetaLogControlBlock block 
)
inline

Definition at line 94 of file meta_log_buffer.hpp.

95  : Attachable<MetaLogControlBlock>(engine, block) {}

Member Function Documentation

void foedus::log::MetaLogBuffer::commit ( BaseLogType metalog,
Epoch commit_epoch 
)

Synchronously writes out the given log to metadata log file.

Definition at line 33 of file meta_log_buffer.cpp.

References foedus::xct::XctManager::advance_current_global_epoch(), ASSERT_ND, foedus::Attachable< MetaLogControlBlock >::control_block_, foedus::Attachable< MetaLogControlBlock >::engine_, foedus::xct::XctManager::get_current_global_epoch(), foedus::log::LogHeader::get_kind(), foedus::Engine::get_xct_manager(), foedus::log::BaseLogType::header_, foedus::log::kEngineLogs, foedus::log::kStorageLogs, foedus::log::LogHeader::log_length_, foedus::assorted::memory_fence_acquire(), foedus::xct::XctId::set_epoch(), and foedus::log::LogHeader::xct_id_.

Referenced by foedus::storage::StorageManagerPimpl::create_storage_and_log(), foedus::storage::StorageManagerPimpl::drop_storage(), and foedus::storage::sequential::SequentialStoragePimpl::truncate().

33  {
34  LOG(INFO) << "Writing a metadata log. " << metalog->header_ << "...";
35  {
36  soc::SharedMutexScope scope(&control_block_->mutex_);
37  // access to metadata buffer is mutex-protected
38  ASSERT_ND(control_block_->buffer_used_ == 0);
39 
40  // To avoid mixing with normal operations on the storage in this epoch, advance epoch.
41  // This happens within the mutex, so this is assured to be the only metadata log in the epoch.
43  *commit_epoch = engine_->get_xct_manager()->get_current_global_epoch();
44  LOG(INFO) << "Issued an epoch for the metadata log: " << *commit_epoch << "...";
45  metalog->header_.xct_id_.set_epoch(*commit_epoch);
46 
47  // copy to buffer_ first
48  ASSERT_ND(metalog->header_.get_kind() == kStorageLogs
49  || metalog->header_.get_kind() == kEngineLogs);
50  std::memcpy(control_block_->buffer_, metalog, metalog->header_.log_length_);
51 
52  // then write buffer_used_ after fence for the logger to safely read it
53  // Also, do it within mutex to avoid lost signal
54  {
55  // Wakeup the logger
56  control_block_->buffer_used_ = metalog->header_.log_length_;
57  control_block_->logger_wakeup_.signal();
58  }
59 
60  // Simply sleep for a while. Metadata logging is not so often, so we can simply spin
61  // with a short sleep.
62  while (control_block_->buffer_used_ > 0) {
63  std::this_thread::sleep_for(std::chrono::microseconds(100));
65  }
66  }
67  LOG(INFO) << "Wrote a metadata log. " << metalog->header_ << "...";
68 }
Epoch get_current_global_epoch() const
Returns the current global epoch, the epoch a newly started transaction will be in.
Engine * engine_
Most attachable object stores an engine pointer (local engine), so we define it here.
Definition: attachable.hpp:107
MetaLogControlBlock * control_block_
The shared data on shared memory that has been initialized in some SOC or master engine.
Definition: attachable.hpp:111
engine targetted logs
Definition: log_type.hpp:107
xct::XctManager * get_xct_manager() const
See Transaction Manager.
Definition: engine.cpp:61
void advance_current_global_epoch()
Requests to advance the current global epoch as soon as possible and blocks until it actually does...
storage targetted logs
Definition: log_type.hpp:105
void memory_fence_acquire()
Equivalent to std::atomic_thread_fence(std::memory_order_acquire).
#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

Here is the call graph for this function:

Here is the caller graph for this function:

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  o,
const MetaLogBuffer v 
)
friend

Definition at line 70 of file meta_log_buffer.cpp.

70  {
71  o << "<MetaLogBuffer>"
72  << "<buffer_used_>" << v.control_block_->buffer_used_ << "</buffer_used_>"
73  << "<oldest_offset_>" << v.control_block_->oldest_offset_ << "</oldest_offset_>"
74  << "<durable_offset_>" << v.control_block_->durable_offset_ << "</durable_offset_>"
75  << "</MetaLogBuffer>";
76  return o;
77 }

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