libfoedus-core
FOEDUS Core Library
|
An in-memory single-threaded data structure to compose tuples in a hash bin. More...
An in-memory single-threaded data structure to compose tuples in a hash bin.
This object is used in the hash composer to organize data pages for each hash bin, applying log entries to existing tuples. In essense, it is another hash-table where bucket is low-bits (while bin-bits use high-bits). For testability and modularity, we separated this to its own class.
Definition at line 54 of file hash_tmpbin.hpp.
#include <hash_tmpbin.hpp>
Classes | |
struct | Record |
Represents a record with a unique key. More... | |
Public Types | |
enum | Constants { kBucketCount = 1 << 16, kDefaultInitialSize = 1 << 24 } |
typedef uint32_t | RecordIndex |
Pointer to Record. More... | |
Public Member Functions | |
HashTmpBin () | |
Constructor doesn't do any initialization. More... | |
ErrorCode | create_memory (uint16_t numa_node, uint64_t initial_size=kDefaultInitialSize) |
Allocates the memory to use by this object. More... | |
void | release_memory () |
Destructor automatically releases everything, but you can use this to do it earlier. More... | |
void | steal_memory (memory::AlignedMemory *provider) |
This is a special version of create_memory() where this object steals the memory ownership from the recipient. More... | |
void | give_memory (memory::AlignedMemory *recipient) |
This is a special version of release_memory() where this object moves the memory ownership to the recipient. More... | |
void | clean () |
Removes all tuple data for the current bin. More... | |
void | clean_quick () |
This version selectively clears buckets_ by seeing individual records. More... | |
Record * | get_record (RecordIndex index) const |
RecordIndex | get_records_capacity () const |
RecordIndex | get_records_consumed () const |
RecordIndex | get_first_record () const |
uint32_t | get_physical_record_count () const |
RecordIndex | get_bucket_head (uint32_t bucket) const |
ErrorCode | insert_record (xct::XctId xct_id, const void *key, uint16_t key_length, HashValue hash, const void *payload, uint16_t payload_length) |
Inserts a new record of the given key and payload. More... | |
ErrorCode | delete_record (xct::XctId xct_id, const void *key, uint16_t key_length, HashValue hash) |
Logically deletes a record of the given key. More... | |
ErrorCode | overwrite_record (xct::XctId xct_id, const void *key, uint16_t key_length, HashValue hash, const void *payload, uint16_t payload_offset, uint16_t payload_count) |
Overwrites a part of the record of the given key. More... | |
ErrorCode | update_record (xct::XctId xct_id, const void *key, uint16_t key_length, HashValue hash, const void *payload, uint16_t payload_length) |
Updates a record of the given key with the given payload, which might change length. More... | |
Friends | |
std::ostream & | operator<< (std::ostream &o, const HashTmpBin &v) |
typedef uint32_t foedus::storage::hash::HashTmpBin::RecordIndex |
Definition at line 56 of file hash_tmpbin.hpp.
foedus::storage::hash::HashTmpBin::HashTmpBin | ( | ) |
Constructor doesn't do any initialization.
You must call create_memory() before using.
Definition at line 32 of file hash_tmpbin.cpp.
void foedus::storage::hash::HashTmpBin::clean | ( | ) |
Removes all tuple data for the current bin.
The memory is kept so that we can efficiently reuse resources for next bins to process.
This is a full cleaning method that can be used anytime, but costs a bit more. When there were few records, it is a bit expensive to mem-zero the entire buckets_. In that case, use clean_quick()
Definition at line 74 of file hash_tmpbin.cpp.
References get_first_record().
Referenced by create_memory(), foedus::storage::hash::HashComposeContext::execute(), give_memory(), release_memory(), and steal_memory().
void foedus::storage::hash::HashTmpBin::clean_quick | ( | ) |
This version selectively clears buckets_ by seeing individual records.
Hence, this can be used only after records_consumed_ is populated. Instead, when there are just a few records, this is much faster than clean().
Definition at line 81 of file hash_tmpbin.cpp.
References ASSERT_ND, get_first_record(), get_record(), and foedus::storage::hash::HashTmpBin::Record::hash_.
ErrorCode foedus::storage::hash::HashTmpBin::create_memory | ( | uint16_t | numa_node, |
uint64_t | initial_size = kDefaultInitialSize |
||
) |
Allocates the memory to use by this object.
Must be called before using this object.
[in] | numa_node | the NUMA node to allocate this object's memory on |
[in] | initial_size | byte size of the memory to start from. |
Definition at line 36 of file hash_tmpbin.cpp.
References foedus::memory::AlignedMemory::alloc(), ASSERT_ND, clean(), kBucketCount, foedus::kErrorCodeOk, foedus::memory::AlignedMemory::kNumaAllocOnnode, and foedus::storage::kPageSize.
Referenced by foedus::storage::hash::HashComposeContext::execute().
ErrorCode foedus::storage::hash::HashTmpBin::delete_record | ( | xct::XctId | xct_id, |
const void * | key, | ||
uint16_t | key_length, | ||
HashValue | hash | ||
) |
Logically deletes a record of the given key.
If there is no existing record of the key, or such a record is already logically deleted, this method returns an error (kErrorCodeStrKeyNotFound). Mustn't happen either.
Definition at line 167 of file hash_tmpbin.cpp.
References ASSERT_ND, foedus::xct::XctId::compare_epoch_and_orginal(), get_record(), foedus::storage::hash::HashTmpBin::Record::hash_, foedus::storage::hash::hashinate(), foedus::xct::XctId::is_deleted(), foedus::kErrorCodeOk, foedus::kErrorCodeStrKeyNotFound, UNLIKELY, and foedus::storage::hash::HashTmpBin::Record::xct_id_.
|
inline |
Definition at line 211 of file hash_tmpbin.hpp.
References ASSERT_ND, and kBucketCount.
|
inline |
Definition at line 204 of file hash_tmpbin.hpp.
References kBucketCount.
Referenced by clean(), clean_quick(), get_physical_record_count(), and foedus::storage::hash::operator<<().
|
inline |
Definition at line 208 of file hash_tmpbin.hpp.
References get_first_record(), and get_records_consumed().
|
inline |
Definition at line 197 of file hash_tmpbin.hpp.
References ASSERT_ND, and kBucketCount.
Referenced by clean_quick(), delete_record(), insert_record(), foedus::storage::hash::operator<<(), overwrite_record(), and update_record().
|
inline |
Definition at line 202 of file hash_tmpbin.hpp.
|
inline |
Definition at line 203 of file hash_tmpbin.hpp.
Referenced by get_physical_record_count(), and foedus::storage::hash::operator<<().
void foedus::storage::hash::HashTmpBin::give_memory | ( | memory::AlignedMemory * | recipient | ) |
This is a special version of release_memory() where this object moves the memory ownership to the recipient.
Combined with steal_memory(), this allows completely reusing memory.
[in,out] | recipient | the memory to receive the ownership of memory this object has |
Definition at line 64 of file hash_tmpbin.cpp.
References ASSERT_ND, clean(), and foedus::memory::AlignedMemory::is_null().
ErrorCode foedus::storage::hash::HashTmpBin::insert_record | ( | xct::XctId | xct_id, |
const void * | key, | ||
uint16_t | key_length, | ||
HashValue | hash, | ||
const void * | payload, | ||
uint16_t | payload_length | ||
) |
Inserts a new record of the given key and payload.
If there is an existing record of the key that is logically deleted, we flip the deletion flag. If such an record exists and also is not logically deleted, this method returns an error (kErrorCodeStrKeyAlreadyExists). Considering how this object is used, it mustn't hapepn.
Definition at line 126 of file hash_tmpbin.cpp.
References ASSERT_ND, CHECK_ERROR_CODE, foedus::xct::XctId::compare_epoch_and_orginal(), get_record(), foedus::storage::hash::HashTmpBin::Record::hash_, foedus::storage::hash::hashinate(), foedus::xct::XctId::is_deleted(), foedus::kErrorCodeOk, foedus::kErrorCodeStrKeyAlreadyExists, foedus::storage::hash::HashTmpBin::Record::next_, foedus::storage::hash::HashTmpBin::Record::set_all(), foedus::storage::hash::HashTmpBin::Record::set_payload(), UNLIKELY, and foedus::storage::hash::HashTmpBin::Record::xct_id_.
ErrorCode foedus::storage::hash::HashTmpBin::overwrite_record | ( | xct::XctId | xct_id, |
const void * | key, | ||
uint16_t | key_length, | ||
HashValue | hash, | ||
const void * | payload, | ||
uint16_t | payload_offset, | ||
uint16_t | payload_count | ||
) |
Overwrites a part of the record of the given key.
If there is no existing record of the key, or such a record is already logically deleted, this method returns an error (kErrorCodeStrKeyNotFound). Mustn't happen either.
Definition at line 194 of file hash_tmpbin.cpp.
References ASSERT_ND, foedus::xct::XctId::compare_epoch_and_orginal(), get_record(), foedus::storage::hash::HashTmpBin::Record::hash_, foedus::storage::hash::hashinate(), foedus::xct::XctId::is_deleted(), foedus::kErrorCodeOk, foedus::kErrorCodeStrKeyNotFound, foedus::kErrorCodeStrTooShortPayload, foedus::storage::hash::HashTmpBin::Record::overwrite_payload(), foedus::storage::hash::HashTmpBin::Record::payload_length_, UNLIKELY, and foedus::storage::hash::HashTmpBin::Record::xct_id_.
void foedus::storage::hash::HashTmpBin::release_memory | ( | ) |
Destructor automatically releases everything, but you can use this to do it earlier.
Definition at line 49 of file hash_tmpbin.cpp.
References clean(), and foedus::memory::AlignedMemory::release_block().
void foedus::storage::hash::HashTmpBin::steal_memory | ( | memory::AlignedMemory * | provider | ) |
This is a special version of create_memory() where this object steals the memory ownership from the recipient.
Combined with give_memory(), this allows completely reusing memory.
[in,out] | provider | the memory from which this object steals ownership |
Definition at line 55 of file hash_tmpbin.cpp.
References ASSERT_ND, clean(), and foedus::memory::AlignedMemory::is_null().
ErrorCode foedus::storage::hash::HashTmpBin::update_record | ( | xct::XctId | xct_id, |
const void * | key, | ||
uint16_t | key_length, | ||
HashValue | hash, | ||
const void * | payload, | ||
uint16_t | payload_length | ||
) |
Updates a record of the given key with the given payload, which might change length.
This method is same as delete_record()+insert_record(). The difference is that this can be faster because it does only one lookup. If there is no existing record of the key, or such a record is already logically deleted, this method returns an error (kErrorCodeStrKeyNotFound). Mustn't happen either.
Definition at line 229 of file hash_tmpbin.cpp.
References ASSERT_ND, foedus::xct::XctId::compare_epoch_and_orginal(), get_record(), foedus::storage::hash::HashTmpBin::Record::hash_, foedus::storage::hash::hashinate(), foedus::xct::XctId::is_deleted(), foedus::kErrorCodeOk, foedus::kErrorCodeStrKeyNotFound, foedus::storage::hash::HashTmpBin::Record::set_payload(), UNLIKELY, and foedus::storage::hash::HashTmpBin::Record::xct_id_.
|
friend |
Definition at line 287 of file hash_tmpbin.cpp.