Skip to content

ingest: batch WAL truncation in the shard-positions gossip handler#6599

Open
aanufriev-celonis wants to merge 1 commit into
quickwit-oss:mainfrom
celonis:wal-cleanup-lock-hold-ingest-stall
Open

ingest: batch WAL truncation in the shard-positions gossip handler#6599
aanufriev-celonis wants to merge 1 commit into
quickwit-oss:mainfrom
celonis:wal-cleanup-lock-hold-ingest-stall

Conversation

@aanufriev-celonis

@aanufriev-celonis aanufriev-celonis commented Jul 13, 2026

Copy link
Copy Markdown

Fixes #6598

Problem

See the original description of #6598.

Fix

Process the update in small batches (GOSSIP_TRUNCATE_BATCH_SIZE = 8), acquiring and releasing the lock per batch instead of once for the whole update. Between batches the lock is free, so queued persist / init_shards calls interleave.

This is turn-processing on the shared WAL lock, not added parallelism: the WAL is a single shared log, and its operations remain serialized. The change only bounds how long the cleanup task holds the lock before yielding it.

Compatibility

The per-shard helpers already re-validate state on each call, so releasing and re-acquiring the lock mid-update cannot corrupt state:

  • truncate_shard re-looks up the shard and only advances the truncation position;
  • delete_shard treats an already-missing WAL queue as success.

Testing

  • Added test_ingester_truncate_on_shard_positions_update_spans_multiple_batches, which drives more shards than a single batch (mixed truncate + EOF-delete) and asserts every shard is processed correctly across the multiple lock acquisitions.

@aanufriev-celonis aanufriev-celonis requested a review from a team as a code owner July 13, 2026 10:39
@aanufriev-celonis aanufriev-celonis force-pushed the wal-cleanup-lock-hold-ingest-stall branch from f6d235b to fc7ed60 Compare July 13, 2026 12:05

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fc7ed6001b

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

}
// Drop the guard (end of scope) and yield so a runnable persist/init_shards task can
// be polled and take the lock before re-acquire for the next batch.
tokio::task::yield_now().await;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Drop the WAL guard before yielding between batches

When a gossip update spans multiple batches, this yield_now().await still runs while state_guard is in scope, so the full ingester/WAL lock is held during the yield. A queued persist or init_shards task that gets polled by this yield can only block on the same lock, and the lock is not actually released until this handler is scheduled again and reaches the end of the loop body; this adds idle lock-hold time and undermines the intended interleaving between batches. Explicitly drop the guard before yielding or put the guarded work in an inner scope.

Useful? React with 👍 / 👎.

@aanufriev-celonis aanufriev-celonis force-pushed the wal-cleanup-lock-hold-ingest-stall branch from fc7ed60 to fcfe740 Compare July 13, 2026 12:37
@aanufriev-celonis

Copy link
Copy Markdown
Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: fcfe740014

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ingest v2: WAL truncation blocks persist/init_shards, causing ingest timeouts under load

1 participant