Repository navigation
fix(tsi1): series delete deadlocks against in-flight index compaction - #27696
Open
goingforstudying-ctrl wants to merge 1 commit into
Open
goingforstudying-ctrl wants to merge 1 commit into
goingforstudying-ctrl wants to merge 1 commit into
Conversation
A delete retains the index file set through its series iterator and then blocks in Partition.Wait() for compactions to drain, while the finishing compaction blocks in LogFile.Close()/IndexFile.Close() waiting for the iterator's reference. Neither can proceed, wedging the shard. After the manifest swap commits a compaction, swapped-out files are no longer reachable from the file set, so closing and removing them off the compaction goroutine is safe and breaks the circular wait. Partition.Close() drains the deferred closes. Also fix DisableCompactions never firing the compaction interrupt: the check ran after the increment and compared against 0, so in-flight compactions were never asked to abort when a delete arrived.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Required checklist
/etcfolder andNewDemoConfigmethods) (influxdb and plutonium)Description
A
DELETEthat lands while a tsi1 index compaction is in flight can wedge the shard for good. The delete path builds its series iterator first, which retains the current file set (including the log file mid-compaction), then callsPartition.Wait()for in-progress compactions to drain. The compaction, meanwhile, finishes writing the new index file and blocks inLogFile.Close()waiting for exactly that reference to drop. Delete waits on compaction, compaction waits on delete. With log compactions firing every so often this is basically guaranteed to happen eventually on a busy instance.Context
Two changes, both in
tsdb/index/tsi1/partition.go:Once the manifest swap commits a compaction, the swapped-out files are closed and removed off the compaction goroutine (tracked by a new
closeWgthatPartition.Close()drains). At that point the old files are no longer reachable from the file set, so no new references can appear, and waiting for the existing readers to finish is pure cleanup. This breaks the circular wait for bothcompactLogFileandcompactToLevel, regardless of who holds references or why.DisableCompactions()had a dead branch: it incrementscompactionsDisabledand then checks== 0, so thecompactionInterruptchannel was never closed and in-flight compactions were never actually asked to abort. Fixed to fire on the first disabler (== 1), matching how the tsm engine aborts compactions for deletes. This keepsWait()from sitting behind a whole multi-minuteCompactTowhen a delete shows up mid-compaction.Risks: compaction completion no longer implies the old files are already unlinked, only that they're out of the manifest. Startup already cleans up non-manifest files via
deleteNonManifestFiles, so an interrupted process just leaves a stray file for the next open rather than corrupting anything.Partition.Close()waits for pending closes, so test and shutdown behavior is unchanged.Affected areas (delete section if not relevant):
Internal only: tsi1 index compaction lifecycle. No user-visible API, CLI, or config changes.
Severity (delete section if not relevant)
Recommend upgrade for anyone running periodic
DELETE/DROPworkloads on 2.x — the deadlock freezes the affected shard (and can stall the whole engine) until restart.Note for reviewers:
Reproduced the deadlock shape with a regression test (
TestPartition_CompactLogFile_HeldReferenceDoesNotBlockWait): hold a file-set reference like a delete's iterator does, compact, and assertWait()returns anyway, then assert the old log file is removed once the reference drops. On current code that test hangs until the watchdog fires. Also addedTestPartition_DisableCompactions_InterruptsInflightfor the interrupt channel semantics.go test -race ./tsdb/index/tsi1/passes.