@@ -64,8 +64,14 @@ BlockCache::Config& BlockCache::Config::validate() {
6464 if (numInMemBuffers == 0 ) {
6565 throw std::invalid_argument (" there must be at least one in-mem buffers" );
6666 }
67- if (numPriorities == 0 ) {
68- throw std::invalid_argument (" allocator must have at least one priority" );
67+ if (allocatorsPerPriority.size () == 0 ) {
68+ throw std::invalid_argument (" Allocators must have at least one priority" );
69+ }
70+ for (const auto & ac : allocatorsPerPriority) {
71+ if (ac == 0 ) {
72+ throw std::invalid_argument (
73+ " Each priority must have at least one allocator" );
74+ }
6975 }
7076
7177 reinsertionConfig.validate ();
@@ -115,7 +121,8 @@ BlockCache::BlockCache(Config&& config)
115121
116122BlockCache::BlockCache (Config&& config, ValidConfigTag)
117123 : config_{serializeConfig (config)},
118- numPriorities_{config.numPriorities },
124+ numPriorities_{
125+ static_cast <uint16_t >(config.allocatorsPerPriority .size ())},
119126 checkExpired_{std::move (config.checkExpired )},
120127 destructorCb_{std::move (config.destructorCb )},
121128 checksumData_{config.checksum },
@@ -141,10 +148,10 @@ BlockCache::BlockCache(Config&& config, ValidConfigTag)
141148 bindThis (&BlockCache::onRegionCleanup, *this ),
142149 std::move (config.evictionPolicy ),
143150 config.numInMemBuffers ,
144- config.numPriorities ,
151+ static_cast < uint16_t >( config.allocatorsPerPriority . size ()) ,
145152 config.inMemBufFlushRetryLimit ,
146153 config.regionManagerFlushAsync },
147- allocator_{regionManager_, config.numPriorities },
154+ allocator_{regionManager_, config.allocatorsPerPriority },
148155 reinsertionPolicy_{makeReinsertionPolicy (config.reinsertionConfig )} {
149156 validate (config);
150157 XLOG (INFO, " Block cache created" );
@@ -181,8 +188,8 @@ Status BlockCache::insert(HashedKey hk, BufferView value) {
181188 }
182189
183190 // All newly inserted items are assigned with the lowest priority
184- auto [desc, slotSize, addr] =
185- allocator_. allocate ( size, kDefaultItemPriority , true /* canWait */ );
191+ auto [desc, slotSize, addr] = allocator_. allocate (
192+ size, kDefaultItemPriority , true /* canWait */ , hk. keyHash () );
186193
187194 switch (desc.status ()) {
188195 case OpenStatus::Error:
@@ -634,7 +641,7 @@ BlockCache::ReinsertionRes BlockCache::reinsertOrRemoveItem(
634641
635642 uint32_t size = serializedSize (hk.key ().size (), value.size ());
636643 auto [desc, slotSize, addr] =
637- allocator_.allocate (size, priority, false /* canWait */ );
644+ allocator_.allocate (size, priority, false /* canWait */ , hk. keyHash () );
638645
639646 switch (desc.status ()) {
640647 case OpenStatus::Ready:
0 commit comments