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

Represents an append/scan-only store. More...

Detailed Description

Represents an append/scan-only store.

Definition at line 41 of file sequential_storage.hpp.

#include <sequential_storage.hpp>

Inheritance diagram for foedus::storage::sequential::SequentialStorage:
Collaboration diagram for foedus::storage::sequential::SequentialStorage:

Public Types

typedef SequentialStoragePimpl ThisPimpl
 
typedef SequentialCreateLogType ThisCreateLogType
 
typedef SequentialMetadata ThisMetadata
 

Public Member Functions

 SequentialStorage ()
 
 SequentialStorage (Engine *engine, SequentialStorageControlBlock *control_block)
 
 SequentialStorage (Engine *engine, StorageControlBlock *control_block)
 
 SequentialStorage (Engine *engine, StorageId id)
 
 SequentialStorage (Engine *engine, const StorageName &name)
 
 SequentialStorage (const SequentialStorage &other)
 
SequentialStorageoperator= (const SequentialStorage &other)
 
const SequentialMetadataget_sequential_metadata () const
 
ErrorStack create (const Metadata &metadata)
 
ErrorStack load (const StorageControlBlock &snapshot_block)
 
ErrorStack drop ()
 
ErrorCode append_record (thread::Thread *context, const void *payload, uint16_t payload_count)
 Append one record to this sequential storage. More...
 
void apply_append_record (thread::Thread *context, const SequentialAppendLogType *log_entry)
 Used to apply the effect of appending to volatile list. More...
 
ErrorCode optimistic_read_truncate_epoch (thread::Thread *context, Epoch *out) const
 Obtains the current value of truncate-epoch in an OCC-fashion. More...
 
Epoch get_truncate_epoch () const
 This version doesn't protect the read in a xct. More...
 
ErrorStack truncate (Epoch new_truncate_epoch, Epoch *commit_epoch)
 Discards all records in this storage before the given epoch. More...
 
void apply_truncate (const SequentialTruncateLogType &the_log)
 
- Public Member Functions inherited from foedus::storage::Storage< SequentialStorageControlBlock >
 Storage ()
 
 Storage (Engine *engine, SequentialStorageControlBlock *control_block)
 
 Storage (Engine *engine, StorageControlBlock *control_block)
 
 Storage (Engine *engine, StorageId id)
 Shorthand for engine->get_storage_manager()->get_storage(id) More...
 
 Storage (Engine *engine, const StorageName &name)
 Shorthand for engine->get_storage_manager()->get_storage(name) More...
 
 Storage (const Storage &other)
 
Storageoperator= (const Storage &other)
 
StorageId get_id () const
 Returns the unique ID of this storage. More...
 
StorageType get_type () const
 Returns the type of this storage. More...
 
const StorageNameget_name () const
 Returns the unique name of this storage. More...
 
const Metadataget_metadata () const
 Returns the metadata of this storage. More...
 
bool exists () const
 Returns whether this storage is already created. More...
 
- Public Member Functions inherited from foedus::Attachable< SequentialStorageControlBlock >
 Attachable ()
 
 Attachable (Engine *engine)
 
 Attachable (Engine *engine, SequentialStorageControlBlock *control_block)
 
 Attachable (SequentialStorageControlBlock *control_block)
 
 Attachable (const Attachable &other)
 
virtual ~Attachable ()
 
Attachableoperator= (const Attachable &other)
 
virtual void attach (SequentialStorageControlBlock *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...
 
SequentialStorageControlBlock * get_control_block () const
 
Engineget_engine () const
 
void set_engine (Engine *engine)
 

Friends

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

Additional Inherited Members

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

Member Typedef Documentation

Constructor & Destructor Documentation

foedus::storage::sequential::SequentialStorage::SequentialStorage ( )

Definition at line 35 of file sequential_storage.cpp.

35 : Storage<SequentialStorageControlBlock>() {}
foedus::storage::sequential::SequentialStorage::SequentialStorage ( Engine engine,
SequentialStorageControlBlock control_block 
)

Definition at line 36 of file sequential_storage.cpp.

References ASSERT_ND, foedus::storage::Storage< SequentialStorageControlBlock >::exists(), foedus::storage::Storage< SequentialStorageControlBlock >::get_type(), and foedus::storage::kSequentialStorage.

37  : Storage<SequentialStorageControlBlock>(engine, control_block) {
39 }
StorageType get_type() const
Returns the type of this storage.
Definition: storage.hpp:150
bool exists() const
Returns whether this storage is already created.
Definition: storage.hpp:169
#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:

foedus::storage::sequential::SequentialStorage::SequentialStorage ( Engine engine,
StorageControlBlock control_block 
)

Definition at line 40 of file sequential_storage.cpp.

References ASSERT_ND, foedus::storage::Storage< SequentialStorageControlBlock >::exists(), foedus::storage::Storage< SequentialStorageControlBlock >::get_type(), and foedus::storage::kSequentialStorage.

41  : Storage<SequentialStorageControlBlock>(engine, control_block) {
43 }
StorageType get_type() const
Returns the type of this storage.
Definition: storage.hpp:150
bool exists() const
Returns whether this storage is already created.
Definition: storage.hpp:169
#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:

foedus::storage::sequential::SequentialStorage::SequentialStorage ( Engine engine,
StorageId  id 
)

Definition at line 44 of file sequential_storage.cpp.

45  : Storage<SequentialStorageControlBlock>(engine, id) {}
foedus::storage::sequential::SequentialStorage::SequentialStorage ( Engine engine,
const StorageName name 
)

Definition at line 46 of file sequential_storage.cpp.

47  : Storage<SequentialStorageControlBlock>(engine, name) {}
foedus::storage::sequential::SequentialStorage::SequentialStorage ( const SequentialStorage other)

Definition at line 48 of file sequential_storage.cpp.

49  : Storage<SequentialStorageControlBlock>(other.engine_, other.control_block_) {
50 }

Member Function Documentation

ErrorCode foedus::storage::sequential::SequentialStorage::append_record ( thread::Thread context,
const void *  payload,
uint16_t  payload_count 
)

Append one record to this sequential storage.

Parameters
[in]contextThread context
[in]payloadWe copy from this buffer. Must be at least get_payload_size().
[in]payload_countLength of payload.
Precondition
payload_count > 0
payload_count < kMaxPayload

The strict ordering of the appended record is NOT guaranteed to be the commit serialization order. Sequential Storage storage essentially provides a set semantics, not a strictly ordered LIFO queue, to be more scalable. However, the orders are at least loosely ordered; the order largely represents when it was inserted.

Definition at line 56 of file sequential_storage_pimpl.cpp.

References foedus::xct::Xct::add_to_lock_free_write_set(), foedus::storage::sequential::SequentialAppendLogType::calculate_log_length(), foedus::thread::Thread::get_current_xct(), foedus::storage::Storage< SequentialStorageControlBlock >::get_id(), foedus::thread::Thread::get_thread_log_buffer(), foedus::kErrorCodeStrTooLongPayload, foedus::storage::sequential::kMaxPayload, foedus::storage::sequential::SequentialAppendLogType::populate(), and foedus::log::ThreadLogBuffer::reserve_new_log().

59  {
60  if (payload_count >= kMaxPayload) {
62  }
63 
64  // Sequential storage doesn't need to check its current state for appends.
65  // we are sure we can append it anyways, so we just create a log record.
66  uint16_t log_length = SequentialAppendLogType::calculate_log_length(payload_count);
67  SequentialAppendLogType* log_entry = reinterpret_cast<SequentialAppendLogType*>(
68  context->get_thread_log_buffer().reserve_new_log(log_length));
69  log_entry->populate(get_id(), payload, payload_count);
70 
71  // also, we don't have to take a lock while commit because our SequentialVolatileList is
72  // lock-free. So, we maintain a special lock-free write-set for sequential storage.
73  return context->get_current_xct().add_to_lock_free_write_set(get_id(), log_entry);
74 }
0x0808 : "STORAGE: Payload of the record is too long" .
Definition: error_code.hpp:174
StorageId get_id() const
Returns the unique ID of this storage.
Definition: storage.hpp:145
static uint16_t calculate_log_length(uint16_t payload_count) __attribute__((always_inline))
const uint16_t kMaxPayload
Payload must be shorter than this length.

Here is the call graph for this function:

void foedus::storage::sequential::SequentialStorage::apply_append_record ( thread::Thread context,
const SequentialAppendLogType log_entry 
)

Used to apply the effect of appending to volatile list.

Definition at line 76 of file sequential_storage_pimpl.cpp.

References foedus::storage::sequential::SequentialStoragePimpl::append_record(), foedus::log::BaseLogType::header_, foedus::storage::sequential::SequentialAppendLogType::payload_, foedus::storage::sequential::SequentialAppendLogType::payload_count_, and foedus::log::LogHeader::xct_id_.

Referenced by foedus::storage::sequential::SequentialAppendLogType::apply_record().

78  {
79  SequentialStoragePimpl(this).append_record(
80  context,
81  log_entry->header_.xct_id_,
82  log_entry->payload_,
83  log_entry->payload_count_);
84 }

Here is the call graph for this function:

Here is the caller graph for this function:

void foedus::storage::sequential::SequentialStorage::apply_truncate ( const SequentialTruncateLogType the_log)

Definition at line 81 of file sequential_storage.cpp.

References foedus::storage::sequential::SequentialStoragePimpl::apply_truncate().

Referenced by foedus::storage::sequential::SequentialTruncateLogType::apply_storage().

81  {
82  SequentialStoragePimpl(this).apply_truncate(the_log);
83 }

Here is the call graph for this function:

Here is the caller graph for this function:

ErrorStack foedus::storage::sequential::SequentialStorage::create ( const Metadata metadata)

Definition at line 61 of file sequential_storage.cpp.

References foedus::storage::sequential::SequentialStoragePimpl::create().

61  {
62  return SequentialStoragePimpl(this).create(static_cast<const SequentialMetadata&>(metadata));
63 }

Here is the call graph for this function:

ErrorStack foedus::storage::sequential::SequentialStorage::drop ( )

Definition at line 67 of file sequential_storage.cpp.

References foedus::storage::sequential::SequentialStoragePimpl::drop().

67  {
68  return SequentialStoragePimpl(this).drop();
69 }

Here is the call graph for this function:

const SequentialMetadata * foedus::storage::sequential::SequentialStorage::get_sequential_metadata ( ) const

Definition at line 57 of file sequential_storage.cpp.

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

57  {
58  return &control_block_->meta_;
59 }
SequentialStorageControlBlock * control_block_
The shared data on shared memory that has been initialized in some SOC or master engine.
Definition: attachable.hpp:111
Epoch foedus::storage::sequential::SequentialStorage::get_truncate_epoch ( ) const

This version doesn't protect the read in a xct.

Handy, but use with care. You should use this method only in non-racy places (eg reporting/debugging etc).

See also
optimistic_read_truncate_epoch()

Definition at line 70 of file sequential_storage.cpp.

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

Referenced by foedus::storage::sequential::operator<<().

70  {
71  return Epoch(control_block_->cur_truncate_epoch_.load());
72 }
SequentialStorageControlBlock * 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:

ErrorStack foedus::storage::sequential::SequentialStorage::load ( const StorageControlBlock snapshot_block)

Definition at line 64 of file sequential_storage.cpp.

References foedus::storage::sequential::SequentialStoragePimpl::load().

64  {
65  return SequentialStoragePimpl(this).load(snapshot_block);
66 }

Here is the call graph for this function:

SequentialStorage & foedus::storage::sequential::SequentialStorage::operator= ( const SequentialStorage other)

Definition at line 51 of file sequential_storage.cpp.

References foedus::Attachable< SequentialStorageControlBlock >::control_block_, foedus::Attachable< CONTROL_BLOCK >::control_block_, foedus::Attachable< SequentialStorageControlBlock >::engine_, and foedus::Attachable< CONTROL_BLOCK >::engine_.

51  {
52  engine_ = other.engine_;
53  control_block_ = other.control_block_;
54  return *this;
55 }
Engine * engine_
Most attachable object stores an engine pointer (local engine), so we define it here.
Definition: attachable.hpp:107
SequentialStorageControlBlock * control_block_
The shared data on shared memory that has been initialized in some SOC or master engine.
Definition: attachable.hpp:111
ErrorCode foedus::storage::sequential::SequentialStorage::optimistic_read_truncate_epoch ( thread::Thread context,
Epoch out 
) const

Obtains the current value of truncate-epoch in an OCC-fashion.

See also
foedus::storage::sequential::SequentialMetadata::truncate_epoch_

This method takes a read-set to protect this OCC-read. Thus it receives a thread context.

Definition at line 73 of file sequential_storage.cpp.

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

75  {
76  return control_block_->optimistic_read_truncate_epoch(context, out);
77 }
SequentialStorageControlBlock * control_block_
The shared data on shared memory that has been initialized in some SOC or master engine.
Definition: attachable.hpp:111
ErrorStack foedus::storage::sequential::SequentialStorage::truncate ( Epoch  new_truncate_epoch,
Epoch commit_epoch 
)

Discards all records in this storage before the given epoch.

Parameters
[in]new_truncate_epochall records whose epoch is exclusively smaller than this will be logically deleted.
[out]commit_epochThe epoch when the truncate has happened.
Precondition
new_truncate_epoch.is_valid()
new_truncate_epoch >= engine.get_earliest_epoch()
Postcondition
new_truncate_epoch == get_truncate_epoch()

This method implements the special truncate feature as a metadata operation on this storage. This method starts and ends its own meta-transaction. So it does NOT receive a Thread context. In other words, you cannot invoke this operation as part of another transaction.

As far as a valid parameter is given, this method always succeeds because there is no race. If new_truncate_epoch <= get_truncate_epoch(), this method does nothing (not an error).

See also
optimistic_read_truncate_epoch()
get_truncate_epoch()

Definition at line 78 of file sequential_storage.cpp.

References foedus::storage::sequential::SequentialStoragePimpl::truncate().

78  {
79  return SequentialStoragePimpl(this).truncate(new_truncate_epoch, commit_epoch);
80 }

Here is the call graph for this function:

Friends And Related Function Documentation

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

Definition at line 86 of file sequential_storage.cpp.

86  {
87  uint64_t page_count = 0;
88  uint64_t record_count = 0;
89  SequentialStoragePimpl pimpl(const_cast<SequentialStorage*>(&v));
90  pimpl.for_every_page([&page_count, &record_count](SequentialPage* page){
91  ++page_count;
92  record_count += page->get_record_count();
93  return kErrorCodeOk;
94  });
95  o << "<SequentialStorage>"
96  << "<id>" << v.get_id() << "</id>"
97  << "<name>" << v.get_name() << "</name>"
98  << "<truncate_epoch>" << v.get_truncate_epoch() << "</truncate_epoch>"
99  << "<page_count>" << page_count << "</page_count>"
100  << "<record_count>" << record_count << "</record_count>"
101  << "</SequentialStorage>";
102  return o;
103 }
0 means no-error.
Definition: error_code.hpp:87

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