libfoedus-core
FOEDUS Core Library
foedus::storage::sequential::SequentialRecordIterator Class Referencefinal

Iterator for one SequentialRecordBatch, or a page. More...

Detailed Description

Iterator for one SequentialRecordBatch, or a page.

This class inlines per-record methods, but not per-page methods (eg initialization).

Definition at line 383 of file sequential_cursor.hpp.

#include <sequential_cursor.hpp>

Public Member Functions

 SequentialRecordIterator ()
 
 SequentialRecordIterator (const SequentialRecordBatch *batch, Epoch from_epoch, Epoch to_epoch)
 
void reset ()
 
bool is_valid () const __attribute__((always_inline))
 
void next () __attribute__((always_inline))
 
uint16_t get_cur_record_length () const __attribute__((always_inline))
 
Epoch get_cur_record_epoch () const __attribute__((always_inline))
 
void copy_cur_record (char *out, uint16_t out_size) const __attribute__((always_inline))
 Copies the current record to the given buffer. More...
 
const char * get_cur_record_raw () const __attribute__((always_inline))
 Directly returns a pointer to the current record. More...
 
const xct::RwLockableXctIdget_cur_record_owner_id () const __attribute__((always_inline))
 
bool in_epoch_range (Epoch epoch) const __attribute__((always_inline))
 
uint16_t get_stat_skipped_records () const
 
uint16_t get_record_count () const
 
const SequentialRecordBatchget_raw_batch () const
 

Constructor & Destructor Documentation

foedus::storage::sequential::SequentialRecordIterator::SequentialRecordIterator ( )

Definition at line 127 of file sequential_cursor.cpp.

References foedus::INVALID_EPOCH.

128  : batch_(nullptr),
129  from_epoch_(INVALID_EPOCH),
130  to_epoch_(INVALID_EPOCH),
131  record_count_(0) {
132  cur_record_ = 0;
133  cur_record_length_ = 0;
134  cur_offset_ = 0;
135  cur_record_epoch_ = INVALID_EPOCH;
136  stat_skipped_records_ = 0;
137 }
const Epoch INVALID_EPOCH
A constant epoch object that represents an invalid epoch.
Definition: epoch.hpp:204
foedus::storage::sequential::SequentialRecordIterator::SequentialRecordIterator ( const SequentialRecordBatch batch,
Epoch  from_epoch,
Epoch  to_epoch 
)

Definition at line 139 of file sequential_cursor.cpp.

References ASSERT_ND, foedus::storage::sequential::SequentialRecordBatch::get_epoch_from_offset(), foedus::storage::sequential::SequentialRecordBatch::get_record_length(), in_epoch_range(), foedus::Epoch::is_valid(), and next().

143  : batch_(batch),
144  from_epoch_(from_epoch),
145  to_epoch_(to_epoch),
146  record_count_(batch->get_record_count()) {
147  cur_record_ = 0;
148  cur_record_length_ = batch_->get_record_length(0);
149  cur_offset_ = 0;
150  cur_record_epoch_ = batch->get_epoch_from_offset(0);
151  ASSERT_ND(cur_record_epoch_.is_valid());
152  stat_skipped_records_ = 0;
153  if (!in_epoch_range(cur_record_epoch_)) {
154  ++stat_skipped_records_;
155  next();
156  }
157 }
bool in_epoch_range(Epoch epoch) const __attribute__((always_inline))
bool is_valid() const
Definition: epoch.hpp:96
#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:

Member Function Documentation

void foedus::storage::sequential::SequentialRecordIterator::copy_cur_record ( char *  out,
uint16_t  out_size 
) const
inline

Copies the current record to the given buffer.

This is safe even after the cursor moves on, but it incurs one memcpy.

See also
get_cur_record_raw()

Definition at line 425 of file sequential_cursor.hpp.

References ASSERT_ND, get_cur_record_raw(), and is_valid().

425  {
426  ASSERT_ND(is_valid());
427  const char* raw = get_cur_record_raw();
428  uint16_t copy_size = std::min<uint16_t>(out_size, cur_record_length_);
429  std::memcpy(out, raw, copy_size);
430  }
const char * get_cur_record_raw() const __attribute__((always_inline))
Directly returns a pointer to the current record.
bool is_valid() const __attribute__((always_inline))
#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:

Epoch foedus::storage::sequential::SequentialRecordIterator::get_cur_record_epoch ( ) const
inline

Definition at line 416 of file sequential_cursor.hpp.

References ASSERT_ND, and is_valid().

416  {
417  ASSERT_ND(is_valid());
418  return cur_record_epoch_;
419  }
bool is_valid() const __attribute__((always_inline))
#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:

uint16_t foedus::storage::sequential::SequentialRecordIterator::get_cur_record_length ( ) const
inline

Definition at line 412 of file sequential_cursor.hpp.

References ASSERT_ND, and is_valid().

412  {
413  ASSERT_ND(is_valid());
414  return cur_record_length_;
415  }
bool is_valid() const __attribute__((always_inline))
#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:

const xct::RwLockableXctId* foedus::storage::sequential::SequentialRecordIterator::get_cur_record_owner_id ( ) const
inline

Definition at line 440 of file sequential_cursor.hpp.

References ASSERT_ND, foedus::storage::sequential::SequentialRecordBatch::get_owner_id_from_offset(), and is_valid().

440  {
441  ASSERT_ND(is_valid());
442  return batch_->get_owner_id_from_offset(cur_offset_);
443  }
const xct::RwLockableXctId * get_owner_id_from_offset(uint16_t offset) const
bool is_valid() const __attribute__((always_inline))
#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:

const char* foedus::storage::sequential::SequentialRecordIterator::get_cur_record_raw ( ) const
inline

Directly returns a pointer to the current record.

No memcpy, but note that the pointed address might become invalid once the cursor moves on. Use it with caution, like std::string::data().

See also
copy_cur_record()

Definition at line 436 of file sequential_cursor.hpp.

References ASSERT_ND, foedus::storage::sequential::SequentialRecordBatch::get_payload_from_offset(), and is_valid().

Referenced by copy_cur_record().

436  {
437  ASSERT_ND(is_valid());
438  return batch_->get_payload_from_offset(cur_offset_);
439  }
bool is_valid() const __attribute__((always_inline))
const char * get_payload_from_offset(uint16_t offset) const
#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:

const SequentialRecordBatch* foedus::storage::sequential::SequentialRecordIterator::get_raw_batch ( ) const
inline

Definition at line 453 of file sequential_cursor.hpp.

453 { return batch_; }
uint16_t foedus::storage::sequential::SequentialRecordIterator::get_record_count ( ) const
inline
Returns
total number of records in this batch

Definition at line 451 of file sequential_cursor.hpp.

451 { return record_count_; }
uint16_t foedus::storage::sequential::SequentialRecordIterator::get_stat_skipped_records ( ) const
inline
Returns
number of records we skipped so far due to from/to epoch

Definition at line 449 of file sequential_cursor.hpp.

449 { return stat_skipped_records_; }
bool foedus::storage::sequential::SequentialRecordIterator::in_epoch_range ( Epoch  epoch) const
inline

Definition at line 444 of file sequential_cursor.hpp.

Referenced by next(), and SequentialRecordIterator().

444  {
445  return epoch >= from_epoch_ && epoch < to_epoch_;
446  }

Here is the caller graph for this function:

bool foedus::storage::sequential::SequentialRecordIterator::is_valid ( ) const
inline

Definition at line 392 of file sequential_cursor.hpp.

Referenced by copy_cur_record(), get_cur_record_epoch(), get_cur_record_length(), get_cur_record_owner_id(), and get_cur_record_raw().

392 { return cur_record_ < record_count_; }

Here is the caller graph for this function:

void foedus::storage::sequential::SequentialRecordIterator::next ( )
inline

Definition at line 393 of file sequential_cursor.hpp.

References foedus::assorted::align8(), ASSERT_ND, foedus::storage::sequential::SequentialRecordBatch::get_epoch_from_offset(), foedus::storage::sequential::SequentialRecordBatch::get_record_length(), in_epoch_range(), foedus::Epoch::is_valid(), LIKELY, and UNLIKELY.

Referenced by SequentialRecordIterator().

393  {
394  while (true) {
395  if (UNLIKELY(cur_record_ + 1U >= record_count_)) {
396  cur_record_ = record_count_;
397  break;
398  }
399 
400  ++cur_record_;
401  cur_offset_ += assorted::align8(cur_record_length_) + sizeof(xct::RwLockableXctId);
402  cur_record_length_ = batch_->get_record_length(cur_record_);
403  cur_record_epoch_ = batch_->get_epoch_from_offset(cur_offset_);
404  ASSERT_ND(cur_record_epoch_.is_valid());
405  if (LIKELY(in_epoch_range(cur_record_epoch_))) {
406  break;
407  }
408  // we have to skip this record
409  ++stat_skipped_records_;
410  }
411  }
T align8(T value)
8-alignment.
#define LIKELY(x)
Hints that x is highly likely true.
Definition: compiler.hpp:103
bool in_epoch_range(Epoch epoch) const __attribute__((always_inline))
bool is_valid() const
Definition: epoch.hpp:96
#define UNLIKELY(x)
Hints that x is highly likely false.
Definition: compiler.hpp:104
#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::storage::sequential::SequentialRecordIterator::reset ( )
inline

Definition at line 388 of file sequential_cursor.hpp.

Referenced by foedus::storage::sequential::SequentialCursor::next_batch().

388  {
389  std::memset(this, 0, sizeof(SequentialRecordIterator));
390  }

Here is the caller graph for this function:


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