Skip to content

Checkpoint starvation #10559

Open
Open

Description

@bt90

What happened?

Our current database maintenance logic is prone to checkpoint starvation. The problem is that there's no guarantee that readers are active during the maintenance window. While wal_checkpoint(TRUNCATE) blocks other writers, there is no such thing for readers:

https://www.sqlite.org/pragma.html#pragma_wal_checkpoint

The result of this is a WAL that will keep its size or even grow further until a checkpoint without an active reader transaction can be executed. For long running scans and transfers, this might never happen.

As the WAL size has a negative impact on reader performance, we end up with a positive feedback loop. The readers execute slower with a growing WAL and the chances of a successful checkpoint vanish.

Syncthing version

v2.0.14

Platform & operating system

Linux

Browser version

No response

Relevant log output

Activity

  1. added theissue type on Feb 4, 2026
  2. added
    bug
    needs-triage
    on Feb 4, 2026
  3. dmih commented on Feb 4, 2026

    @dmih

    as it seems that it will require isolation readers from checkpoint, the fix to this bug will probably also fix this: #10529

  4. bt90 commented on Feb 4, 2026

    @bt90
    ContributorAuthor

    https://sqlite.org/c3ref/wal_checkpoint_v2.html has a bit more details.

    FULL:

    This mode blocks (it invokes the busy-handler callback) until there is no database writer and all readers are reading from the most recent database snapshot.

    RESTART:

    This mode works the same way as SQLITE_CHECKPOINT_FULL with the addition that after checkpointing the log file it blocks (calls the busy-handler callback) until all readers are reading from the database file only

    If I'm interpreting this correctly, a checkpoint would fail while there's an active reader transaction based on an older snapshot of the database.

  5. bt90 commented on Feb 4, 2026

    @bt90
    ContributorAuthor

    https://forum.syncthing.net/t/is-syncthing-v2-with-very-large-folders-possible/26082/38 shows that we're constantly moving pages from the WAL to the database(albeit slower than the WAL is growing). This means that it's not caused by a read transaction that is running for hours/days.

    The problem is that those reads are in quick succession. Our checkpointer routine is never able to hit a gap.

  6. bt90 commented on Feb 5, 2026

    @bt90
    ContributorAuthor

    The rabbit hole goes even deeper. Readers might trip the autocheckpointer threshold:

    https://sqlite.org/pragma.html#pragma_wal_autocheckpoint

    While we took checkpoint handling into our own hands, we didn't disable the auto mechanism.

    All calls obtain an exclusive "checkpoint" lock on the database file. If any other process is running a checkpoint operation at the same time, the lock cannot be obtained and SQLITE_BUSY is returned. Even if there is a busy-handler configured, it will not be invoked in this case.

    Given a large WAL, all readers would trigger a PASSIVE checkpoint on commit. If such a checkpoint is executing our manual checkpoints would instantly fail.

  7. schaurian commented on Sep 12, 2026

    @schaurian
  8. calmh commented on Sep 12, 2026

    @calmh
    Member

    I don't follow your analysis. The sequence will update on any insert or change. If the disk is full and everything is stopped it may indeed not run, but also would likely not succeed since I'm sure the compaction requires additional space for temp files.

  9. schaurian commented on Sep 13, 2026

    @schaurian
  10. added a commit that references this issue on Nov 4, 2026
  11. added a commit that references this issue on Nov 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugneeds-triage

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions