Repository navigation
perf: write periodic station progress off the main thread - #33
Conversation
The 30-second progress save fsynced stations.json on the server thread (about 25 s of main-thread fsync per day on Main). It now snapshots the stations on the main thread and writes them with the same temp file, fsync and atomic rename on a single station writer thread. Every state change (construction start, completion, cancellation, station removal, reload and disable) still saves synchronously and reports failure as before. Each snapshot carries a sequence number and a queued snapshot older than one already written is dropped, so a background write can never put back state older than a synchronous checkpoint. Disable saves synchronously, then drains and stops the writer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Snapshot writing and writer lifecycle src/main/java/net/tfminecraft/vfbuilders/data/Database.java, src/test/java/net/tfminecraft/vfbuilders/data/StationWriterTest.java, src/test/java/net/tfminecraft/vfbuilders/DatabaseFixture.java |
Database resolves the station file at call time, captures snapshots, and supports synchronous and queued writes. It serialises writes and provides writer shutdown. Tests cover snapshot ordering, failures, shutdown, timeout, interruption, and restart. |
Periodic saves and shutdown src/main/java/net/tfminecraft/vfbuilders/managers/StationManager.java, src/test/java/net/tfminecraft/vfbuilders/SchedulerTest.java |
The station manager queues periodic saves when a station has a blueprint and closes the database after saving state during shutdown. Scheduler tests check the queued save and shutdown order. |
Priority:
Estimated code review effort: 3 (Moderate) | ~20 minutes
Change: Refactor
Sequence Diagram(s)
sequenceDiagram
participant StationManager
participant Database
participant WriterExecutor
participant StationsFile
StationManager->>Database: saveStationsLater(stations)
Database->>Database: Capture snapshot on calling thread
Database->>WriterExecutor: Submit snapshot
WriterExecutor->>StationsFile: Write snapshot
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Warning
Git: CodeRabbit could not clone the repository, so clone-backed analysis was skipped and this review may be incomplete. Verify repository clone access, such as SSH credentials, before requesting another full review. If clone access is intentionally unavailable, use path_filters to narrow the review scope.
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands.
Database fixes its file when the class first loads. On CI another test loads it under its own temp folder first, so the writer tests read the fixture path and found nothing. They now ask Database for the real path. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Database fixed its path from whichever plugin data folder was set when the class first loaded, so test classes broke each other depending on run order. The path now comes from the plugin's data folder at save and load time; the background writer gets it inside the snapshot taken on the calling thread. On the server the data folder never changes, so saves and loads use the same file as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
CI found an order-dependent test failure, now fixed:
|
|
@coderabbitai review |
✅ Action performed
|
Why
Main profiles, 22 hourly spark dumps 10-29 07:00 → 10-30 05:00 (peak ~30 players, ~23 ms/tick total).
StationManager$1.run → Database.saveStationsNowfsynced on a main-thread timer: 25 s of main-thread fsync over the day.Change
VFBuilders station writer) with the same temp → fsync → atomic rename.Testing
StationWriterTest(6 new) and updatedSchedulerTest; 61 pass.LifecycleTestfails only on Windows (POSIX permissions).stations-*.tmp.🤖 Generated with Claude Code