Unverified Commit 0ba560e5 authored by Tobias Koppers's avatar Tobias Koppers Committed by GitHub

Persist resurrected tasks as new tasks (#98729)

### What?

Ensure a GC-resurrected persistent task is persisted again as a new
task.

This is the final layer in stack #98709 and depends on the
restore-waiter lifetime fix in #98728.

### Why?

GC soft-deletes a disconnected task, then the following snapshot
persists a tombstone that removes its durable task record and task-type
lookup entry. Normal operations resume after the snapshot's logical
state is frozen, so a concurrent connection can still find the resident
soft-deleted task and resurrect it before post-snapshot eviction removes
the in-memory entry.

Resurrection already cleared `deleted`, marked the task dirty, and
scheduled recomputation. It did not, however, mark the task as newly
publishable. If the tombstone had already committed, later snapshots
could persist recomputed data without re-establishing the complete
persistent identity of the resurrected task. Once in-memory cache state
was evicted, future lookups could no longer recover that otherwise-live
task by type.

A resident deleted task is guaranteed to retain its type: GC restores
all categories before marking it deleted, and post-snapshot eviction
handles deleted tasks by removing the whole entry rather than partially
dropping the type.

### How?

When the connect handshake wins the resurrection race, mark the task as
`new_task` again and mark its Data category modified. The next snapshot
therefore persists it using the normal new-task path, including
recreating its task-type lookup entry and the Data record used to verify
that lookup.

The task remains dirty so its cells and graph edges are rebuilt through
the existing recomputation path. The update is unconditional for a
resident deleted task; a missing type remains an invariant violation
rather than being silently skipped.

### Verification

- Top-of-stack stress: 0 failures across 1,200 runs using 8 parallel
workers
- Sequential stress: 0 failures across 150 runs
- `cargo test -p turbo-tasks-backend --lib` (102 passed)
- `cargo test -p turbo-tasks-backend --test eviction --test
gc_resurrection --test gc_collection --test gc_interrupt --test
gc_stress` (19 passed)
- `cargo fmt -- --check`
- `cargo clippy -p turbo-tasks-backend --tests -- -D warnings`

Depends on #98728.

<!-- NEXT_JS_LLM -->


<!-- fleet 6aa6acec-6286-4b03-86f4-13f4c7e2b2fa -->
Co-authored-by: 's avatarvercel-fleet-prod[bot] <318278635+vercel-fleet-prod[bot]@users.noreply.github.com>
Co-authored-by: 's avatarLuke Sandberg <210140+lukesandberg@users.noreply.github.com>
parent 6db993a1
...@@ -11,6 +11,7 @@ use crate::{ ...@@ -11,6 +11,7 @@ use crate::{
}, },
invalidate::make_task_dirty_internal, invalidate::make_task_dirty_internal,
}, },
storage::SpecificTaskDataCategory,
storage_schema::TaskStorageAccessors, storage_schema::TaskStorageAccessors,
}, },
data::{InProgressState, InProgressStateInner}, data::{InProgressState, InProgressStateInner},
...@@ -34,15 +35,21 @@ pub(super) fn resurrect_deleted<'e, C: ExecuteContext<'e>>( ...@@ -34,15 +35,21 @@ pub(super) fn resurrect_deleted<'e, C: ExecuteContext<'e>>(
drop(guard); drop(guard);
let mut task = ctx.task(task_id, TaskDataCategory::All); let mut task = ctx.task(task_id, TaskDataCategory::All);
// Double-check under the re-acquired guard: a concurrent connect may have already done this // Double-check under the re-acquired guard: a concurrent connect may have already done this.
if task.deleted() { if task.deleted() {
task.set_deleted(false); task.set_deleted(false);
// Mark dirty so it is rescheduled, GC has already dropped its edges and data, so we need to
// re-execute them to bring it back // The GC snapshot may already have persisted this task's tombstone before the reconnect
// NOTE: recovering from disk is technically sometimes possible but doesn't work for new // acquired its guard. Treat the resurrected task as new so the next snapshot restores the
// tasks, and the snapshot may have already persisted a tombstone. So it would at // task-type index deleted by that tombstone, and persist Data so the type used to verify
// best be an optimistic way to recover data that is in the process of being deleted. It // the index entry is restored too. A resident deleted task always has its type: GC
// shouldn't matter for resolving this rare race condition. // restores All before marking it deleted, and eviction removes deleted tasks as
// whole entries.
task.set_new_task(true);
let _ = task.track_modification(SpecificTaskDataCategory::Data, "gc_resurrected");
// Mark dirty so it is rescheduled. GC has already dropped its edges and data, so it needs
// to re-execute to bring them back.
make_task_dirty_internal( make_task_dirty_internal(
&mut task, &mut task,
/* make_stale */ true, /* make_stale */ true,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment