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

A view of Logger object for other SOCs and master engine. More...

Detailed Description

A view of Logger object for other SOCs and master engine.

Definition at line 35 of file logger_ref.hpp.

#include <logger_ref.hpp>

Inheritance diagram for foedus::log::LoggerRef:
Collaboration diagram for foedus::log::LoggerRef:

Public Member Functions

 LoggerRef ()
 
 LoggerRef (Engine *engine, LoggerControlBlock *block, LoggerId id, uint16_t numa_node, uint16_t in_node_ordinal)
 
Epoch get_durable_epoch () const
 Returns this logger's durable epoch. More...
 
void wakeup ()
 Wakes up this logger if it is sleeping. More...
 
void wakeup_for_durable_epoch (Epoch desired_durable_epoch)
 Wakes up this logger if its durable_epoch has not reached the given epoch yet. More...
 
void copy_logger_state (savepoint::Savepoint *new_savepoint) const
 Called from log manager's copy_logger_states. More...
 
void add_epoch_history (const EpochMarkerLogType &epoch_marker)
 Append a new epoch history. More...
 
LogRange get_log_range (Epoch prev_epoch, Epoch until_epoch)
 Constructs the range of log entries that represent the given epoch ranges. More...
 
- Public Member Functions inherited from foedus::Attachable< LoggerControlBlock >
 Attachable ()
 
 Attachable (Engine *engine)
 
 Attachable (Engine *engine, LoggerControlBlock *control_block)
 
 Attachable (LoggerControlBlock *control_block)
 
 Attachable (const Attachable &other)
 
virtual ~Attachable ()
 
Attachableoperator= (const Attachable &other)
 
virtual void attach (LoggerControlBlock *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...
 
LoggerControlBlock * get_control_block () const
 
Engineget_engine () const
 
void set_engine (Engine *engine)
 

Protected Attributes

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

Constructor & Destructor Documentation

foedus::log::LoggerRef::LoggerRef ( )

Definition at line 28 of file logger_ref.cpp.

28 : Attachable<LoggerControlBlock>() {}
foedus::log::LoggerRef::LoggerRef ( Engine engine,
LoggerControlBlock block,
LoggerId  id,
uint16_t  numa_node,
uint16_t  in_node_ordinal 
)

Definition at line 29 of file logger_ref.cpp.

References id_, in_node_ordinal_, and numa_node_.

35  : Attachable<LoggerControlBlock>(engine, block) {
36  id_ = id;
37  numa_node_ = numa_node;
38  in_node_ordinal_ = in_node_ordinal;
39 }

Member Function Documentation

void foedus::log::LoggerRef::add_epoch_history ( const EpochMarkerLogType epoch_marker)

Append a new epoch history.

Definition at line 65 of file logger_ref.cpp.

References ASSERT_ND, foedus::Attachable< LoggerControlBlock >::control_block_, id_, foedus::log::LoggerControlBlock::kMaxEpochHistory, foedus::log::EpochMarkerLogType::new_epoch_, and foedus::log::EpochMarkerLogType::old_epoch_.

Referenced by foedus::log::EpochMarkerLogType::apply_engine().

65  {
66  soc::SharedMutexScope scope(&control_block_->epoch_history_mutex_);
67  uint32_t tail_index = control_block_->get_tail_epoch_history();
68  ASSERT_ND(control_block_->epoch_history_count_ == 0
69  || control_block_->epoch_histories_[tail_index].new_epoch_ == epoch_marker.old_epoch_);
70  // the first epoch marker is allowed only if it's a dummy marker.
71  // this simplifies the detection of first epoch marker
72  if (!control_block_->is_epoch_history_empty()
73  && epoch_marker.old_epoch_ == epoch_marker.new_epoch_) {
74  LOG(INFO) << "Ignored a dummy epoch marker while replaying epoch marker log on Logger-"
75  << id_ << ". marker=" << epoch_marker;
76  } else {
77  if (control_block_->epoch_history_count_ >= LoggerControlBlock::kMaxEpochHistory) {
78  // TASK(Hideaki) To avoid this, we should maintain sparse history, like one history per
79  // tens of epochs. So far kMaxEpochHistory is enough big, so it won't happen.
80  LOG(FATAL) << "Exceeded kMaxEpochHistory. Unexpected.";
81  }
82  ++control_block_->epoch_history_count_;
83  tail_index = control_block_->get_tail_epoch_history();
84  control_block_->epoch_histories_[tail_index] = EpochHistory(epoch_marker);
85  ASSERT_ND(control_block_->epoch_histories_[tail_index].new_epoch_.is_valid());
86  ASSERT_ND(control_block_->epoch_histories_[tail_index].old_epoch_.is_valid());
87  }
88 }
LoggerControlBlock * control_block_
The shared data on shared memory that has been initialized in some SOC or master engine.
Definition: attachable.hpp:111
Max number of active epoch histories.
Definition: logger_impl.hpp:57
#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 caller graph for this function:

void foedus::log::LoggerRef::copy_logger_state ( savepoint::Savepoint new_savepoint) const

Called from log manager's copy_logger_states.

Definition at line 56 of file logger_ref.cpp.

References foedus::Attachable< LoggerControlBlock >::control_block_, foedus::savepoint::Savepoint::current_log_files_, foedus::savepoint::Savepoint::current_log_files_offset_durable_, foedus::savepoint::Savepoint::oldest_log_files_, and foedus::savepoint::Savepoint::oldest_log_files_offset_begin_.

56  {
57  new_savepoint->oldest_log_files_.push_back(control_block_->oldest_ordinal_);
58  new_savepoint->oldest_log_files_offset_begin_.push_back(
59  control_block_->oldest_file_offset_begin_);
60  new_savepoint->current_log_files_.push_back(control_block_->current_ordinal_);
61  new_savepoint->current_log_files_offset_durable_.push_back(
62  control_block_->current_file_durable_offset_);
63 }
LoggerControlBlock * control_block_
The shared data on shared memory that has been initialized in some SOC or master engine.
Definition: attachable.hpp:111
Epoch foedus::log::LoggerRef::get_durable_epoch ( ) const

Returns this logger's durable epoch.

Definition at line 41 of file logger_ref.cpp.

References foedus::Attachable< LoggerControlBlock >::control_block_.

Referenced by get_log_range(), foedus::log::operator<<(), and wakeup_for_durable_epoch().

41  {
42  return Epoch(control_block_->durable_epoch_);
43 }
LoggerControlBlock * control_block_
The shared data on shared memory that has been initialized in some SOC or master engine.
Definition: attachable.hpp:111

Here is the caller graph for this function:

LogRange foedus::log::LoggerRef::get_log_range ( Epoch  prev_epoch,
Epoch  until_epoch 
)

Constructs the range of log entries that represent the given epoch ranges.

Parameters
[in]prev_epochLog entries until this epoch are skipped. An invalid epoch means from the beginning.
[in]until_epochLog entries until this epoch are contained. Must be valid.
Returns
log range that contains all logs (prev_epoch, until_epoch]. In other owrds, from prev_epoch-exclusive and to until_epoch-inclusive.

In case there is no ending epoch marker (only when marked_epoch_ < durable_epoch_.one_more()) this method writes out a new epoch marker. This method is called only for each snapshotting, so it shouldn't be too big a waste.

Definition at line 91 of file logger_ref.cpp.

References ASSERT_ND, foedus::log::LogRange::begin_file_ordinal, foedus::log::LogRange::begin_offset, foedus::Attachable< LoggerControlBlock >::control_block_, foedus::log::LogRange::end_file_ordinal, foedus::log::LogRange::end_offset, get_durable_epoch(), id_, foedus::Epoch::is_valid(), foedus::log::EpochHistory::log_file_offset_, foedus::log::EpochHistory::log_file_ordinal_, and foedus::log::EpochHistory::new_epoch_.

Referenced by foedus::snapshot::LogMapper::handle_process().

91  {
92  // TASK(Hideaki) binary search. we assume there are not many epoch histories, so not urgent.
93  ASSERT_ND(until_epoch <= get_durable_epoch());
94  LogRange result;
95 
96  // Epoch mark is not written to empty epoch. Thus, we might holes at the beginning, in the
97  // middle, and at the end. Be careful.
98  soc::SharedMutexScope scope(&control_block_->epoch_history_mutex_);
99  const uint32_t head = control_block_->epoch_history_head_;
100  const uint32_t count = control_block_->epoch_history_count_;
101  uint32_t pos = 0; // RELATIVE position from head
102  result.begin_file_ordinal = 0;
103  result.begin_offset = 0;
104  if (prev_epoch.is_valid()) {
105  // first, locate the prev_epoch
106  for (; pos < count; ++pos) {
107  uint32_t abs_pos = control_block_->wrap_epoch_history_index(head + pos);
108  const EpochHistory& cur = control_block_->epoch_histories_[abs_pos];
109  if (cur.new_epoch_ > prev_epoch) {
110  result.begin_file_ordinal = cur.log_file_ordinal_;
111  result.begin_offset = cur.log_file_offset_;
112  break;
113  }
114  }
115  if (pos == count) {
116  LOG(INFO) << "No epoch mark found for " << prev_epoch << " in logger-" << id_
117  << " This usually happens when there was no transactional log before system shutdown";
118  result.end_file_ordinal = 0;
119  result.end_offset = 0;
120  return result;
121  }
122  }
123 
124  // next, locate until_epoch. we might not find it if the logger was idle for a while.
125  // in that case, the last mark tells the file/ordinal.
126  for (; pos < count; ++pos) {
127  uint32_t abs_pos = control_block_->wrap_epoch_history_index(head + pos);
128  const EpochHistory& cur = control_block_->epoch_histories_[abs_pos];
129  // first mark that is after the until_epoch tells how much we have to read.
130  // note that we might have multiple marks of the same epoch because of beginning-of-file marker.
131  // we can't stop at the first mark with new_epoch==until.
132  if (cur.new_epoch_ > until_epoch) {
133  result.end_file_ordinal = cur.log_file_ordinal_;
134  result.end_offset = cur.log_file_offset_;
135  break;
136  }
137  }
138 
139  if (pos == count) {
140  if (count == 0) {
141  ASSERT_ND(result.begin_file_ordinal == 0);
142  ASSERT_ND(result.begin_offset == 0);
143  result.end_file_ordinal = 0;
144  result.end_offset = 0;
145  } else {
146  // in this case, we read everything.
147  result.end_file_ordinal = control_block_->current_ordinal_;
148  result.end_offset = control_block_->current_file_durable_offset_;
149  }
150  }
151 
152  ASSERT_ND(result.begin_file_ordinal <= result.end_file_ordinal);
153  ASSERT_ND(result.begin_file_ordinal < result.end_file_ordinal
154  || result.begin_offset <= result.end_offset);
155  return result;
156 }
LoggerControlBlock * control_block_
The shared data on shared memory that has been initialized in some SOC or master engine.
Definition: attachable.hpp:111
Epoch get_durable_epoch() const
Returns this logger's durable epoch.
Definition: logger_ref.cpp:41
#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:

void foedus::log::LoggerRef::wakeup ( )

Wakes up this logger if it is sleeping.

Definition at line 52 of file logger_ref.cpp.

References foedus::Attachable< LoggerControlBlock >::control_block_.

Referenced by wakeup_for_durable_epoch().

52  {
53  control_block_->wakeup_cond_.signal();
54 }
LoggerControlBlock * control_block_
The shared data on shared memory that has been initialized in some SOC or master engine.
Definition: attachable.hpp:111

Here is the caller graph for this function:

void foedus::log::LoggerRef::wakeup_for_durable_epoch ( Epoch  desired_durable_epoch)

Wakes up this logger if its durable_epoch has not reached the given epoch yet.

If this logger's durable_epoch is already same or larger than the epoch, does nothing. This method just wakes up the logger and immediately returns.

Definition at line 45 of file logger_ref.cpp.

References get_durable_epoch(), foedus::assorted::memory_fence_acquire(), and wakeup().

45  {
47  if (get_durable_epoch() < desired_durable_epoch) {
48  wakeup();
49  }
50 }
Epoch get_durable_epoch() const
Returns this logger's durable epoch.
Definition: logger_ref.cpp:41
void wakeup()
Wakes up this logger if it is sleeping.
Definition: logger_ref.cpp:52
void memory_fence_acquire()
Equivalent to std::atomic_thread_fence(std::memory_order_acquire).

Here is the call graph for this function:

Member Data Documentation

uint16_t foedus::log::LoggerRef::in_node_ordinal_
protected

Definition at line 85 of file logger_ref.hpp.

Referenced by LoggerRef(), and foedus::log::operator<<().

uint16_t foedus::log::LoggerRef::numa_node_
protected

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