1
0
Fork 0
mirror of https://github.com/dragonflydb/dragonfly.git synced 2024-12-14 11:58:02 +00:00

chore: remove goto statements (#3791)

* replace goto statements with lambda calls

Signed-off-by: kostas <kostas@dragonflydb.io>
This commit is contained in:
Kostas Kyrimis 2024-09-25 16:08:31 +03:00 committed by GitHub
parent 734be21407
commit a5d34adc4c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 31 additions and 27 deletions

View file

@ -1301,6 +1301,26 @@ pair<uint64_t, size_t> DbSlice::FreeMemWithEvictionStep(DbIndex db_ind, size_t s
bool record_keys = owner_->journal() != nullptr || expired_keys_events_recording_;
vector<string> 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<uint64_t, size_t>{evicted_items, evicted_bytes};
};
{
FiberAtomicGuard guard;
for (int32_t slot_id = num_slots - 1; slot_id >= 0; --slot_id) {
@ -1336,30 +1356,13 @@ pair<uint64_t, size_t> 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) {

View file

@ -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) {