Archived
prefix cache: a reserved snapshot is a save target until its commit (#129)
A checkpoint reservation (Scheduler::reserve_ckpt, at planning) is written only after the
step (Engine::checkpoint_save), and nothing between the two checked that the slot was still
the reservation's. A later reservation in the same step that found the store full ran
retention over every session, and the policy, placing its ladder from each session's tip,
could release the very slot just handed out: a second request's reservation lands on a
snapshot a first session already holds (the same prefix, so the same key) below that
session's tip, or a lookup's take_over indexes a fresh reservation under a session whose
ladder does not keep it. The save then faulted in checkpoint_copy ("the store does not hold
that slot ... given back after its id was handed out"), the step loop read the negative as a
device fault, and the engine exited with every in-flight request (#129: every 25-50 min
under multi-session agentic load, the store not full at the fault, 12-15 of 16 in use --
the eviction itself had freed the rest).
A reservation now keeps its slot the way a handed-out snapshot does: retention, the LRU
eviction and expiry skip it from reserve_checkpoint until commit_checkpoint, or until the
next step begins when the save was skipped (its request gone), so a skipped save cannot hold
a slot for good. The engine issues every save before it plans the next step, so the window
covers the copy. A reservation that finds every slot handed out or awaiting a save is
refused as before (ckpt_refused) and the chunk goes without a snapshot.
mem_test: the two cases, the shared-prefix one at the position geometric backoff releases,
and a step boundary (begin_step) in the three cases that reserve several snapshots in a
row without committing, as the engine does one per step.
This commit is contained in:
1 parent
816e24bd46
commit
d37639ef71
3 files changed
+129
-18
No files matched your search
+21
-10
@@ -711,9 +711,9 @@ int64_t PrefixCache::retain(uint64_t session) {
|
||||
int64_t freed = 0;
|
||||
for (const auto& a : all) {
|
||||
if (std::binary_search(keep.begin(), keep.end(), a.first)) { kept.push_back(a.second); continue; }
|
||||
/* Keep one handed out this step regardless of policy: its admission restores from the
|
||||
* slot ahead of the step. */
|
||||
if (handed(a.second)) { kept.push_back(a.second); continue; }
|
||||
/* Keep one handed out this step or reserved and not yet committed regardless of policy:
|
||||
* its admission restores from the slot ahead of the step, or the step's save lands in it. */
|
||||
if (handed(a.second) || reserved(a.second)) { kept.push_back(a.second); continue; }
|
||||
auto e = ck_by_prefix_.find(a.second);
|
||||
if (e == ck_by_prefix_.end()) continue;
|
||||
/* And one a lookup resumed from since the session's tip was written. The policy places
|
||||
@@ -754,6 +754,10 @@ int PrefixCache::reserve_checkpoint(uint64_t session, int64_t pos, const BlockHa
|
||||
if (existing != ck_by_prefix_.end()) {
|
||||
existing->second.used = ++clock_;
|
||||
existing->second.used_ns = rad_mono_ns();
|
||||
/* Another session's snapshot, this step's save target: retention run by a later
|
||||
* reservation in this step places its ladder from THAT session's tip and may not keep
|
||||
* this position. Held until the save is committed. */
|
||||
if (!reserved(prefix)) reserved_.push_back(prefix);
|
||||
*slot_out = existing->second.slot;
|
||||
return RAD_OK;
|
||||
}
|
||||
@@ -768,20 +772,21 @@ int PrefixCache::reserve_checkpoint(uint64_t session, int64_t pos, const BlockHa
|
||||
for (uint64_t s : sessions) retain(s);
|
||||
if (kv_->alloc_checkpoint(&slot) < 0) {
|
||||
/* Evict the least recently used snapshot, where a use is its reservation or a lookup
|
||||
* resuming from it, and never one handed out this step (its admission restores from
|
||||
* the slot ahead of the step). A tip gets no protection beyond its recency: sessions
|
||||
* resuming from it, and never one handed out or reserved this step (its admission
|
||||
* restores from the slot ahead of the step; the save lands in it after). A tip gets
|
||||
* no protection beyond its recency: sessions
|
||||
* are request ids, and a client that rewrites its last message leaves one tip per
|
||||
* turn that no later turn reaches, while the anchor every turn resumes from is used
|
||||
* each turn. */
|
||||
const Ckpt* victim = nullptr;
|
||||
for (const auto& kvp : ck_by_prefix_) {
|
||||
if (handed(kvp.first)) continue;
|
||||
if (handed(kvp.first) || reserved(kvp.first)) continue;
|
||||
if (!victim || kvp.second.used < victim->used) victim = &kvp.second;
|
||||
}
|
||||
if (!victim) {
|
||||
++stats_.ckpt_refused;
|
||||
RAD_DEBUG("prefix cache: no snapshot at %lld for session %llu: every one of the "
|
||||
"%lld slots was handed out this step", (long long)pos,
|
||||
"%lld slots was handed out this step or awaits its save", (long long)pos,
|
||||
(unsigned long long)session, (long long)ck_by_prefix_.size());
|
||||
return RAD_E_FULL;
|
||||
}
|
||||
@@ -805,11 +810,17 @@ int PrefixCache::reserve_checkpoint(uint64_t session, int64_t pos, const BlockHa
|
||||
c.used_ns = rad_mono_ns();
|
||||
ck_by_prefix_.emplace(prefix, c);
|
||||
ck_by_session_[session].push_back(prefix);
|
||||
/* A save target until committed: a lookup's take_over may index it under another session
|
||||
* before the save, where retention run by a later reservation in this step would weigh it by
|
||||
* that session's ladder. */
|
||||
reserved_.push_back(prefix);
|
||||
*slot_out = slot;
|
||||
return RAD_OK;
|
||||
}
|
||||
|
||||
void PrefixCache::commit_checkpoint(const BlockHash& prefix) {
|
||||
/* The save has landed: the slot is a snapshot like any other from here. */
|
||||
reserved_.erase(std::remove(reserved_.begin(), reserved_.end(), prefix), reserved_.end());
|
||||
auto it = ck_by_prefix_.find(prefix);
|
||||
if (it == ck_by_prefix_.end()) return;
|
||||
/* One that lost its slot since the reservation holds nothing to serve. */
|
||||
@@ -915,12 +926,12 @@ int64_t PrefixCache::expire(uint64_t now_ns, uint64_t ttl_ns) {
|
||||
}
|
||||
}
|
||||
|
||||
/* ---- snapshots: skip uncommitted reservations and ones handed out this step. At most
|
||||
* --checkpoint-slots of them, so walk the whole index. */
|
||||
/* ---- snapshots: skip uncommitted reservations, ones handed out this step and ones a save
|
||||
* is pending on. At most --checkpoint-slots of them, so walk the whole index. */
|
||||
std::vector<BlockHash> gone;
|
||||
for (const auto& kvp : ck_by_prefix_) {
|
||||
const Ckpt& c = kvp.second;
|
||||
if (!c.valid || handed(kvp.first)) continue;
|
||||
if (!c.valid || handed(kvp.first) || reserved(kvp.first)) continue;
|
||||
auto e = map_.find(kvp.first);
|
||||
const uint64_t used = std::max(c.used_ns, e == map_.end() ? 0 : e->second.used_ns);
|
||||
if (used < cutoff) gone.push_back(kvp.first);
|
||||
|
||||
Reference in new issue
Block a user