18 #ifndef FOEDUS_STORAGE_HASH_LOG_TYPES_HPP_
19 #define FOEDUS_STORAGE_HASH_LOG_TYPES_HPP_
78 uint16_t payload_offset_;
79 uint16_t payload_count_;
93 char aligned_data_[8];
95 static uint16_t calculate_log_length(uint16_t key_length, uint16_t payload_count)
ALWAYS_INLINE {
100 const char*
get_key()
const {
return aligned_data_; }
102 char*
get_payload() {
return aligned_data_ + get_key_length_aligned(); }
103 const char*
get_payload()
const {
return aligned_data_ + get_key_length_aligned(); }
112 uint16_t payload_offset = 0,
117 key_length_ = key_length;
118 payload_offset_ = payload_offset;
119 payload_count_ = payload_count;
120 bin_bits_ = bin_bits;
125 std::memcpy(aligned_data_, key, key_length);
127 if (aligned_key_length != key_length) {
128 std::memset(aligned_data_ + key_length, 0, aligned_key_length - key_length);
130 if (payload_count > 0) {
132 char* payload_base = aligned_data_ + aligned_key_length;
133 std::memcpy(payload_base, payload, payload_count);
134 if (aligned_payload_count != payload_count) {
135 std::memset(payload_base + payload_count, 0, aligned_payload_count - payload_count);
143 const char* log_key = get_key();
145 uint16_t log_key_length_aligned = get_key_length_aligned();
148 uint16_t* lengthes =
reinterpret_cast<uint16_t*
>(owner_id + 1);
154 ASSERT_ND(hash_ == reinterpret_cast<HashValue*>(owner_id + 1)[1]);
156 ASSERT_ND(std::memcmp(log_key, data, log_key_length_aligned) == 0);
181 ASSERT_ND(left->header_.storage_id_ == right->header_.storage_id_);
182 ASSERT_ND(left->bin_bits_ == right->bin_bits_);
188 HashBin left_bin = left->hash_ >> (64U - left->bin_bits_);
189 HashBin right_bin = right->hash_ >> (64U - right->bin_bits_);
190 if (left_bin != right_bin) {
191 if (left_bin < right_bin) {
197 return left->header_.xct_id_.compare_epoch_and_orginal(right->header_.xct_id_);
221 populate_base(type, storage_id, key, key_length, bin_bits, hash, payload, 0, payload_count);
229 ASSERT_ND(owner_id->xct_id_.is_deleted());
230 ASSERT_ND(!owner_id->xct_id_.is_next_layer());
231 ASSERT_ND(!owner_id->xct_id_.is_moved());
235 assert_record_and_log_keys(owner_id, data);
237 uint16_t* lengthes =
reinterpret_cast<uint16_t*
>(owner_id + 1);
241 lengthes[3] = payload_count_;
243 if (payload_count_ > 0U) {
246 uint16_t key_length_aligned = get_key_length_aligned();
247 void* data_payload =
ASSUME_ALIGNED(data + key_length_aligned, 8U);
251 assert_record_and_log_keys(owner_id, data);
252 owner_id->xct_id_.set_notdeleted();
281 populate_base(type, storage_id, key, key_length, bin_bits, hash);
289 ASSERT_ND(!owner_id->xct_id_.is_deleted());
290 ASSERT_ND(!owner_id->xct_id_.is_next_layer());
291 ASSERT_ND(!owner_id->xct_id_.is_moved());
292 assert_record_and_log_keys(owner_id, data);
293 owner_id->xct_id_.set_deleted();
327 populate_base(type, storage_id, key, key_length, bin_bits, hash, payload, 0, payload_count);
335 ASSERT_ND(!owner_id->xct_id_.is_deleted());
336 ASSERT_ND(!owner_id->xct_id_.is_next_layer());
337 ASSERT_ND(!owner_id->xct_id_.is_moved());
341 assert_record_and_log_keys(owner_id, data);
343 uint16_t* lengthes =
reinterpret_cast<uint16_t*
>(owner_id + 1);
347 lengthes[3] = payload_count_;
349 if (payload_count_ > 0U) {
352 uint16_t key_length_aligned = get_key_length_aligned();
353 void* data_payload =
ASSUME_ALIGNED(data + key_length_aligned, 8U);
357 assert_record_and_log_keys(owner_id, data);
387 uint16_t payload_offset,
407 ASSERT_ND(!owner_id->xct_id_.is_deleted());
408 ASSERT_ND(!owner_id->xct_id_.is_next_layer());
409 ASSERT_ND(!owner_id->xct_id_.is_moved());
411 uint16_t key_length_aligned = get_key_length_aligned();
412 assert_record_and_log_keys(owner_id, data);
415 uint16_t* lengthes =
reinterpret_cast<uint16_t*
>(owner_id + 1);
416 ASSERT_ND(payload_offset_ + payload_count_ <= lengthes[3]);
421 std::memcpy(data + key_length_aligned + payload_offset_, get_payload(), payload_count_);
437 #endif // FOEDUS_STORAGE_HASH_LOG_TYPES_HPP_
LogCode
A unique identifier of all log types.
Base class for log type of storage-wide operation.
void assert_valid() __attribute__((always_inline))
T align8(T value)
8-alignment.
Definitions of IDs in this package and a few related constant values.
void assert_type() const __attribute__((always_inline))
#define CXX11_NULLPTR
Used in public headers in place of "nullptr" of C++11.
uint32_t StorageId
Unique ID for storage.
Root package of FOEDUS (Fast Optimistic Engine for Data Unification Services).
Represents one thread running on one NUMA core.
void assert_valid() __attribute__((always_inline))
void apply_record(thread::Thread *, StorageId, xct::RwLockableXctId *owner_id, char *data) const __attribute__((always_inline))
0x002A : foedus::storage::hash::HashDeleteLogType .
friend std::ostream & operator<<(std::ostream &o, const HashCreateLogType &v)
void apply_record(thread::Thread *, StorageId, xct::RwLockableXctId *owner_id, char *data) const __attribute__((always_inline))
Declares common log types used in all packages.
#define ASSUME_ALIGNED(x, y)
Wraps GCC's __builtin_assume_aligned.
const char * get_payload() const
The MCS reader-writer lock variant of LockableXctId.
void apply_storage(Engine *engine, StorageId storage_id)
void assert_valid() __attribute__((always_inline))
Independent utility methods/classes for hashination, or hash functions.
HashValue hashinate(const void *key, uint16_t key_length)
Calculates hash value for general input.
void assert_valid() __attribute__((always_inline))
Definitions of IDs in this package and a few related constant values.
const char * get_key() const
Log type of hash-storage's update operation.
Database engine object that holds all resources and provides APIs.
A base class for HashInsertLogType/HashDeleteLogType/HashOverwriteLogType.
void populate_base(log::LogCode type, StorageId storage_id, const void *key, uint16_t key_length, uint8_t bin_bits, HashValue hash, const void *payload=nullptr, uint16_t payload_offset=0, uint16_t payload_count=0) __attribute__((always_inline))
0x0029 : foedus::storage::hash::HashInsertLogType .
void assert_record_and_log_keys(xct::RwLockableXctId *owner_id, const char *data) const
used only for sanity check.
uint16_t get_key_length_aligned() const
uint64_t HashBin
Represents a bin of a hash value.
Log type of hash-storage's insert operation.
Log type of hash-storage's overwrite operation.
0x0028 : foedus::storage::hash::HashOverwriteLogType .
#define LOG_TYPE_NO_CONSTRUCT(clazz)
Macro to delete all constructors/destructors to prevent misuse for log type classes.
void apply_record(thread::Thread *, StorageId, xct::RwLockableXctId *owner_id, char *data) __attribute__((always_inline))
static int compare_logs(const HashCommonLogType *left, const HashCommonLogType *right) __attribute__((always_inline))
Returns -1, 0, 1 when left is less than, same, larger than right in terms of bin and xct_id...
void apply_record(thread::Thread *, StorageId, xct::RwLockableXctId *owner_id, char *data) 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'...
Definitions of IDs in this package and a few related constant values.
#define ALWAYS_INLINE
A function suffix to hint that the function should always be inlined.
0x002B : foedus::storage::hash::HashUpdateLogType .
void assert_valid_generic() __attribute__((always_inline))
Verifies the log contains essential fields set.
Forward declarations of classes in hash storage package.
Log type of hash-storage's delete operation.
Log type of CREATE HASH STORAGE operation.
uint64_t HashValue
Represents a full 64-bit hash value calculated from a key.