From a5d34adc4ccc74e7b333afc4b7b51e7eef274ca5 Mon Sep 17 00:00:00 2001 From: Kostas Kyrimis Date: Wed, 25 Sep 2024 16:08:31 +0300 Subject: [PATCH] chore: remove goto statements (#3791) * replace goto statements with lambda calls Signed-off-by: kostas --- src/server/db_slice.cc | 41 ++++++++++++++++++++----------------- src/server/server_family.cc | 17 +++++++-------- 2 files changed, 31 insertions(+), 27 deletions(-) diff --git a/src/server/db_slice.cc b/src/server/db_slice.cc index 5d7db9d38..0cc30214e 100644 --- a/src/server/db_slice.cc +++ b/src/server/db_slice.cc @@ -1301,6 +1301,26 @@ pair DbSlice::FreeMemWithEvictionStep(DbIndex db_ind, size_t s bool record_keys = owner_->journal() != nullptr || expired_keys_events_recording_; vector keys_to_journal; + auto return_cb = [&, this]() mutable { + // send the deletion to the replicas. + // fiber preemption could happen in this phase. + for (string_view key : keys_to_journal) { + if (auto journal = owner_->journal(); journal) + RecordExpiry(db_ind, key); + + if (expired_keys_events_recording_) + db_table->expired_keys_events_.emplace_back(key); + } + + auto time_finish = absl::GetCurrentTimeNanos(); + events_.evicted_keys += evicted_items; + DVLOG(2) << "Evicted: " << evicted_bytes; + DVLOG(2) << "Number of keys evicted / max eviction per hb: " << evicted_items << "/" + << max_eviction_per_hb; + DVLOG(2) << "Eviction time (us): " << (time_finish - time_start) / 1000; + return pair{evicted_items, evicted_bytes}; + }; + { FiberAtomicGuard guard; for (int32_t slot_id = num_slots - 1; slot_id >= 0; --slot_id) { @@ -1336,30 +1356,13 @@ pair DbSlice::FreeMemWithEvictionStep(DbIndex db_ind, size_t s // returns when whichever condition is met first if ((evicted_items == max_eviction_per_hb) || (evicted_bytes >= increase_goal_bytes)) - goto finish; + return return_cb(); } } } } -finish: - // send the deletion to the replicas. - // fiber preemption could happen in this phase. - for (string_view key : keys_to_journal) { - if (auto journal = owner_->journal(); journal) - RecordExpiry(db_ind, key); - - if (expired_keys_events_recording_) - db_table->expired_keys_events_.emplace_back(key); - } - - auto time_finish = absl::GetCurrentTimeNanos(); - events_.evicted_keys += evicted_items; - DVLOG(2) << "Evicted: " << evicted_bytes; - DVLOG(2) << "Number of keys evicted / max eviction per hb: " << evicted_items << "/" - << max_eviction_per_hb; - DVLOG(2) << "Eviction time (us): " << (time_finish - time_start) / 1000; - return {evicted_items, evicted_bytes}; + return return_cb(); } void DbSlice::CreateDb(DbIndex db_ind) { diff --git a/src/server/server_family.cc b/src/server/server_family.cc index e01cd2a9d..ea5d407d6 100644 --- a/src/server/server_family.cc +++ b/src/server/server_family.cc @@ -2846,8 +2846,14 @@ void ServerFamily::ReplConf(CmdArgList args, ConnectionContext* cntx) { } } + auto err_cb = [&]() mutable { + LOG(ERROR) << "Error in receiving command: " << args; + cntx->SendError(kSyntaxErr); + }; + if (args.size() % 2 == 1) - goto err; + return err_cb(); + for (unsigned i = 0; i < args.size(); i += 2) { DCHECK_LT(i + 1, args.size()); ToUpper(&args[i]); @@ -2925,16 +2931,11 @@ void ServerFamily::ReplConf(CmdArgList args, ConnectionContext* cntx) { return; } else { VLOG(1) << "Error " << cmd << " " << arg << " " << args.size(); - goto err; + return err_cb(); } } - cntx->SendOk(); - return; - -err: - LOG(ERROR) << "Error in receiving command: " << args; - cntx->SendError(kSyntaxErr); + return cntx->SendOk(); } void ServerFamily::Role(CmdArgList args, ConnectionContext* cntx) {