20 #include <glog/logging.h>
72 o <<
"<MasstreeStorage>"
73 <<
"<id>" << v.
get_id() <<
"</id>"
74 <<
"<name>" << v.
get_name() <<
"</name>"
75 <<
"</MasstreeStorage>";
87 if (key_length ==
sizeof(
KeySlice)) {
116 if (key_length ==
sizeof(
KeySlice)) {
119 context, slice, payload, payload_offset, payload_count, read_only);
138 template <
typename PAYLOAD>
147 if (key_length ==
sizeof(
KeySlice)) {
149 return get_record_primitive_normalized<PAYLOAD>(
150 context, slice, payload, payload_offset, read_only);
211 template <
typename PAYLOAD>
236 ASSERT_ND(physical_payload_hint >= payload_count);
237 if (physical_payload_hint < payload_count) {
238 physical_payload_hint = payload_count;
244 return physical_payload_hint;
255 if (key_length ==
sizeof(
KeySlice)) {
271 physical_payload_hint,
299 physical_payload_hint,
317 if (key_length ==
sizeof(
KeySlice)) {
344 return pimpl.
delete_general(context, location, &be_key,
sizeof(be_key));
355 if (key_length ==
sizeof(
KeySlice)) {
371 physical_payload_hint,
399 physical_payload_hint,
420 if (key_length ==
sizeof(
KeySlice)) {
443 template <
typename PAYLOAD>
451 if (key_length ==
sizeof(
KeySlice)) {
453 return overwrite_record_primitive_normalized<PAYLOAD>(context, slice, payload, payload_offset);
498 template <
typename PAYLOAD>
522 template <
typename PAYLOAD>
530 if (key_length ==
sizeof(
KeySlice)) {
532 return increment_record_normalized<PAYLOAD>(context, slice, value, payload_offset);
552 template <
typename PAYLOAD>
582 uint32_t max_pages) {
592 bool install_volatile,
606 uint32_t desired_count,
607 bool disable_no_record_split) {
618 if (key_length > (layer + 1U) *
sizeof(
KeySlice)) {
629 #define EXPIN_1(x) template ErrorCode MasstreeStorage::get_record_primitive< x > \
630 (thread::Thread* context, const void* key, KeyLength key_length, x* payload, \
631 PayloadLength payload_offset, bool read_only)
634 #define EXPIN_2(x) template ErrorCode \
635 MasstreeStorage::get_record_primitive_normalized< x > \
636 (thread::Thread* context, KeySlice key, x* payload, PayloadLength payload_offset, bool read_only)
639 #define EXPIN_3(x) template ErrorCode MasstreeStorage::overwrite_record_primitive< x > \
640 (thread::Thread* context, const void* key, KeyLength key_length, x payload, \
641 PayloadLength payload_offset)
644 #define EXPIN_4(x) template ErrorCode \
645 MasstreeStorage::overwrite_record_primitive_normalized< x > \
646 (thread::Thread* context, KeySlice key, x payload, PayloadLength payload_offset)
649 #define EXPIN_5(x) template ErrorCode MasstreeStorage::increment_record< x > \
650 (thread::Thread* context, const void* key, KeyLength key_length, x* value, \
651 PayloadLength payload_offset)
654 #define EXPIN_6(x) template ErrorCode MasstreeStorage::increment_record_normalized< x > \
655 (thread::Thread* context, KeySlice key, x* value, PayloadLength payload_offset)
ErrorCode get_record_normalized(thread::Thread *context, KeySlice key, void *payload, PayloadLength *payload_capacity, bool read_only)
Retrieves an entire record of the given primitive key in this Masstree.
T align8(T value)
8-alignment.
uint16_t PayloadLength
Represents a byte-length of a payload in this package.
ErrorStack fatify_first_root(thread::Thread *context, uint32_t desired_count, bool disable_no_record_split)
Defined in masstree_storage_fatify.cpp.
uint16_t SlotIndex
Index of a record in a (border) page.
std::ostream & operator<<(std::ostream &o, const MasstreeComposeContext::PathLevel &v)
ErrorCode reserve_record_normalized(thread::Thread *context, KeySlice key, PayloadLength payload_count, PayloadLength physical_payload_hint, RecordLocation *result)
ErrorCode locate_record_normalized(thread::Thread *context, KeySlice key, bool for_writes, RecordLocation *result)
Identifies page and record for the normalized key.
StorageType get_type() const
Returns the type of this storage.
ErrorCode increment_record_normalized(thread::Thread *context, KeySlice key, PAYLOAD *value, PayloadLength payload_offset)
For primitive key.
uint32_t StorageId
Unique ID for storage.
Root package of FOEDUS (Fast Optimistic Engine for Data Unification Services).
ErrorStack create(const Metadata &metadata)
Represents one thread running on one NUMA core.
ErrorCode retrieve_part_general(thread::Thread *context, const RecordLocation &location, void *payload, PayloadLength payload_offset, PayloadLength payload_count)
const uint32_t kBorderPageSlotSize
Byte size of one slot in MasstreeBorderPage excluding slice information.
ErrorCode upsert_record(thread::Thread *context, const void *key, KeyLength key_length, const void *payload, PayloadLength payload_count) __attribute__((always_inline))
Inserts a new record of the given key or replaces the existing one, or so-called upsert.
Declares all log types used in this storage type.
Brings error stacktrace information as return value of functions.
ErrorCode prefetch_pages_normalized(thread::Thread *context, bool install_volatile, bool cache_snapshot, KeySlice from, KeySlice to)
defined in masstree_storage_prefetch.cpp
Engine * engine_
Most attachable object stores an engine pointer (local engine), so we define it here.
ErrorCode overwrite_general(thread::Thread *context, const RecordLocation &location, const void *be_key, KeyLength key_length, const void *payload, PayloadLength payload_offset, PayloadLength payload_count)
implementation of overwrite_record family.
uint64_t KeySlice
Each key slice is an 8-byte integer.
ErrorCode retrieve_general(thread::Thread *context, const RecordLocation &location, void *payload, PayloadLength *payload_capacity)
implementation of get_record family.
0x0808 : "STORAGE: Payload of the record is too long" .
uint16_t KeyLength
Represents a byte-length of a key in this package.
ErrorCode upsert_record_normalized(thread::Thread *context, KeySlice key, const void *payload, PayloadLength payload_count) __attribute__((always_inline))
Upserts a new record of the given primitive key in this Masstree.
KeySlice normalize_be_bytes_full(const void *be_bytes)
Convert a big-endian byte array of at least 8-bytes-length to KeySlice.
MasstreeStorage & operator=(const MasstreeStorage &other)
ErrorStack load(const StorageControlBlock &snapshot_block)
ErrorCode get_record_part_normalized(thread::Thread *context, KeySlice key, void *payload, PayloadLength payload_offset, PayloadLength payload_count, bool read_only)
Retrieves a part of the given primitive key in this Masstree.
uint64_t htobe< uint64_t >(uint64_t host_value)
Represents one key-value store.
uint8_t Layer
Represents the depth of a B-trie layer.
ErrorCode get_record_primitive(thread::Thread *context, const void *key, KeyLength key_length, PAYLOAD *payload, PayloadLength payload_offset, bool read_only)
Retrieves a part of the given key in this Masstree as a primitive value.
ErrorCode insert_general(thread::Thread *context, const RecordLocation &location, const void *be_key, KeyLength key_length, const void *payload, PayloadLength payload_count)
implementation of insert_record family.
ErrorCode prefetch_pages_normalized(thread::Thread *context, bool install_volatile, bool cache_snapshot, KeySlice from=kInfimumSlice, KeySlice to=kSupremumSlice)
Prefetch data pages in this storage.
PayloadLength adjust_payload_hint(PayloadLength payload_count, PayloadLength physical_payload_hint)
MasstreeStorageControlBlock * control_block_
The shared data on shared memory that has been initialized in some SOC or master engine.
const StorageName & get_name() const
Returns the unique name of this storage.
ErrorCode reserve_record(thread::Thread *context, const void *key, KeyLength key_length, PayloadLength payload_count, PayloadLength physical_payload_hint, RecordLocation *result)
Like locate_record(), this is also a logical operation.
bool exists() const
Returns whether this storage is already created.
ErrorStack fatify_first_root(thread::Thread *context, uint32_t desired_count, bool disable_no_record_split=true)
Deliberately causes splits under the volatile root of first layer, or "fatify" it.
ErrorCode get_record(thread::Thread *context, const void *key, KeyLength key_length, void *payload, PayloadLength *payload_capacity, bool read_only)
Retrieves an entire record of the given key in this Masstree.
Database engine object that holds all resources and provides APIs.
const SlotIndex kBorderPageMaxSlots
Maximum number of slots in one MasstreeBorderPage.
const uint32_t kBorderPageDataPartSize
Byte size of the record data part (data_) in MasstreeBorderPage.
static SlotIndex estimate_records_per_page(Layer layer, KeyLength key_length, PayloadLength payload_length)
StorageId get_id() const
Returns the unique ID of this storage.
ErrorCode overwrite_record_normalized(thread::Thread *context, KeySlice key, const void *payload, PayloadLength payload_offset, PayloadLength payload_count)
Overwrites a part of one record of the given primitive key in this Masstree.
Pimpl object of MasstreeStorage.
ErrorStack load(const StorageControlBlock &snapshot_block)
ErrorCode delete_record_normalized(thread::Thread *context, KeySlice key)
Deletes a record of the given primitive key from this Masstree.
Represents a Masstree storage.
const PayloadLength kMaxPayloadLength
Max length of a payload.
ErrorCode increment_general(thread::Thread *context, const RecordLocation &location, const void *be_key, KeyLength key_length, PAYLOAD *value, PayloadLength payload_offset)
implementation of increment_record family.
ErrorStack debugout_single_thread(Engine *engine, bool volatile_only=false, uint32_t max_pages=1024U)
A super-expensive and single-thread only debugging feature to write out gigantic human-readable texts...
ErrorStack verify_single_thread(thread::Thread *context)
ErrorCode delete_general(thread::Thread *context, const RecordLocation &location, const void *be_key, KeyLength key_length)
implementation of delete_record family.
ErrorCode delete_record(thread::Thread *context, const void *key, KeyLength key_length)
Deletes a record of the given key from this Masstree.
ErrorStack hcc_reset_all_temperature_stat()
Resets all volatile pages' temperature stat to be zero in this storage.
ErrorCode insert_record_normalized(thread::Thread *context, KeySlice key, const void *payload, PayloadLength payload_count) __attribute__((always_inline))
Inserts a new record of the given primitive key in this Masstree.
Shared data of this storage type.
#define CHECK_ERROR_CODE(x)
This macro calls x and checks its returned error code.
ErrorCode get_record_part(thread::Thread *context, const void *key, KeyLength key_length, void *payload, PayloadLength payload_offset, PayloadLength payload_count, bool read_only)
Retrieves a part of the given key in this Masstree.
ErrorCode increment_record(thread::Thread *context, const void *key, KeyLength key_length, PAYLOAD *value, PayloadLength payload_offset)
This one further optimizes overwrite methods for the frequent use case of incrementing some data in p...
ErrorStack hcc_reset_all_temperature_stat()
For stupid reasons (I'm lazy!) these are defined in _debug.cpp.
ErrorStack verify_single_thread(thread::Thread *context)
These are defined in masstree_storage_verify.cpp.
ErrorStack drop()
Storage-wide operations, such as drop, create, etc.
ErrorCode get_record_primitive_normalized(thread::Thread *context, KeySlice key, PAYLOAD *payload, PayloadLength payload_offset, bool read_only)
Retrieves a part of the given primitive key in this Masstree as a primitive value.
ErrorCode overwrite_record_primitive_normalized(thread::Thread *context, KeySlice key, PAYLOAD payload, PayloadLength payload_offset)
Overwrites a part of one record of the given primitive key in this Masstree as a primitive value...
ErrorStack create(const MasstreeMetadata &metadata)
#define INSTANTIATE_ALL_NUMERIC_TYPES(M)
INSTANTIATE_ALL_TYPES minus std::string.
ErrorCode overwrite_record(thread::Thread *context, const void *key, KeyLength key_length, const void *payload, PayloadLength payload_offset, PayloadLength payload_count)
Overwrites a part of one record of the given key in this Masstree.
#define UNLIKELY(x)
Hints that x is highly likely false.
#define ASSERT_ND(x)
A warning-free wrapper macro of assert() that has no performance effect in release mode even when 'x'...
ErrorCode upsert_general(thread::Thread *context, const RecordLocation &location, const void *be_key, KeyLength key_length, const void *payload, PayloadLength payload_count)
implementation of upsert_record family.
ErrorCode overwrite_record_primitive(thread::Thread *context, const void *key, KeyLength key_length, PAYLOAD payload, PayloadLength payload_offset)
Overwrites a part of one record of the given key in this Masstree as a primitive value.
A base layout of shared data for all storage types.
return value of MasstreeStoragePimpl::locate_record()/reserve_record().
ErrorCode insert_record(thread::Thread *context, const void *key, KeyLength key_length, const void *payload, PayloadLength payload_count) __attribute__((always_inline))
Inserts a new record of the given key in this Masstree.
ErrorCode
Enum of error codes defined in error_code.xmacro.
const MasstreeMetadata * get_masstree_metadata() const
ErrorCode locate_record(thread::Thread *context, const void *key, KeyLength key_length, bool for_writes, RecordLocation *result)
Identifies page and record for the key.
ErrorStack debugout_single_thread(Engine *engine, bool volatile_only, uint32_t max_pages)
These are defined in masstree_storage_debug.cpp.