Fix DuckDB file corruption during maintenance (#218)#221
Merged
erikdarlingdata merged 1 commit intodevfrom Feb 21, 2026
Merged
Conversation
…ystem (#218) Root cause: archival DELETEs + CHECKPOINT reorganized/truncated the DuckDB file while UI connections had stale file offsets, causing "Reached the end of the file" crashes after ~1 hour of uptime. Fix: ReaderWriterLockSlim coordinates UI readers with maintenance writers. UI queries hold read locks (unlimited concurrency) via LockedConnection wrapper. CHECKPOINT and archive DELETEs hold exclusive write locks (<1s duration). Maintenance overhaul: - Replaced compaction cycle (File.Replace race condition) with archive-all-and-reset - Size-based trigger at 512MB archives ALL data to parquet, deletes .duckdb, reinits - Tested: 515MB → 19MB in <1s, 65K rows to ~400KB ZSTD parquet per cycle - Per-reset timestamped parquet naming (20260221_1925_table.parquet) eliminates merge logic and simplifies 90-day retention (delete by date prefix) - RetentionService handles both new timestamped and legacy monthly formats - Wired AppLoggerAdapter<T> for all 8 services that had null loggers - Removed dead CompactAsync method (~140 lines) Tested with 4 SQL Servers under HammerDB load, 3 successful archive+reset cycles, zero errors, archive views correctly serve data from all parquet file sets. Co-Authored-By: Claude Opus 4.6 <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.
Summary
Fixes #218 — Lite app crashes with "Reached the end of the file" DuckDB errors after ~1 hour of uptime.
ReaderWriterLockSlimcoordinates UI readers (read locks viaLockedConnectionwrapper) with maintenance writers (exclusive write locks on CHECKPOINT and archive DELETEs)File.Replacerace condition) with archive-all-and-reset at 512MB threshold20260221_1925_table.parquet) — no merge logic, trivial 90-day retention by date prefixAppLoggerAdapter<T>for all 8 services that had null loggersCompactAsyncmethod (~140 lines)Test plan
server_id— no cross-server contaminationyyyyMMddandyyyy-MMfilename formats🤖 Generated with Claude Code