mirror of
https://github.com/dragonflydb/dragonfly.git
synced 2025-05-10 18:05:44 +02:00
chore: remove goto statements (#3791)
* replace goto statements with lambda calls Signed-off-by: kostas <kostas@dragonflydb.io>
This commit is contained in:
parent
734be21407
commit
a5d34adc4c
2 changed files with 31 additions and 27 deletions
|
@ -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_;
|
bool record_keys = owner_->journal() != nullptr || expired_keys_events_recording_;
|
||||||
vector<string> keys_to_journal;
|
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;
|
FiberAtomicGuard guard;
|
||||||
for (int32_t slot_id = num_slots - 1; slot_id >= 0; --slot_id) {
|
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
|
// returns when whichever condition is met first
|
||||||
if ((evicted_items == max_eviction_per_hb) || (evicted_bytes >= increase_goal_bytes))
|
if ((evicted_items == max_eviction_per_hb) || (evicted_bytes >= increase_goal_bytes))
|
||||||
goto finish;
|
return return_cb();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
finish:
|
return return_cb();
|
||||||
// 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};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DbSlice::CreateDb(DbIndex db_ind) {
|
void DbSlice::CreateDb(DbIndex db_ind) {
|
||||||
|
|
|
@ -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)
|
if (args.size() % 2 == 1)
|
||||||
goto err;
|
return err_cb();
|
||||||
|
|
||||||
for (unsigned i = 0; i < args.size(); i += 2) {
|
for (unsigned i = 0; i < args.size(); i += 2) {
|
||||||
DCHECK_LT(i + 1, args.size());
|
DCHECK_LT(i + 1, args.size());
|
||||||
ToUpper(&args[i]);
|
ToUpper(&args[i]);
|
||||||
|
@ -2925,16 +2931,11 @@ void ServerFamily::ReplConf(CmdArgList args, ConnectionContext* cntx) {
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
VLOG(1) << "Error " << cmd << " " << arg << " " << args.size();
|
VLOG(1) << "Error " << cmd << " " << arg << " " << args.size();
|
||||||
goto err;
|
return err_cb();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cntx->SendOk();
|
return cntx->SendOk();
|
||||||
return;
|
|
||||||
|
|
||||||
err:
|
|
||||||
LOG(ERROR) << "Error in receiving command: " << args;
|
|
||||||
cntx->SendError(kSyntaxErr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerFamily::Role(CmdArgList args, ConnectionContext* cntx) {
|
void ServerFamily::Role(CmdArgList args, ConnectionContext* cntx) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue