18 #ifndef FOEDUS_STORAGE_MASSTREE_MASSTREE_LOG_TYPES_HPP_
19 #define FOEDUS_STORAGE_MASSTREE_MASSTREE_LOG_TYPES_HPP_
96 char aligned_data_[8];
98 static uint16_t calculate_log_length(
105 const char*
get_key()
const {
return aligned_data_; }
109 return reinterpret_cast<char*
>(
ASSUME_ALIGNED(aligned_data_ + get_key_length_aligned(), 8U));
112 return reinterpret_cast<const char*
>(
127 key_length_ = key_length;
128 payload_offset_ = payload_offset;
129 payload_count_ = payload_count;
132 std::memcpy(aligned_data_, key, key_length);
134 if (aligned_key_length != key_length) {
135 std::memset(aligned_data_ + key_length, 0, aligned_key_length - key_length);
137 if (payload_count > 0) {
139 char* payload_base = aligned_data_ + aligned_key_length;
140 std::memcpy(payload_base, payload, payload_count);
141 if (aligned_payload_count != payload_count) {
142 std::memset(payload_base + payload_count, 0, aligned_payload_count - payload_count);
154 if (key_length_ > skipped) {
155 const char* key = get_key();
156 KeyLength suffix_length = key_length_ - skipped;
160 return std::memcmp(data, key + skipped, suffix_length_aligned) == 0;
173 ASSERT_ND(left->header_.storage_id_ == right->header_.storage_id_);
177 if (
LIKELY(left->key_length_ > 0 && right->key_length_ > 0)) {
179 const char* left_key = left->get_key();
180 const char* right_key = right->get_key();
185 if (left_slice < right_slice) {
187 }
else if (left_slice > right_slice) {
192 KeyLength min_length = std::min(left->key_length_, right->key_length_);
195 int key_result = std::memcmp(left_key + kSliceLen, right_key + kSliceLen, remainder);
196 if (key_result != 0) {
201 if (left->key_length_ < right->key_length_) {
203 }
else if (left->key_length_ < right->key_length_) {
208 return left->header_.xct_id_.compare_epoch_and_orginal(right->header_.xct_id_);
254 const KeyLength key_length_aligned = this->get_key_length_aligned();
255 ASSERT_ND(key_length_aligned >= skipped);
256 const KeyLength suffix_length_aligned = key_length_aligned - skipped;
259 ASSERT_ND(equal_record_and_log_suffixes(record));
264 uint16_t* lengthes =
reinterpret_cast<uint16_t*
>(owner_id + 1);
274 char* page_char =
reinterpret_cast<char*
>(page);
277 if (old_offset != offset) {
285 ASSERT_ND(equal_record_and_log_suffixes(record));
291 char* record_payload =
reinterpret_cast<char*
>(
318 populate_base(type, storage_id, key, key_length, payload, 0, payload_count);
327 ASSERT_ND(owner_id->xct_id_.is_deleted());
329 if (payload_count_ > 0U) {
330 const char* log_payload = get_payload();
333 owner_id->xct_id_.set_notdeleted();
363 populate_base(type, storage_id, key, key_length);
371 apply_record_prepare(owner_id, data);
372 ASSERT_ND(!owner_id->xct_id_.is_deleted());
373 owner_id->xct_id_.set_deleted();
401 populate_base(type, storage_id, key, key_length, payload, 0, payload_count);
410 ASSERT_ND(!owner_id->xct_id_.is_deleted());
412 if (payload_count_ > 0U) {
413 const char* log_payload = get_payload();
446 populate_base(type, storage_id, key, key_length, payload, payload_offset, payload_count);
455 ASSERT_ND(!owner_id->xct_id_.is_deleted());
457 if (payload_count_ > 0U) {
458 const char* log_payload = get_payload();
479 #endif // FOEDUS_STORAGE_MASSTREE_MASSTREE_LOG_TYPES_HPP_
LogCode
A unique identifier of all log types.
Base class for log type of storage-wide operation.
0x0033 : foedus::storage::masstree::MasstreeInsertLogType .
void apply_record(thread::Thread *, StorageId, xct::RwLockableXctId *owner_id, char *data) const __attribute__((always_inline))
T align8(T value)
8-alignment.
const uint64_t kSliceLen
Shorthand for sizeof(KeySlice).
uint16_t PayloadLength
Represents a byte-length of a payload in this package.
Definitions of IDs in this package and a few related constant values.
#define CXX11_NULLPTR
Used in public headers in place of "nullptr" of C++11.
Page * to_page(const void *address)
super-dirty way to obtain Page the address belongs to.
Log type of CREATE MASSTREE STORAGE operation.
uint32_t StorageId
Unique ID for storage.
Root package of FOEDUS (Fast Optimistic Engine for Data Unification Services).
void apply_record(thread::Thread *, StorageId, xct::RwLockableXctId *owner_id, char *data) const __attribute__((always_inline))
Represents one thread running on one NUMA core.
uint16_t DataOffset
Byte-offset in a page.
const char * get_key() const
const DataOffset kBorderPageDataPartOffset
Offset of data_ member in MasstreeBorderPage.
XctId xct_id_
the second 64bit: Persistent status part of TID.
uint64_t KeySlice
Each key slice is an 8-byte integer.
void assert_valid() const __attribute__((always_inline))
Declares common log types used in all packages.
A base class for MasstreeInsertLogType/MasstreeDeleteLogType/MasstreeOverwriteLogType.
Definitions of IDs in this package and a few related constant values.
uint16_t KeyLength
Represents a byte-length of a key in this package.
#define ASSUME_ALIGNED(x, y)
Wraps GCC's __builtin_assume_aligned.
Log type of masstree-storage's insert operation.
#define LIKELY(x)
Hints that x is highly likely true.
PayloadLength * record_payload_count_
void assert_valid() const __attribute__((always_inline))
The MCS reader-writer lock variant of LockableXctId.
0x0032 : foedus::storage::masstree::MasstreeOverwriteLogType .
RecordAddresses apply_record_prepare(xct::RwLockableXctId *owner_id, char *record) const
Common parts of apply_record() in these log types that extract relevant addresses from the record hea...
MasstreeMetadata metadata_
void populate_base(log::LogCode type, StorageId storage_id, const void *key, KeyLength key_length, const void *payload=nullptr, PayloadLength payload_offset=0, PayloadLength payload_count=0) __attribute__((always_inline))
Log type of masstree-storage's delete operation.
void assert_valid() const __attribute__((always_inline))
static int compare_logs(const MasstreeCommonLogType *left, const MasstreeCommonLogType *right) __attribute__((always_inline))
Returns -1, 0, 1 when left is less than, same, larger than right in terms of key and xct_id...
Log type of masstree-storage's overwrite operation.
uint8_t extract_page_layer(const void *in_page_pointer)
Retrieve masstree layer information from the header of the page that contains the pointer...
Database engine object that holds all resources and provides APIs.
void apply_storage(Engine *engine, StorageId storage_id)
void assert_valid() const __attribute__((always_inline))
friend std::ostream & operator<<(std::ostream &o, const MasstreeCreateLogType &v)
bool is_next_layer() const __attribute__((always_inline))
Just a marker to denote that the memory region represents a data page.
void apply_record(thread::Thread *, StorageId, xct::RwLockableXctId *owner_id, char *data) const __attribute__((always_inline))
bool equal_record_and_log_suffixes(const char *data) const
used only for sanity check.
Log type of masstree-storage's update operation.
KeyLength get_key_length_aligned() const
static uint16_t calculate_log_length(KeyLength key_length, PayloadLength payload_count) __attribute__((always_inline))
0x0034 : foedus::storage::masstree::MasstreeDeleteLogType .
void apply_record(thread::Thread *, StorageId, xct::RwLockableXctId *owner_id, char *data) const __attribute__((always_inline))
0x0035 : foedus::storage::masstree::MasstreeUpdateLogType .
bool is_key_aligned_and_zero_padded(const char *key, KeyLength key_length)
Returns if the given key is 8-bytes aligned and also zero-padded to 8-bytes for easier slicing (which...
#define LOG_TYPE_NO_CONSTRUCT(clazz)
Macro to delete all constructors/destructors to prevent misuse for log type classes.
const char * get_payload() const
void populate(StorageId storage_id, const void *key, KeyLength key_length) __attribute__((always_inline))
PageHeader & get_header()
At least the basic header exists in all pages.
KeySlice get_first_slice() const
Base class for log type of record-wise operation.
Forward declarations of classes in masstree storage package.
bool is_moved() 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'...
#define ALWAYS_INLINE
A function suffix to hint that the function should always be inlined.
void assert_valid_generic() __attribute__((always_inline))
Verifies the log contains essential fields set.
const uint16_t kPageSize
A constant defining the page size (in bytes) of both snapshot pages and volatile pages.
KeySlice normalize_be_bytes_full_aligned(const void *be_bytes)
Convert an aligned big-endian byte array of at least 8-bytes-length to KeySlice.
bool is_keylocked() const __attribute__((always_inline))