Fix Lite UI freeze during archival (#979)#982
Merged
Conversation
…979) ArchiveService.ArchiveOldDataAsync held DuckDB's exclusive write lock across the entire export-to-Parquet + DELETE loop. Export-to-Parquet (COPY ... TO) only reads the database, but running it under the write lock blocked every UI query for the whole export - tab switches showed the spinning wheel, and it got worse with more monitored servers. Per table, export now runs under a shared read lock (concurrent with the UI); only the DELETE takes the exclusive write lock, briefly. Safe to split: the DELETE only removes rows older than the cutoff and collectors only insert "now"-stamped rows, so nothing archivable lands in the gap between the export and the delete. ArchiveAllAndResetAsync (the size-triggered reset path) keeps its write lock unchanged - there the lock also prevents collectors writing rows between the export snapshot and the database reset. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Problem
Split out from #976. While Lite is connected to servers, tab navigation intermittently shows the spinning wheel or a 2–3 s delay, correlating with archival and worsening with more monitored servers.
ArchiveService.ArchiveOldDataAsyncheld DuckDB's exclusive write lock (DuckDbInitializer.s_dbLock) across the entire export-to-Parquet +DELETEloop. Export-to-Parquet (COPY … TO) only reads the database, but under the write lock it blocked every UI read for its full duration — and UI queries take a read lock with no timeout, so a tab switch froze until archival finished.Change
In
ArchiveOldDataAsync, per table:DELETEtakes the exclusive write lock, briefly.Splitting the lock scopes is safe here: the
DELETEonly removes rows older than the cutoff, and collectors only ever insert "now"-stamped rows, so nothing archivable can land in the gap between the export and the delete.ArchiveAllAndResetAsync(the size-triggered "export everything → reset database" path) is left unchanged — there the write lock also prevents collectors writing rows between the export snapshot and the reset, and it's the rare emergency path rather than the routine one.Test plan
dotnet build Lite/PerformanceMonitorLite.csproj -c Debug— clean, 0 warnings.COPY … SELECT … TO), so a read lock is sufficient; only theDELETEmutates the file and keeps the exclusive lock.🤖 Generated with Claude Code