libfoedus-core
FOEDUS Core Library
|
Hashtable Storage, a concurrent hashtable. More...
Hashtable Storage, a concurrent hashtable.
What we have here is a quite simple hash storage. Allthemore simple, more robust and scalable.
The hash storage has two types of pages: HashIntermediatePage and HashDataPage. HashIntermediatePage, starting from the root page, points down to other intermediate pages, and the level-0 intermediate pages point to HashDataPage. HashDataPage has a next-pointer. One entry (pointer) in a level-0 intermediate page corresponds to a hash bin. Usually one hash bin corresponds to a very small number of data pages, zero, one or rarely two.
foedus::storage::hash::HashIntermediatePage foedus::storage::hash::HashDataPage
When a hash bin receives many records or very long key or values, a data page contains a link to next page that forms a singly-linked list of pages. Although this is a dual page pointer, we use only one of them. Snapshot hash pages of course point to only snapshot hash pages. Volatile hash pages, to simplify, also point to only volatile hash pages.
In other words, when we make a volatile version of any page in a hash bin, we instantiate volatile pages for all pages in the hash bin. This might sound costly, but there should be only 1 or only occasionaly a few pages in the bin, assuming 1) bin-bits that is large enough, and 2) good hash function.
Intermediate pages are completely lock-free. Data pages do have per-page and per-tuple locks. Hopefully most locks are per-tuple, meaning just taking the TID of the tuple as read-set or write-set. However, there are a few cases the thread must take an exclusive lock in page-header.
All of the above are quite similar to masstree package's insertion/splits/miss-search. Like masstree package, the full-hash/key of a physical tuple is immutable once installed. We only use logical deletion flags and "moved" bits to allow record expansion. Also like masstree, other operations proceed without locks or in many cases even atomic operations, just a few memory barriers. For example, deletion just puts a logical deletion flag to the record without page-lock. Reading is completely atomics-free as far as you find the exact record (miss-search is a bit more complicated as above).
To implement the above protocol, the moved bit in TID has a bit different meaning from masstree package. It means that the corresponding record for the full-hash/key is somewhere later in the list. When we need to expand a record space that is not at the end, we insert a new physical tuple for the record with large space, then put the "moved" bit in the original physical record. If threads see the flag while processing, it skips such a record. If pre-commit sees the flag because of concurrent migration, it tracks the moved record just like Master-Tree protocol. The idea is almost the same, but here the tracking is much simpler. Just follow the linked list.
Classes | |
struct | BloomFilterFingerprint |
A fingerprint for bloom filter in each HashDataPage. More... | |
struct | ComposedBin |
Represents an output of composer on one bin. More... | |
struct | ComposedBinsBuffer |
Abstracts how we batch-read several HashComposedBinsPage emit from individual composers. More... | |
struct | ComposedBinsMergedStream |
Packages all ComposedBinsBuffer to easily extract bins of current interest. More... | |
struct | DataPageBloomFilter |
To quickly check whether a HashDataPage might contain a specific hash value, we maintain a non-counting bloom filter in each page. More... | |
struct | HashBinRange |
Represents a range of hash bins in a hash storage, such as what an intermediate page is responsible for. More... | |
struct | HashCombo |
A set of information that are used in many places, extracted from the given key. More... | |
struct | HashCommonLogType |
A base class for HashInsertLogType/HashDeleteLogType/HashOverwriteLogType. More... | |
class | HashComposeContext |
HashComposer's compose() implementation separated from the class itself. More... | |
struct | HashComposedBinsPage |
A page to pack many ComposedBin as an output of composer. More... | |
class | HashComposer |
Composer for a hash storage. More... | |
struct | HashCreateLogType |
Log type of CREATE HASH STORAGE operation. More... | |
class | HashDataPage |
Represents an individual data page in Hashtable Storage. More... | |
struct | HashDeleteLogType |
Log type of hash-storage's delete operation. More... | |
struct | HashInsertLogType |
Log type of hash-storage's insert operation. More... | |
class | HashIntermediatePage |
Represents an intermediate page in Hashtable Storage. More... | |
struct | HashMetadata |
Metadata of an hash storage. More... | |
struct | HashMetadataSerializer |
struct | HashOverwriteLogType |
Log type of hash-storage's overwrite operation. More... | |
class | HashPartitioner |
Partitioner for a hash storage. More... | |
struct | HashPartitionerData |
class | HashStorage |
Represents a key-value store based on a dense and regular hash. More... | |
struct | HashStorageControlBlock |
Shared data of this storage type. More... | |
class | HashStoragePimpl |
Pimpl object of HashStorage. More... | |
class | HashTmpBin |
An in-memory single-threaded data structure to compose tuples in a hash bin. More... | |
struct | HashUpdateLogType |
Log type of hash-storage's update operation. More... | |
union | IntermediateRoute |
Compactly represents the route of intermediate pages to reach the given hash bin. More... | |
struct | RecordLocation |
return value of locate_record(). More... | |
struct | ReserveRecords |
A system transaction to reserve a physical record(s) in a hash data page. More... | |
struct | SortEntry |
Used in sort_batch(). More... | |
struct | TmpSnashotPage |
Typedefs | |
typedef HashIntermediatePage | HashRootInfoPage |
Output of one compose() call, which are then combined in construct_root(). More... | |
typedef uint64_t | HashValue |
Represents a full 64-bit hash value calculated from a key. More... | |
typedef uint64_t | HashBin |
Represents a bin of a hash value. More... | |
typedef uint16_t | DataPageSlotIndex |
typedef uint16_t | KeyLength |
Represents a byte-length of a key in this package. More... | |
typedef uint16_t | PayloadLength |
Represents a byte-length of a payload in this package. More... | |
Functions | |
HashValue | hashinate (const void *key, uint16_t key_length) |
Calculates hash value for general input. More... | |
template<typename T > | |
HashValue | hashinate (T key) |
Calculates hash value for a primitive type. More... | |
uint64_t | fanout_power (uint8_t exponent) |
uint8_t | bins_to_level (uint64_t bins) |
void | hash_intermediate_volatile_page_init (const VolatilePageInitArguments &args) |
volatile page initialize callback for HashIntermediatePage. More... | |
void | hash_data_volatile_page_init (const VolatilePageInitArguments &args) |
volatile page initialize callback for HashDataPage. More... | |
std::ostream & | operator<< (std::ostream &o, const HashCombo &v) |
HashDataPage * | resolve_data_impl (const memory::GlobalVolatilePageResolver &resolver, VolatilePagePointer pointer) |
HashIntermediatePage * | resolve_intermediate_impl (const memory::GlobalVolatilePageResolver &resolver, VolatilePagePointer pointer) |
std::ostream & | operator<< (std::ostream &o, const BloomFilterFingerprint &v) |
std::ostream & | operator<< (std::ostream &o, const IntermediateRoute &v) |
std::ostream & | operator<< (std::ostream &o, const DataPageBloomFilter &v) |
std::ostream & | operator<< (std::ostream &o, const HashBinRange &v) |
std::ostream & | operator<< (std::ostream &o, const HashCreateLogType &v) |
std::ostream & | operator<< (std::ostream &o, const HashInsertLogType &v) |
std::ostream & | operator<< (std::ostream &o, const HashDeleteLogType &v) |
std::ostream & | operator<< (std::ostream &o, const HashUpdateLogType &v) |
std::ostream & | operator<< (std::ostream &o, const HashOverwriteLogType &v) |
std::ostream & | operator<< (std::ostream &o, const HashMetadata &v) |
std::ostream & | operator<< (std::ostream &o, const HashIntermediatePage &v) |
std::ostream & | operator<< (std::ostream &o, const HashDataPage &v) |
void | release_parallel (Engine *engine, VolatilePagePointer pointer) |
void | design_partition_thread (HashPartitioner *partitioner, uint16_t task) |
void | prepare_sort_entries (uint8_t bin_shifts, const Partitioner::SortBatchArguments &args, SortEntry *entries) |
subroutine of sort_batch More... | |
uint32_t | compact_logs (uint8_t, const Partitioner::SortBatchArguments &args, SortEntry *entries) |
subroutine of sort_batch More... | |
std::ostream & | operator<< (std::ostream &o, const HashPartitioner &v) |
std::ostream & | operator<< (std::ostream &o, const HashStorage &v) |
uint16_t | adjust_payload_hint (uint16_t payload_count, uint16_t physical_payload_hint) |
std::ostream & | operator<< (std::ostream &o, const HashTmpBin &v) |
Variables | |
const uint16_t | kHashComposedBinsPageMaxBins = (kPageSize - 80) / sizeof(ComposedBin) |
const uint64_t | kXxhashKeySeed = 0x3f119e0435262a17ULL |
Default seed value used for xxhash's xxh32/64 to hashinate keys. More... | |
const uint16_t | kHashDataPageBloomFilterBytes = 64 |
Byte size of bloom filter in each HashDataPage. More... | |
const uint16_t | kHashDataPageBloomFilterBits = kHashDataPageBloomFilterBytes * 8 |
Bit size of bloom filter in each HashDataPage. More... | |
const uint8_t | kHashDataPageBloomFilterIndexSize = 9U |
How many bits we need in order to represent an index in bloom filter in each HashDataPage. More... | |
const HashValue | kHashDataPageBloomFilterIndexMask = (1U << kHashDataPageBloomFilterIndexSize) - 1U |
const uint8_t | kHashDataPageBloomFilterHashes = 3 |
Number of hash functions (k) of bloom filter in each HashDataPage. More... | |
const uint16_t | kHashIntermediatePageHeaderSize = 64 |
Byte size of header in an intermediate page of hash storage. More... | |
const uint8_t | kHashIntermediatePageFanout |
Number of pointers in an intermediate page of hash storage. More... | |
const uint64_t | kFanout64 = kHashIntermediatePageFanout |
just to write the following concisely More... | |
const uint64_t | kHashMaxBins [] |
kHashTotalBins[n] gives the maximum number of hash bins n-level hash can hold. More... | |
const uint8_t | kHashMaxLevels = 8 |
Max level of intermediate pages. More... | |
const uint16_t | kHashDataPageHeaderSize = 128 |
Byte size of header in data page of hash storage. More... | |
const uint16_t | kHashDataPageDataSize = kPageSize - kHashDataPageHeaderSize |
Body data byte size in data page of hash storage. More... | |
const uint8_t | kHashMinBinBits = 7U |
Minimum number allowed for bin-bits. More... | |
const uint8_t | kHashMaxBinBits = 48U |
Maximum number allowed for bin-bits. More... | |
const HashBin | kInvalidHashBin = 1ULL << kHashMaxBinBits |
This value or larger never appears as a valid HashBin. More... | |
const DataPageSlotIndex | kSlotNotFound = 0xFFFFU |
typedef uint16_t foedus::storage::hash::DataPageSlotIndex |
Definition at line 196 of file hash_id.hpp.
uint16_t foedus::storage::hash::adjust_payload_hint | ( | uint16_t | payload_count, |
uint16_t | physical_payload_hint | ||
) |
Definition at line 250 of file hash_storage_pimpl.cpp.
References foedus::assorted::align8(), and ASSERT_ND.
Referenced by foedus::storage::hash::HashStoragePimpl::insert_record(), and foedus::storage::hash::HashStoragePimpl::upsert_record().
uint32_t foedus::storage::hash::compact_logs | ( | uint8_t | , |
const Partitioner::SortBatchArguments & | args, | ||
SortEntry * | entries | ||
) |
subroutine of sort_batch
Definition at line 261 of file hash_partitioner_impl.cpp.
References foedus::storage::hash::SortEntry::get_position(), foedus::storage::Partitioner::SortBatchArguments::logs_count_, and foedus::storage::Partitioner::SortBatchArguments::output_buffer_.
Referenced by foedus::storage::hash::HashPartitioner::sort_batch().
void foedus::storage::hash::design_partition_thread | ( | HashPartitioner * | partitioner, |
uint16_t | task | ||
) |
Definition at line 64 of file hash_partitioner_impl.cpp.
References foedus::storage::hash::HashPartitioner::design_partition_task().
Referenced by foedus::storage::hash::HashPartitioner::design_partition().
std::ostream& foedus::storage::hash::operator<< | ( | std::ostream & | o, |
const HashBinRange & | v | ||
) |
Defined in hash_id.cpp
Definition at line 28 of file hash_id.cpp.
References foedus::storage::hash::HashBinRange::begin_, and foedus::storage::hash::HashBinRange::end_.
std::ostream& foedus::storage::hash::operator<< | ( | std::ostream & | o, |
const HashIntermediatePage & | v | ||
) |
Definition at line 31 of file hash_page_debug.cpp.
References foedus::storage::hash::HashBinRange::begin_, foedus::storage::hash::HashIntermediatePage::get_bin_range(), foedus::storage::hash::HashIntermediatePage::get_level(), foedus::storage::hash::HashIntermediatePage::get_pointer(), foedus::storage::hash::HashIntermediatePage::header(), foedus::storage::DualPagePointer::is_both_null(), kHashIntermediatePageFanout, and kHashMaxBins.
std::ostream& foedus::storage::hash::operator<< | ( | std::ostream & | o, |
const HashMetadata & | v | ||
) |
Definition at line 34 of file hash_metadata.cpp.
std::ostream& foedus::storage::hash::operator<< | ( | std::ostream & | o, |
const HashCombo & | v | ||
) |
Definition at line 37 of file hash_combo.cpp.
References foedus::storage::hash::HashCombo::bin_, foedus::storage::hash::HashCombo::fingerprint_, foedus::storage::hash::HashCombo::hash_, and foedus::storage::hash::HashCombo::route_.
std::ostream& foedus::storage::hash::operator<< | ( | std::ostream & | o, |
const HashCreateLogType & | v | ||
) |
Definition at line 47 of file hash_log_types.cpp.
References foedus::storage::hash::HashCreateLogType::metadata_.
std::ostream& foedus::storage::hash::operator<< | ( | std::ostream & | o, |
const HashDataPage & | v | ||
) |
Definition at line 52 of file hash_page_debug.cpp.
References foedus::storage::hash::DataPageBloomFilter::extract_fingerprint(), foedus::storage::hash::HashDataPage::Slot::get_aligned_key_length(), foedus::storage::hash::HashDataPage::get_bin(), foedus::storage::hash::HashDataPage::get_record_count(), foedus::storage::hash::HashDataPage::get_slot_address(), foedus::storage::hash::HashDataPage::Slot::hash_, foedus::storage::hash::HashDataPage::header(), foedus::storage::hash::HashDataPage::Slot::key_length_, foedus::storage::hash::HashDataPage::next_page(), foedus::storage::hash::HashDataPage::Slot::offset_, foedus::storage::hash::HashDataPage::Slot::payload_length_, foedus::storage::hash::HashDataPage::Slot::physical_record_length_, foedus::storage::hash::HashDataPage::record_from_offset(), and foedus::storage::hash::HashDataPage::Slot::tid_.
std::ostream& foedus::storage::hash::operator<< | ( | std::ostream & | o, |
const HashInsertLogType & | v | ||
) |
Definition at line 52 of file hash_log_types.cpp.
References foedus::storage::hash::HashCommonLogType::bin_bits_, foedus::storage::hash::HashCommonLogType::get_key(), foedus::storage::hash::HashCommonLogType::get_payload(), foedus::storage::hash::HashCommonLogType::hash_, foedus::storage::hash::HashCommonLogType::key_length_, and foedus::storage::hash::HashCommonLogType::payload_count_.
std::ostream& foedus::storage::hash::operator<< | ( | std::ostream & | o, |
const BloomFilterFingerprint & | v | ||
) |
Definition at line 55 of file hash_hashinate.cpp.
References foedus::storage::hash::BloomFilterFingerprint::indexes_, and kHashDataPageBloomFilterHashes.
std::ostream& foedus::storage::hash::operator<< | ( | std::ostream & | o, |
const HashDeleteLogType & | v | ||
) |
Definition at line 64 of file hash_log_types.cpp.
References foedus::storage::hash::HashCommonLogType::bin_bits_, foedus::storage::hash::HashCommonLogType::get_key(), foedus::storage::hash::HashCommonLogType::hash_, and foedus::storage::hash::HashCommonLogType::key_length_.
std::ostream& foedus::storage::hash::operator<< | ( | std::ostream & | o, |
const IntermediateRoute & | v | ||
) |
Definition at line 64 of file hash_hashinate.cpp.
References foedus::storage::hash::IntermediateRoute::route.
std::ostream& foedus::storage::hash::operator<< | ( | std::ostream & | o, |
const DataPageBloomFilter & | v | ||
) |
Definition at line 73 of file hash_hashinate.cpp.
References kHashDataPageBloomFilterBytes, and foedus::storage::hash::DataPageBloomFilter::values_.
std::ostream& foedus::storage::hash::operator<< | ( | std::ostream & | o, |
const HashUpdateLogType & | v | ||
) |
Definition at line 74 of file hash_log_types.cpp.
References foedus::storage::hash::HashCommonLogType::bin_bits_, foedus::storage::hash::HashCommonLogType::get_key(), foedus::storage::hash::HashCommonLogType::get_payload(), foedus::storage::hash::HashCommonLogType::hash_, foedus::storage::hash::HashCommonLogType::key_length_, and foedus::storage::hash::HashCommonLogType::payload_count_.
std::ostream& foedus::storage::hash::operator<< | ( | std::ostream & | o, |
const HashOverwriteLogType & | v | ||
) |
Definition at line 86 of file hash_log_types.cpp.
References foedus::storage::hash::HashCommonLogType::bin_bits_, foedus::storage::hash::HashCommonLogType::get_key(), foedus::storage::hash::HashCommonLogType::get_payload(), foedus::storage::hash::HashCommonLogType::hash_, foedus::storage::hash::HashCommonLogType::key_length_, foedus::storage::hash::HashCommonLogType::payload_count_, and foedus::storage::hash::HashCommonLogType::payload_offset_.
std::ostream& foedus::storage::hash::operator<< | ( | std::ostream & | o, |
const HashStorage & | v | ||
) |
Definition at line 247 of file hash_storage.cpp.
References foedus::storage::hash::HashMetadata::bin_bits_, foedus::Attachable< CONTROL_BLOCK >::control_block_, foedus::storage::Storage< CONTROL_BLOCK >::get_id(), foedus::storage::Storage< CONTROL_BLOCK >::get_name(), and foedus::storage::hash::HashStorageControlBlock::meta_.
std::ostream& foedus::storage::hash::operator<< | ( | std::ostream & | o, |
const HashTmpBin & | v | ||
) |
Definition at line 287 of file hash_tmpbin.cpp.
References foedus::storage::hash::HashTmpBin::get_first_record(), foedus::storage::hash::HashTmpBin::Record::get_key(), foedus::storage::hash::HashTmpBin::Record::get_payload(), foedus::storage::hash::HashTmpBin::get_record(), foedus::storage::hash::HashTmpBin::get_records_consumed(), foedus::storage::hash::HashTmpBin::Record::hash_, foedus::storage::hash::HashTmpBin::kBucketCount, foedus::storage::hash::HashTmpBin::Record::key_length_, foedus::storage::hash::HashTmpBin::Record::next_, foedus::storage::hash::HashTmpBin::Record::payload_length_, and foedus::storage::hash::HashTmpBin::Record::xct_id_.
std::ostream& foedus::storage::hash::operator<< | ( | std::ostream & | o, |
const HashPartitioner & | v | ||
) |
Definition at line 364 of file hash_partitioner_impl.cpp.
References foedus::storage::hash::HashPartitionerData::levels_, and foedus::storage::hash::HashPartitionerData::total_bin_count_.
void foedus::storage::hash::prepare_sort_entries | ( | uint8_t | bin_shifts, |
const Partitioner::SortBatchArguments & | args, | ||
SortEntry * | entries | ||
) |
subroutine of sort_batch
Definition at line 236 of file hash_partitioner_impl.cpp.
References ASSERT_ND, foedus::storage::hash::HashCommonLogType::assert_type(), foedus::storage::Partitioner::SortBatchArguments::base_epoch_, foedus::xct::XctId::get_epoch(), foedus::xct::XctId::get_ordinal(), foedus::storage::hash::HashCommonLogType::hash_, foedus::log::BaseLogType::header_, foedus::storage::Partitioner::SortBatchArguments::log_buffer_, foedus::storage::Partitioner::SortBatchArguments::log_positions_, foedus::storage::Partitioner::SortBatchArguments::logs_count_, foedus::snapshot::LogBuffer::resolve(), foedus::storage::hash::SortEntry::set(), foedus::Epoch::subtract(), and foedus::log::LogHeader::xct_id_.
Referenced by foedus::storage::hash::HashPartitioner::sort_batch().
void foedus::storage::hash::release_parallel | ( | Engine * | engine, |
VolatilePagePointer | pointer | ||
) |
Definition at line 260 of file hash_page_impl.cpp.
References ASSERT_ND, foedus::memory::EngineMemory::get_global_volatile_page_resolver(), foedus::Engine::get_memory_manager(), foedus::storage::PageHeader::get_page_type(), foedus::storage::hash::HashIntermediatePage::header(), foedus::storage::kHashIntermediatePageType, foedus::storage::hash::HashIntermediatePage::release_pages_recursive(), and foedus::memory::GlobalVolatilePageResolver::resolve_offset().
Referenced by foedus::storage::hash::HashIntermediatePage::release_pages_recursive_parallel().
|
inline |
Definition at line 59 of file hash_composer_impl.cpp.
References ASSERT_ND, foedus::storage::construct_volatile_page_pointer(), foedus::storage::PageHeader::get_page_type(), foedus::storage::hash::HashDataPage::header(), foedus::storage::VolatilePagePointer::is_equivalent(), foedus::storage::VolatilePagePointer::is_null(), foedus::storage::kHashDataPageType, foedus::storage::PageHeader::page_id_, and foedus::memory::GlobalVolatilePageResolver::resolve_offset().
|
inline |
Definition at line 71 of file hash_composer_impl.cpp.
References ASSERT_ND, foedus::storage::construct_volatile_page_pointer(), foedus::storage::PageHeader::get_page_type(), foedus::storage::hash::HashIntermediatePage::header(), foedus::storage::VolatilePagePointer::is_equivalent(), foedus::storage::VolatilePagePointer::is_null(), foedus::storage::kHashIntermediatePageType, foedus::storage::PageHeader::page_id_, and foedus::memory::GlobalVolatilePageResolver::resolve_offset().
const uint64_t foedus::storage::hash::kFanout64 = kHashIntermediatePageFanout |
just to write the following concisely
Definition at line 65 of file hash_id.hpp.
const uint16_t foedus::storage::hash::kHashComposedBinsPageMaxBins = (kPageSize - 80) / sizeof(ComposedBin) |
Definition at line 90 of file hash_composed_bins_impl.hpp.
const HashValue foedus::storage::hash::kHashDataPageBloomFilterIndexMask = (1U << kHashDataPageBloomFilterIndexSize) - 1U |
Definition at line 88 of file hash_hashinate.hpp.
Referenced by foedus::storage::hash::DataPageBloomFilter::extract_fingerprint().
const HashBin foedus::storage::hash::kInvalidHashBin = 1ULL << kHashMaxBinBits |
This value or larger never appears as a valid HashBin.
Definition at line 162 of file hash_id.hpp.
Referenced by foedus::storage::hash::ComposedBinsMergedStream::init(), foedus::storage::hash::ComposedBinsMergedStream::open_path(), foedus::storage::hash::ComposedBinsMergedStream::process_a_bin(), and foedus::storage::hash::ComposedBinsMergedStream::switch_path().
const DataPageSlotIndex foedus::storage::hash::kSlotNotFound = 0xFFFFU |
Definition at line 197 of file hash_id.hpp.
Referenced by foedus::storage::hash::RecordLocation::clear(), foedus::storage::hash::ReserveRecords::find_or_create_or_expand(), foedus::storage::hash::RecordLocation::is_found(), foedus::storage::hash::HashStoragePimpl::locate_record(), foedus::storage::hash::HashStoragePimpl::locate_record_in_snapshot(), foedus::storage::hash::HashDataPage::search_key_physical(), and foedus::storage::hash::HashStoragePimpl::track_moved_record_search().