1 #ifndef __PAGE_EVICTIONER_SELECTOR_RANDOM_HPP 2 #define __PAGE_EVICTIONER_SELECTOR_RANDOM_HPP 36 template<
typename seed_type>
39 static_assert(std::is_same<seed_type, uint32_t>::value
40 || std::is_same<seed_type, uint64_t>::value
41 || std::is_same<seed_type, __uint128_t>::value,
"'seed_type' is of unsupported type!");
42 #else // __SIZEOF_INT128__ 43 static_assert(std::is_same<seed_type, uint32_t>::value
44 || std::is_same<seed_type, uint64_t>::value,
"'seed_type' is of unsupported type!");
45 #endif // __SIZEOF_INT128__ 70 static inline uint32_t
getSeed() noexcept {
71 return static_cast<uint32_t
>(chrono::high_resolution_clock::now().time_since_epoch().count());
89 static inline uint64_t
getSeed() noexcept {
90 return static_cast<uint64_t
>(chrono::high_resolution_clock::now().time_since_epoch().count());
112 static inline __uint128_t getSeed() noexcept {
113 return (static_cast<__uint128_t>(chrono::high_resolution_clock::now().time_since_epoch().count()) << 64)
114 + chrono::high_resolution_clock::now().time_since_epoch().count();
118 #endif // __SIZEOF_INT128__ 130 template<
typename seed_type>
132 #if __SIZEOF_INT128__ 133 static_assert(std::is_same<seed_type, uint32_t>::value
134 || std::is_same<seed_type, uint64_t>::value
135 || std::is_same<seed_type, __uint128_t>::value,
"'seed_type' is of unsupported type!");
136 #else // __SIZEOF_INT128__ 137 static_assert(std::is_same<seed_type, uint32_t>::value
138 || std::is_same<seed_type, uint64_t>::value,
"'seed_type' is of unsupported type!");
139 #endif // __SIZEOF_INT128__ 165 std::random_device randomDevice;
167 return randomDevice();
187 std::random_device randomDevice;
189 return ((static_cast<uint64_t>(randomDevice()) << 32) | static_cast<uint64_t>(randomDevice()));
193 #if __SIZEOF_INT128__ 212 static inline __uint128_t getSeed() noexcept {
213 std::random_device randomDevice;
215 return (static_cast<__uint128_t>((static_cast<uint64_t>(randomDevice()) << 32)
216 | static_cast<uint64_t>(randomDevice())) << 64)
217 + ((
static_cast<uint64_t
>(randomDevice()) << 32) |
static_cast<uint64_t
>(randomDevice()));
221 #endif // __SIZEOF_INT128__ 263 template<
class random_number_generator,
class random_distribution,
class ... seed_generators>
273 _randomNumberGenerator(seed_generators::getSeed() ...),
274 _randomDistribution(1, _maxBufferpoolIndex) {};
284 return static_cast<bf_idx>(_randomDistribution(_randomNumberGenerator));
436 template<
class random_number_generator,
class random_distribution,
bool seed_explicitly,
class ... seed_generators>
446 _randomDistribution(1, _maxBufferpoolIndex) {};
455 inline bf_idx select() noexcept
final {
460 static thread_local
bool _randomNumberGeneratorInitialized;
465 static thread_local random_number_generator _randomNumberGenerator;
467 if constexpr (seed_explicitly) {
468 if (!_randomNumberGeneratorInitialized) {
469 _randomNumberGenerator = random_number_generator(seed_generators::getSeed() ...);
470 _randomNumberGeneratorInitialized =
true;
474 return static_cast<bf_idx>(_randomDistribution(_randomNumberGenerator));
596 template<
class random_number_generator,
class ... seed_generators>
606 _randomNumberGenerator(seed_generators::getSeed() ...) {};
616 return static_cast<uint32_t
>(((uint32_t(_randomNumberGenerator)) % (_maxBufferpoolIndex - 1) + 1));
739 template<
class random_number_generator,
bool seed_explicitly,
class ... seed_generators>
757 inline bf_idx select() noexcept
final {
762 static thread_local
bool _randomNumberGeneratorInitialized;
767 static thread_local random_number_generator _randomNumberGenerator;
769 if constexpr (seed_explicitly) {
770 if (!_randomNumberGeneratorInitialized) {
771 _randomNumberGenerator = random_number_generator(seed_generators::getSeed() ...);
772 _randomNumberGeneratorInitialized =
true;
776 return static_cast<uint32_t
>(((uint32_t(_randomNumberGenerator)) % (_maxBufferpoolIndex - 1) + 1));
890 std::srand(std::time(
nullptr));
901 return 1 + std::rand() / ((RAND_MAX + 1u) / _maxBufferpoolIndex);
1022 inline bf_idx select() noexcept
final {
1030 static thread_local
bool _seedInitialized;
1035 static thread_local uint32_t _x;
1040 static thread_local uint32_t _y;
1045 static thread_local uint32_t _z;
1050 static thread_local uint32_t _w;
1055 static thread_local uint32_t _v;
1060 static thread_local uint32_t _d;
1062 if (!_seedInitialized) {
1063 _x = std::random_device{}();
1064 _y = std::random_device{}();
1065 _z = std::random_device{}();
1066 _w = std::random_device{}();
1067 _v = std::random_device{}();
1068 _d = std::random_device{}();
1069 _seedInitialized =
true;
1071 uint32_t t = _x ^(_x >> 2);
1076 _v = (_v ^ (_v << 4)) ^ (t ^ (t << 1));
1078 return (((_d += 362437) + _v) % (_maxBufferpoolIndex - 1) + 1);
1199 inline bf_idx select() noexcept
final {
1207 static thread_local
bool _seedInitialized;
1212 static thread_local uint64_t _seed0;
1217 static thread_local uint64_t _seed1;
1219 if (!_seedInitialized) {
1220 _seed0 = std::random_device{}();
1221 _seed1 = std::random_device{}();
1222 _seedInitialized =
true;
1224 uint64_t x = _seed0;
1225 uint64_t
const y = _seed1;
1228 _seed1 = x ^ y ^ (x >> 17) ^ (y >> 26);
1229 return ((_seed1 + y) % (_maxBufferpoolIndex - 1) + 1);
1329 #endif // __PAGE_EVICTIONER_SELECTOR_RANDOM_HPP void updateOnPageFixed(bf_idx idx) noexcept final
Updates the eviction statistics of fixed (i.e. used) pages during eviction.
Definition: page_evictioner_selector_random.hpp:941
void updateOnPageExplicitlyUnbuffered(bf_idx idx) noexcept final
Updates the eviction statistics on explicit unbuffer.
Definition: page_evictioner_selector_random.hpp:1158
void updateOnPageDirty(bf_idx idx) noexcept final
Updates the eviction statistics of dirty pages during eviction.
Definition: page_evictioner_selector_random.hpp:1279
Global RANDOM buffer frame selector that wraps an CLHEP PRNG.
Definition: page_evictioner_selector_random.hpp:597
RANDOM buffer frame selector
Definition: page_evictioner_selector_random.hpp:1006
void updateOnPointerSwizzling(bf_idx idx) noexcept final
Updates the eviction statistics of pages when its pointer got swizzled in its parent page...
Definition: page_evictioner_selector_random.hpp:380
void updateOnPageDirty(bf_idx idx) noexcept final
Updates the eviction statistics of dirty pages during eviction.
Definition: page_evictioner_selector_random.hpp:1128
random_number_generator _randomNumberGenerator
Definition: page_evictioner_selector_random.hpp:386
void updateOnPageUnfix(bf_idx idx) noexcept final
Updates the eviction statistics on page unfix.
Definition: page_evictioner_selector_random.hpp:1248
PageEvictionerSelectorRANDOMXORWow(const BufferPool *bufferPool)
Constructs a RANDOM buffer frame selector.
Definition: page_evictioner_selector_random.hpp:1013
void updateOnPageFixed(bf_idx idx) noexcept final
Updates the eviction statistics of fixed (i.e. used) pages during eviction.
Definition: page_evictioner_selector_random.hpp:656
void updateOnPageFixed(bf_idx idx) noexcept final
Updates the eviction statistics of fixed (i.e. used) pages during eviction.
Definition: page_evictioner_selector_random.hpp:324
Definition: buffer_pool.hpp:34
RANDOM buffer frame selector
Definition: page_evictioner_selector_random.hpp:1183
void updateOnPageHit(bf_idx idx) noexcept final
Updates the eviction statistics on page hit.
Definition: page_evictioner_selector_random.hpp:911
void updateOnPageExplicitlyUnbuffered(bf_idx idx) noexcept final
Updates the eviction statistics on explicit unbuffer.
Definition: page_evictioner_selector_random.hpp:856
RANDOM buffer frame selector that wraps an CLHEP PRNG
Definition: page_evictioner_selector_random.hpp:740
void updateOnPageHit(bf_idx idx) noexcept final
Updates the eviction statistics on page hit.
Definition: page_evictioner_selector_random.hpp:786
void updateOnPointerSwizzling(bf_idx idx) noexcept final
Updates the eviction statistics of pages when its pointer got swizzled in its parent page...
Definition: page_evictioner_selector_random.hpp:1168
void releaseInternalLatches() noexcept final
Releases the internal latches of this buffer frame selector.
Definition: page_evictioner_selector_random.hpp:712
void updateOnPageHit(bf_idx idx) noexcept final
Updates the eviction statistics on page hit.
Definition: page_evictioner_selector_random.hpp:294
void updateOnPointerSwizzling(bf_idx idx) noexcept final
Updates the eviction statistics of pages when its pointer got swizzled in its parent page...
Definition: page_evictioner_selector_random.hpp:991
void updateOnPageExplicitlyUnbuffered(bf_idx idx) noexcept final
Updates the eviction statistics on explicit unbuffer.
Definition: page_evictioner_selector_random.hpp:981
void updateOnPageSwizzled(bf_idx idx) noexcept final
Updates the eviction statistics of pages containing swizzled pointers during eviction.
Definition: page_evictioner_selector_random.hpp:971
void updateOnPageMiss(bf_idx idx, PageID pid) noexcept final
Updates the eviction statistics on page miss.
Definition: page_evictioner_selector_random.hpp:931
static uint64_t getSeed() noexcept
Returns two random numbers from the std::random_device concatenated together as seed.
Definition: page_evictioner_selector_random.hpp:186
void updateOnPageHit(bf_idx idx) noexcept final
Updates the eviction statistics on page hit.
Definition: page_evictioner_selector_random.hpp:1088
void updateOnPageUnfix(bf_idx idx) noexcept final
Updates the eviction statistics on page unfix.
Definition: page_evictioner_selector_random.hpp:795
bf_idx select() noexcept final
Selects a page to be evicted from the buffer pool.
Definition: page_evictioner_selector_random.hpp:900
void updateOnPageMiss(bf_idx idx, PageID pid) noexcept final
Updates the eviction statistics on page miss.
Definition: page_evictioner_selector_random.hpp:1108
RANDOM buffer frame selector that wraps an external PRNG
Definition: page_evictioner_selector_random.hpp:437
PageEvictionerSelectorRANDOMCRand(const BufferPool *bufferPool)
Constructs a RANDOM buffer frame selector.
Definition: page_evictioner_selector_random.hpp:888
void updateOnPageSwizzled(bf_idx idx) noexcept final
Updates the eviction statistics of pages containing swizzled pointers during eviction.
Definition: page_evictioner_selector_random.hpp:686
void updateOnPageHit(bf_idx idx) noexcept final
Updates the eviction statistics on page hit.
Definition: page_evictioner_selector_random.hpp:1239
void updateOnPageExplicitlyUnbuffered(bf_idx idx) noexcept final
Updates the eviction statistics on explicit unbuffer.
Definition: page_evictioner_selector_random.hpp:1309
void updateOnPageExplicitlyUnbuffered(bf_idx idx) noexcept final
Updates the eviction statistics on explicit unbuffer.
Definition: page_evictioner_selector_random.hpp:696
void updateOnPageDirty(bf_idx idx) noexcept final
Updates the eviction statistics of dirty pages during eviction.
Definition: page_evictioner_selector_random.hpp:826
PageEvictionerSelectorRANDOMCLHEP(const BufferPool *bufferPool)
Constructs a RANDOM buffer frame selector based on the set PRNG from CLHEP.
Definition: page_evictioner_selector_random.hpp:604
Seed generator using a non-deterministic source for PRNGs.
Definition: page_evictioner_selector_random.hpp:131
uint32_t bf_idx
Definition: basics.h:56
static uint32_t getSeed() noexcept
Returns the lower 32 bits of the current wall-clock time as seed.
Definition: page_evictioner_selector_random.hpp:70
void updateOnPageSwizzled(bf_idx idx) noexcept final
Updates the eviction statistics of pages containing swizzled pointers during eviction.
Definition: page_evictioner_selector_random.hpp:354
void updateOnPointerSwizzling(bf_idx idx) noexcept final
Updates the eviction statistics of pages when its pointer got swizzled in its parent page...
Definition: page_evictioner_selector_random.hpp:866
void updateOnPageMiss(bf_idx idx, PageID pid) noexcept final
Updates the eviction statistics on page miss.
Definition: page_evictioner_selector_random.hpp:504
PageEvictionerSelectorRANDOMExternalThreadLocal(const BufferPool *bufferPool)
Constructs a RANDOM buffer frame selector based on the set PRNG.
Definition: page_evictioner_selector_random.hpp:444
void updateOnPageDirty(bf_idx idx) noexcept final
Updates the eviction statistics of dirty pages during eviction.
Definition: page_evictioner_selector_random.hpp:524
bf_idx select() noexcept final
Selects a page to be evicted from the buffer pool.
Definition: page_evictioner_selector_random.hpp:283
void updateOnPageHit(bf_idx idx) noexcept final
Updates the eviction statistics on page hit.
Definition: page_evictioner_selector_random.hpp:484
RANDOM buffer frame selector
Definition: page_evictioner_selector_random.hpp:881
void updateOnPageUnfix(bf_idx idx) noexcept final
Updates the eviction statistics on page unfix.
Definition: page_evictioner_selector_random.hpp:1097
void updateOnPageFixed(bf_idx idx) noexcept final
Updates the eviction statistics of fixed (i.e. used) pages during eviction.
Definition: page_evictioner_selector_random.hpp:514
void updateOnPageBlocked(bf_idx idx) noexcept final
Updates the eviction statistics of pages that cannot be evicted at all.
Definition: page_evictioner_selector_random.hpp:1138
uint32_t PageID
Definition: basics.h:45
void updateOnPointerSwizzling(bf_idx idx) noexcept final
Updates the eviction statistics of pages when its pointer got swizzled in its parent page...
Definition: page_evictioner_selector_random.hpp:706
random_number_generator _randomNumberGenerator
Definition: page_evictioner_selector_random.hpp:718
void updateOnPageBlocked(bf_idx idx) noexcept final
Updates the eviction statistics of pages that cannot be evicted at all.
Definition: page_evictioner_selector_random.hpp:836
static uint32_t getSeed() noexcept
Returns the a random number from the std::random_device as seed.
Definition: page_evictioner_selector_random.hpp:164
void updateOnPageSwizzled(bf_idx idx) noexcept final
Updates the eviction statistics of pages containing swizzled pointers during eviction.
Definition: page_evictioner_selector_random.hpp:1148
void releaseInternalLatches() noexcept final
Releases the internal latches of this buffer frame selector.
Definition: page_evictioner_selector_random.hpp:1174
Seed generator for PRNGs.
Definition: page_evictioner_selector_random.hpp:18
void updateOnPageMiss(bf_idx idx, PageID pid) noexcept final
Updates the eviction statistics on page miss.
Definition: page_evictioner_selector_random.hpp:1259
void updateOnPageBlocked(bf_idx idx) noexcept final
Updates the eviction statistics of pages that cannot be evicted at all.
Definition: page_evictioner_selector_random.hpp:1289
Seed generator using the wall-clock time for PRNGs.
Definition: page_evictioner_selector_random.hpp:37
void updateOnPageBlocked(bf_idx idx) noexcept final
Updates the eviction statistics of pages that cannot be evicted at all.
Definition: page_evictioner_selector_random.hpp:534
void updateOnPageDirty(bf_idx idx) noexcept final
Updates the eviction statistics of dirty pages during eviction.
Definition: page_evictioner_selector_random.hpp:334
void updateOnPageBlocked(bf_idx idx) noexcept final
Updates the eviction statistics of pages that cannot be evicted at all.
Definition: page_evictioner_selector_random.hpp:344
void updateOnPageMiss(bf_idx idx, PageID pid) noexcept final
Updates the eviction statistics on page miss.
Definition: page_evictioner_selector_random.hpp:806
void updateOnPageUnfix(bf_idx idx) noexcept final
Updates the eviction statistics on page unfix.
Definition: page_evictioner_selector_random.hpp:635
random_distribution _randomDistribution
The uniform distribution and range for the pseudo-random number generator (post-processor) ...
Definition: page_evictioner_selector_random.hpp:391
void updateOnPageUnfix(bf_idx idx) noexcept final
Updates the eviction statistics on page unfix.
Definition: page_evictioner_selector_random.hpp:920
void updateOnPageFixed(bf_idx idx) noexcept final
Updates the eviction statistics of fixed (i.e. used) pages during eviction.
Definition: page_evictioner_selector_random.hpp:816
PageEvictionerSelectorRANDOMXORShift128Plus(const BufferPool *bufferPool)
Constructs a RANDOM buffer frame selector.
Definition: page_evictioner_selector_random.hpp:1190
void releaseInternalLatches() noexcept final
Releases the internal latches of this buffer frame selector.
Definition: page_evictioner_selector_random.hpp:872
void updateOnPointerSwizzling(bf_idx idx) noexcept final
Updates the eviction statistics of pages when its pointer got swizzled in its parent page...
Definition: page_evictioner_selector_random.hpp:564
void updateOnPageMiss(bf_idx idx, PageID pid) noexcept final
Updates the eviction statistics on page miss.
Definition: page_evictioner_selector_random.hpp:646
void updateOnPageUnfix(bf_idx idx) noexcept final
Updates the eviction statistics on page unfix.
Definition: page_evictioner_selector_random.hpp:303
void updateOnPageExplicitlyUnbuffered(bf_idx idx) noexcept final
Updates the eviction statistics on explicit unbuffer.
Definition: page_evictioner_selector_random.hpp:554
PageEvictionerSelectorRANDOMExternal(const BufferPool *bufferPool)
Constructs a RANDOM buffer frame selector based on the set PRNG.
Definition: page_evictioner_selector_random.hpp:271
void releaseInternalLatches() noexcept final
Releases the internal latches of this buffer frame selector.
Definition: page_evictioner_selector_random.hpp:370
A buffer manager that exploits the tree structure of indexes.
Definition: buffer_pool.hpp:40
void releaseInternalLatches() noexcept final
Releases the internal latches of this buffer frame selector.
Definition: page_evictioner_selector_random.hpp:570
void updateOnPageDirty(bf_idx idx) noexcept final
Updates the eviction statistics of dirty pages during eviction.
Definition: page_evictioner_selector_random.hpp:666
void updateOnPageDirty(bf_idx idx) noexcept final
Updates the eviction statistics of dirty pages during eviction.
Definition: page_evictioner_selector_random.hpp:951
void updateOnPageFixed(bf_idx idx) noexcept final
Updates the eviction statistics of fixed (i.e. used) pages during eviction.
Definition: page_evictioner_selector_random.hpp:1118
void updateOnPointerSwizzling(bf_idx idx) noexcept final
Updates the eviction statistics of pages when its pointer got swizzled in its parent page...
Definition: page_evictioner_selector_random.hpp:1319
void releaseInternalLatches() noexcept final
Releases the internal latches of this buffer frame selector.
Definition: page_evictioner_selector_random.hpp:997
bf_idx select() noexcept final
Selects a page to be evicted from the buffer pool.
Definition: page_evictioner_selector_random.hpp:615
void releaseInternalLatches() noexcept final
Releases the internal latches of this buffer frame selector.
Definition: page_evictioner_selector_random.hpp:1325
void updateOnPageExplicitlyUnbuffered(bf_idx idx) noexcept final
Updates the eviction statistics on explicit unbuffer.
Definition: page_evictioner_selector_random.hpp:364
std::uniform_int_distribution< bf_idx > _randomDistribution
The uniform distribution and range for the pseudo-random number generator (post-processor) ...
Definition: page_evictioner_selector_random.hpp:576
void updateOnPageBlocked(bf_idx idx) noexcept final
Updates the eviction statistics of pages that cannot be evicted at all.
Definition: page_evictioner_selector_random.hpp:961
Global RANDOM buffer frame selector that wraps an external PRNG.
Definition: page_evictioner_selector_random.hpp:264
void updateOnPageFixed(bf_idx idx) noexcept final
Updates the eviction statistics of fixed (i.e. used) pages during eviction.
Definition: page_evictioner_selector_random.hpp:1269
SeedGenerator()
Defined to prevent instantiation of seed generators.
Definition: page_evictioner_selector_random.hpp:23
void updateOnPageSwizzled(bf_idx idx) noexcept final
Updates the eviction statistics of pages containing swizzled pointers during eviction.
Definition: page_evictioner_selector_random.hpp:1299
void updateOnPageBlocked(bf_idx idx) noexcept final
Updates the eviction statistics of pages that cannot be evicted at all.
Definition: page_evictioner_selector_random.hpp:676
void updateOnPageSwizzled(bf_idx idx) noexcept final
Updates the eviction statistics of pages containing swizzled pointers during eviction.
Definition: page_evictioner_selector_random.hpp:544
void updateOnPageUnfix(bf_idx idx) noexcept final
Updates the eviction statistics on page unfix.
Definition: page_evictioner_selector_random.hpp:493
static seed_type getSeed() noexcept
Defined to prevent call of this in generic class.
Definition: page_evictioner_selector_random.hpp:147
void updateOnPageSwizzled(bf_idx idx) noexcept final
Updates the eviction statistics of pages containing swizzled pointers during eviction.
Definition: page_evictioner_selector_random.hpp:846
static uint64_t getSeed() noexcept
Returns the current wall-clock time as seed.
Definition: page_evictioner_selector_random.hpp:89
void updateOnPageHit(bf_idx idx) noexcept final
Updates the eviction statistics on page hit.
Definition: page_evictioner_selector_random.hpp:626
Buffer frame selector for the Select-and-Filter page evictioner.
Definition: page_evictioner_selector.hpp:25
void updateOnPageMiss(bf_idx idx, PageID pid) noexcept final
Updates the eviction statistics on page miss.
Definition: page_evictioner_selector_random.hpp:314
PageEvictionerSelectorRANDOMCLHEPThreadLocal(const BufferPool *bufferPool)
Constructs a RANDOM buffer frame selector based on the set PRNG from CLHEP.
Definition: page_evictioner_selector_random.hpp:747
static seed_type getSeed() noexcept
Defined to prevent call of this in generic class.
Definition: page_evictioner_selector_random.hpp:53