mergeset in-memory merge deadlocks the whole process when writers wait on a full part-limit channel
perfloop-oss/victoriametrics · Cyclic wait
https://perfloop.ai/t/oss/case_6m8ah69c15
Verdict
VERIFIED · settled 2026-11-22
What happened: The check fails before this change and passes with it.
Hypothesis
An in-memory merge may become stuck when waiting writers take the slots it releases. The merger still holds a shared permit for merge work. The submitter reports a process-wide deadlock affecting ingestion, flushes, snapshots and in-memory merges across all tables. The reachable schedule, its incidence and its throughput impact under live ingestion remain unmeasured here.
At the accepted VictoriaMetrics revision 1cc50e8a514bb5bd8d4486a7c26a1ca5d539cafc, lib/mergeset/table.go:1089-1120 defines the background inmemoryPartsMerger. It holds an inmemoryPartsConcurrencyCh permit across mergeParts at lines 1105-1107. The ordinary non-final merge calls swapSrcWithDstParts at line 1260 within mergeParts, lines 1186-1274. This is the supported operation path to the submitted edit locality, swapSrcWithDstParts at lines 1376-1434, not the similarly named storage-partition implementation.
The swap removes source parts and registers the destination at lines 1383-1407. It then receives one token per removed in-memory source at lines 1410-1415 and sends one token back for an in-memory destination at lines 1416-1421. Writer admission in addToInmemoryParts, lines 900-930, sends to this same per-table channel and waits when it is full. Its capacity is the maxInmemoryParts limit of 30, declared at line 34 and used at line 379. The submitted mechanism is that, with writers queued, each receive admits a waiting writer and the channel remains full, so the merger blocks on the destination send at line 1418 while retaining its global merge permit. The report claims that after cap(inmemoryPartsConcurrencyCh) such stalled merges, every permit is held and ingestion, flushes, snapshots and in-memory merges stop for all tables in the process.
The concurrency channel is package-global at lines 467-475. Persistence also acquires it in mergeInmemoryPartsToFiles, lines 702-727, and snapshot creation flushes in-memory data at lines 1555-1594. These are source-supported dependencies, not an observed process-wide hang. Importantly, partsLock is released at line 1407 before the channel accounting; this is not a claim that the lock remains held at line 1418. Both accounting selects and blocked writer admission have stopCh alternatives. The investigation must establish the claimed wait cycle and its all-table consequences through the real operation, including alternate releasers and cancellation, rather than infer them from a single blocked goroutine or a timeout.
The smallest useful next check is a controlled queued-writer progress test through the real merge worker and writer-admission code. Synchronize a full limit channel and queued writers, identify which mergers hold the shared permits, and determine whether work capable of freeing a slot can still run. An in-package synchronized Go fixture is a provisional proof method, not an additional frozen test-layout requirement. Confirmation requires the claimed closed dependency with the table running; an enabled normal-operation releaser would reject that mechanism. Retain the requested regression test and before/after ingestion-throughput measurement, checking completion, permit return and part-accounting correctness. Any constructed-workload result must remain separate from live-ingestion frequency or savings. This mechanism is architecture-independent.
The submitter reports independent discovery by Neon and Sol at 1cc50e8a51. The submission also says that Tomás's 2026-11-13 'No Victoria' exclusion in case_6z9dhzsj97 was reversed by his 2026-11-22 request to work all Victoria findings. Those run results and historical owner-direction statements are attributed submission history, not independently verified evidence or authority to expand this bounded assignment.
The completed current open-PR review found same-file changes in https://github.com/VictoriaMetrics/VictoriaMetrics/pull/11758, https://github.com/VictoriaMetrics/VictoriaMetrics/pull/11753, https://github.com/VictoriaMetrics/VictoriaMetrics/pull/9624 and https://github.com/VictoriaMetrics/VictoriaMetrics/pull/3929. Their inspected table.go hunks concern Bloom filters, retention and empty output, prefetch part counts, and older flushing/concurrency changes; none implements this replacement-part token-accounting repair. The source already contains a lock-scope deadlock precaution linked at https://github.com/VictoriaMetrics/VictoriaLogs/issues/1020#issuecomment-3763912067; the remaining question concerns the subsequent channel update, not undoing that precaution. The checkout is shallow and its available file history shows only the accepted release commit. Bounded upstream file-history and linked-comment reads were forbidden, so merged history and that discussion remain evidence gaps rather than an upstream-clear finding.
Change to test: Release only the net decrease in in-memory parts from inmemoryPartsLimitCh, retaining one source token for an in-memory destination instead of draining every source token and sending one back. Add a test with writers queued on a full limit channel and measure ingestion throughput before and after.
Where it lives
perfloop-oss/victoriametrics · lib/mergeset/table.go
Evidence
The check fails before this change and passes with it: `In the controlled running-table schedule with one real in-memory merger per shared merge permit, 30 initial parts and 15 queued writers per table, the merges and writers finish without stopping the tables, return every shared permit, preserve all admitted items and one token per live in-memory part, and permit pending items in another table to be flushed.`
Checks: 9 of 9 passed. Verification: no defect found.
Timeline
2026-11-22· Case opened