libfoedus-core
FOEDUS Core Library
sequential_log_types.hpp
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  */
18 #ifndef FOEDUS_STORAGE_SEQUENTIAL_SEQUENTIAL_LOG_TYPES_HPP_
19 #define FOEDUS_STORAGE_SEQUENTIAL_SEQUENTIAL_LOG_TYPES_HPP_
20 #include <stdint.h>
21 
22 #include <cstring>
23 #include <iosfwd>
24 
25 #include "foedus/assert_nd.hpp"
26 #include "foedus/compiler.hpp"
27 #include "foedus/cxx11.hpp"
28 #include "foedus/engine.hpp"
32 #include "foedus/log/log_type.hpp"
40 #include "foedus/thread/thread.hpp"
41 #include "foedus/xct/xct_id.hpp"
42 
48 namespace foedus {
49 namespace storage {
50 namespace sequential {
65 
66  void apply_storage(Engine* engine, StorageId storage_id);
67  void assert_valid();
68  friend std::ostream& operator<<(std::ostream& o, const SequentialCreateLogType& v);
69 };
70 
80 struct SequentialTruncateLogType : public log::StorageLogType {
82  Epoch new_truncate_epoch_;
83 
84  void apply_storage(Engine* engine, StorageId storage_id);
85  void assert_valid();
86  friend std::ostream& operator<<(std::ostream& o, const SequentialTruncateLogType& v);
87 };
88 
96 struct SequentialAppendLogType : public log::RecordLogType {
98  uint16_t payload_count_; // +2 => 18
99  char payload_[6]; // +6 => 24
100 
101  static uint16_t calculate_log_length(uint16_t payload_count) ALWAYS_INLINE {
102  // we pad to 8 bytes so that we always have a room for FillerLogType to align.
103  return assorted::align8(18 + payload_count);
104  }
105 
106  void populate(
107  StorageId storage_id,
108  const void *payload,
109  uint16_t payload_count) ALWAYS_INLINE {
111  header_.log_length_ = calculate_log_length(payload_count);
112  header_.storage_id_ = storage_id;
113  payload_count_ = payload_count;
114  std::memcpy(payload_, payload, payload_count);
115  }
117  thread::Thread* context,
118  StorageId storage_id,
119  xct::RwLockableXctId* owner_id,
120  char* payload) ALWAYS_INLINE {
121  // It's a lock-free write set, so it doesn't have record info.
122  ASSERT_ND(owner_id == CXX11_NULLPTR);
123  ASSERT_ND(payload == CXX11_NULLPTR);
124  SequentialStorage storage
125  = context->get_engine()->get_storage_manager()->get_sequential(storage_id);
126  storage.apply_append_record(context, this);
127  }
128 
131  ASSERT_ND(header_.log_length_ == calculate_log_length(payload_count_));
132  ASSERT_ND(payload_count_ < kMaxPayload);
134  }
135 
136  friend std::ostream& operator<<(std::ostream& o, const SequentialAppendLogType& v);
137 };
138 
139 } // namespace sequential
140 } // namespace storage
141 } // namespace foedus
142 #endif // FOEDUS_STORAGE_SEQUENTIAL_SEQUENTIAL_LOG_TYPES_HPP_
Base class for log type of storage-wide operation.
T align8(T value)
8-alignment.
void apply_storage(Engine *engine, StorageId storage_id)
sequential::SequentialStorage get_sequential(StorageId id)
Returns the sequential storage of given ID.
Definitions of IDs in this package and a few related constant values.
storage::StorageManager * get_storage_manager() const
See Storage Manager.
Definition: engine.cpp:60
#define CXX11_NULLPTR
Used in public headers in place of "nullptr" of C++11.
Definition: cxx11.hpp:132
void populate(StorageId storage_id, const void *payload, uint16_t payload_count) __attribute__((always_inline))
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
STL namespace.
Represents a time epoch.
Definition: epoch.hpp:61
Declares common log types used in all packages.
friend std::ostream & operator<<(std::ostream &o, const SequentialCreateLogType &v)
The MCS reader-writer lock variant of LockableXctId.
Definition: xct_id.hpp:1132
Represents an append/scan-only store.
Forward declarations of classes in sequential storage package.
Definitions of IDs in this package and a few related constant values.
Database engine object that holds all resources and provides APIs.
Definition: engine.hpp:109
Log type of CREATE SEQUENTIAL STORAGE operation.
0x0026 : foedus::storage::sequential::SequentialAppendLogType .
Definition: log_type.hpp:119
Engine * get_engine() const
Definition: attachable.hpp:99
uint16_t log_type_code_
Actually of LogCode defined in the X-Macro, but we want to make sure the type size is 2 bytes...
Definitions of IDs in this package and a few related constant values.
uint16_t log_length_
Byte size of this log entry including this header itself and everything.
Log type of TRUNCATE SEQUENTIAL STORAGE operation.
void apply_append_record(thread::Thread *context, const SequentialAppendLogType *log_entry)
Used to apply the effect of appending to volatile list.
#define LOG_TYPE_NO_CONSTRUCT(clazz)
Macro to delete all constructors/destructors to prevent misuse for log type classes.
storage::StorageId storage_id_
The storage this loggable operation mainly affects.
Atomic fence methods and load/store with fences that work for both C++11/non-C++11 code...
LogCode get_type() const __attribute__((always_inline))
Convenience method to cast into LogCode.
const uint16_t kMaxPayload
Payload must be shorter than this length.
Log type of sequential-storage's append operation.
#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
#define ALWAYS_INLINE
A function suffix to hint that the function should always be inlined.
Definition: compiler.hpp:106
void assert_valid_generic() __attribute__((always_inline))
Verifies the log contains essential fields set.
void apply_record(thread::Thread *context, StorageId storage_id, xct::RwLockableXctId *owner_id, char *payload) __attribute__((always_inline))