@@ -172,11 +172,8 @@ class TieredStorage::ShardOpManager : public tiering::OpManager {
172172 }
173173
174174 void FlagBackpressure (OpManager::KeyRef id, bool result) {
175- const auto & [dbid, key] = id;
176- if (auto it = ts_->backpressure_ .find ({dbid, string{key}}); it != ts_->backpressure_ .end ()) {
177- it->second .Resolve (result);
178- ts_->backpressure_ .erase (it);
179- }
175+ if (auto node = ts_->stash_backpressure_ .extract (id); !node.empty ())
176+ node.mapped ().Resolve (result);
180177 }
181178
182179 struct {
@@ -319,7 +316,7 @@ error_code TieredStorage::Open(string_view base_path) {
319316}
320317
321318void TieredStorage::Close () {
322- for (auto & [_, f] : backpressure_ )
319+ for (auto & [_, f] : stash_backpressure_ )
323320 f.Resolve (false );
324321 op_manager_->Close ();
325322}
@@ -363,7 +360,7 @@ template TieredStorage::TResult<size_t> TieredStorage::Modify(
363360 std::function<size_t (std::string*)> modf);
364361
365362std::optional<util::fb2::Future<bool >> TieredStorage::TryStash (DbIndex dbid, string_view key,
366- PrimeValue* value) {
363+ PrimeValue* value, bool provide_bp ) {
367364 if (!ShouldStash (*value))
368365 return {};
369366
@@ -398,12 +395,9 @@ std::optional<util::fb2::Future<bool>> TieredStorage::TryStash(DbIndex dbid, str
398395 return {};
399396 }
400397
401- // Throttle stashes over the offload boundary
402- if (ShouldOffload ()) {
403- util::fb2::Future<bool > fut;
404- backpressure_[{dbid, string{key}}] = fut;
405- return fut;
406- }
398+ // If we are in the active offloading phase, throttle stashes by providing backpressure future
399+ if (provide_bp && ShouldOffload ())
400+ return stash_backpressure_[{dbid, string{key}}];
407401
408402 return {};
409403}
@@ -429,7 +423,7 @@ void TieredStorage::CancelStash(DbIndex dbid, std::string_view key, PrimeValue*
429423 DCHECK (value->HasStashPending ());
430424
431425 // If any previous write was happening, it has been cancelled
432- if (auto node = backpressure_ .extract ({ dbid, string{ key}} ); !node.empty ())
426+ if (auto node = stash_backpressure_ .extract (make_pair ( dbid, key) ); !node.empty ())
433427 std::move (node.mapped ()).Resolve (false );
434428
435429 if (OccupiesWholePages (value->Size ())) {
0 commit comments