libfoedus-core
FOEDUS Core Library
sequential_storage.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014-2015, Hewlett-Packard Development Company, LP.
3  * This program is free software; you can redistribute it and/or modify it
4  * under the terms of the GNU General Public License as published by the Free
5  * Software Foundation; either version 2 of the License, or (at your option)
6  * any later version.
7  *
8  * This program is distributed in the hope that it will be useful, but WITHOUT
9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11  * more details. You should have received a copy of the GNU General Public
12  * License along with this program; if not, write to the Free Software
13  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14  *
15  * HP designates this particular file as subject to the "Classpath" exception
16  * as provided by HP in the LICENSE.txt file that accompanied this code.
17  */
19 
20 #include <glog/logging.h>
21 
22 #include <iostream>
23 #include <string>
24 
28 #include "foedus/thread/thread.hpp"
29 #include "foedus/xct/xct.hpp"
30 
31 namespace foedus {
32 namespace storage {
33 namespace sequential {
34 
37  : Storage<SequentialStorageControlBlock>(engine, control_block) {
39 }
41  : Storage<SequentialStorageControlBlock>(engine, control_block) {
43 }
45  : Storage<SequentialStorageControlBlock>(engine, id) {}
47  : Storage<SequentialStorageControlBlock>(engine, name) {}
49  : Storage<SequentialStorageControlBlock>(other.engine_, other.control_block_) {
50 }
52  engine_ = other.engine_;
54  return *this;
55 }
56 
58  return &control_block_->meta_;
59 }
60 
62  return SequentialStoragePimpl(this).create(static_cast<const SequentialMetadata&>(metadata));
63 }
65  return SequentialStoragePimpl(this).load(snapshot_block);
66 }
68  return SequentialStoragePimpl(this).drop();
69 }
71  return Epoch(control_block_->cur_truncate_epoch_.load());
72 }
74  thread::Thread* context,
75  Epoch* out) const {
76  return control_block_->optimistic_read_truncate_epoch(context, out);
77 }
78 ErrorStack SequentialStorage::truncate(Epoch new_truncate_epoch, Epoch* commit_epoch) {
79  return SequentialStoragePimpl(this).truncate(new_truncate_epoch, commit_epoch);
80 }
83 }
84 
85 
86 std::ostream& operator<<(std::ostream& o, const SequentialStorage& v) {
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 }
104 
105 // most other methods are defined in pimpl.cpp to allow inlining
106 
107 } // namespace sequential
108 } // namespace storage
109 } // namespace foedus
std::ostream & operator<<(std::ostream &o, const SequentialCursor &v)
Lock-free list of records stored in the volatile part of sequential storage.
ErrorStack load(const StorageControlBlock &snapshot_block)
StorageType get_type() const
Returns the type of this storage.
Definition: storage.hpp:150
uint32_t StorageId
Unique ID for storage.
Definition: storage_id.hpp:55
Root package of FOEDUS (Fast Optimistic Engine for Data Unification Services).
Definition: assert_nd.hpp:44
Represents one thread running on one NUMA core.
Definition: thread.hpp:48
void apply_truncate(const SequentialTruncateLogType &the_log)
Brings error stacktrace information as return value of functions.
Definition: error_stack.hpp:81
Represents a time epoch.
Definition: epoch.hpp:61
Engine * engine_
Most attachable object stores an engine pointer (local engine), so we define it here.
Definition: attachable.hpp:107
SequentialStorage & operator=(const SequentialStorage &other)
Represents one data page in Sequential Storage.
ErrorStack truncate(Epoch new_truncate_epoch, Epoch *commit_epoch)
Discards all records in this storage before the given epoch.
const SequentialMetadata * get_sequential_metadata() const
Metadata of one storage.
Definition: metadata.hpp:58
Represents an append/scan-only store.
Represents one key-value store.
Definition: storage.hpp:116
0 means no-error.
Definition: error_code.hpp:87
ErrorStack truncate(Epoch new_truncate_epoch, Epoch *commit_epoch)
SequentialStorageControlBlock * control_block_
The shared data on shared memory that has been initialized in some SOC or master engine.
Definition: attachable.hpp:111
ErrorStack create(const Metadata &metadata)
const StorageName & get_name() const
Returns the unique name of this storage.
Definition: storage.hpp:155
bool exists() const
Returns whether this storage is already created.
Definition: storage.hpp:169
Database engine object that holds all resources and provides APIs.
Definition: engine.hpp:109
void apply_truncate(const SequentialTruncateLogType &the_log)
StorageId get_id() const
Returns the unique ID of this storage.
Definition: storage.hpp:145
Epoch get_truncate_epoch() const
This version doesn't protect the read in a xct.
ErrorCode for_every_page(HANDLER handler) const
Traverse all pages and call back the handler for every page.
ErrorCode optimistic_read_truncate_epoch(thread::Thread *context, Epoch *out) const
Obtains the current value of truncate-epoch in an OCC-fashion.
Declares all log types used in this storage type.
uint16_t get_record_count() const
Returns how many records in this page placed so far.
Log type of TRUNCATE SEQUENTIAL STORAGE operation.
ErrorStack create(const SequentialMetadata &metadata)
ErrorStack load(const StorageControlBlock &snapshot_block)
#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
A base layout of shared data for all storage types.
Definition: storage.hpp:53
ErrorCode
Enum of error codes defined in error_code.xmacro.
Definition: error_code.hpp:85