-
Notifications
You must be signed in to change notification settings - Fork 692
enhancement(livestore): skipped wal complete op during shutdown #6839
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mdisibio
merged 8 commits into
grafana:main
from
zhxiaogg:live-store-skip-complete-op-during-shutdown
Apr 10, 2026
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
12adf14
enhancement(livestore): skipped wal complete op during shutdown
zhxiaogg eae3fdd
CHANGELOG.md
zhxiaogg f40ad7f
address pr comments
zhxiaogg d5bc681
relax livestore WAL backpressure from 1 to 4
zhxiaogg 9463acd
minor update to log block size
zhxiaogg 7910736
address pr comment
zhxiaogg 5e15ee3
update changelog
zhxiaogg e3b8f2a
revert vparquet4/5 ctx check in CreateBlock
zhxiaogg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| package livestore | ||
|
|
||
| import ( | ||
| "context" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/google/uuid" | ||
| "github.com/grafana/dskit/services" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| // TestProcessCompleteOpAbandonOnCancelledContext verifies that processCompleteOp | ||
| // skips WAL block completion when the service context is already cancelled | ||
| // (i.e. during shutdown), rather than attempting the work and scheduling a retry. | ||
| // The WAL block must remain on disk so that reloadBlocks() can re-enqueue it on | ||
| // the next startup. | ||
| func TestProcessCompleteOpAbandonOnCancelledContext(t *testing.T) { | ||
| tmpDir := t.TempDir() | ||
|
|
||
| liveStore, err := defaultLiveStore(t, tmpDir) | ||
| require.NoError(t, err) | ||
| t.Cleanup(func() { _ = services.StopAndAwaitTerminated(context.Background(), liveStore) }) | ||
|
|
||
| inst, err := liveStore.getOrCreateInstance(testTenantID) | ||
| require.NoError(t, err) | ||
|
|
||
|
zhxiaogg marked this conversation as resolved.
|
||
| // Push a trace, flush live traces to head block, then cut to WAL. | ||
| pushTracesToInstance(t, inst, 1) | ||
| err = inst.cutIdleTraces(t.Context(), true) | ||
| require.NoError(t, err) | ||
| walID, err := inst.cutBlocks(t.Context(), true) | ||
| require.NoError(t, err) | ||
| require.NotEqual(t, uuid.Nil, walID) | ||
| requireInstanceState(t, inst, instanceState{liveTraces: 0, walBlocks: 1, completeBlocks: 0}) | ||
|
|
||
| // Simulate shutdown by cancelling the service context. | ||
| liveStore.cancel() | ||
|
|
||
| op := &completeOp{ | ||
| tenantID: testTenantID, | ||
| blockID: walID, | ||
| at: time.Now(), | ||
| bo: liveStore.cfg.initialBackoff, | ||
|
zhxiaogg marked this conversation as resolved.
|
||
| maxBackoff: liveStore.cfg.maxBackoff, | ||
| attempts: 1, | ||
| } | ||
|
|
||
| // processCompleteOp must return nil (not exit the worker loop) and must NOT | ||
| // schedule a retry — the WAL block stays on disk for reloadBlocks() on restart. | ||
| err = liveStore.processCompleteOp(op) | ||
| require.NoError(t, err) | ||
|
|
||
| // WAL block is still present: abandoned, not completed or removed. | ||
| requireInstanceState(t, inst, instanceState{liveTraces: 0, walBlocks: 1, completeBlocks: 0}) | ||
|
|
||
| // No retry was enqueued. | ||
| require.True(t, liveStore.completeQueues.IsEmpty()) | ||
|
zhxiaogg marked this conversation as resolved.
|
||
| } | ||
|
zhxiaogg marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.