#1537·litestream

ABS/GCS: LTXFiles applies seek as a blob-name prefix, so compaction advances one TXID per tick and L2+ stalls

Author: petergaultneyCreated Sep 22, 2026Updated Sep 22, 2026

:

Bug Description

On the ABS and GCS replica clients, LTXFiles(ctx, level, seek, ...) appends seek to the blob-name prefix, so a listing that should return "every file with MinTXID >= seek" returns only the file named <seek>-*.ltx, or nothing at all:

  • abs/replica_client.go (v0.5.17, L386): if seek != 0 { prefix += seek.String() }
  • gs/replica_client.go (v0.5.17, L133): same.

The S3 client lists by level prefix and filters with info.MinTXID < itr.seek (s3/replica_client.go L1709), which is the intended semantics. The ABS iterator has the same filter (L461), but the prefix has already narrowed the listing to one name.

Compactor.Compact calls LTXFiles(srcLevel, prevMaxInfo.MaxTXID+1) (compactor.go L111-113), so on ABS/GCS:

  1. L0 -> L1 compaction advances exactly one TXID per L1 interval (30s by default). Any sustained rate above 2 TXIDs/min builds an L0 backlog that never drains.
  2. L1 -> L2 (and up) compaction stops for good once the L1 file named <L2 max + 1> is gone: the prefix matches nothing, Compact returns ErrNoCompaction, and that is only logged at debug level.

The backlog is what makes #1270 deterministic rather than an occasional race. The restore plan is the snapshot plus every L1 file plus every backlogged L0 file, opened sequentially. On our replica that is ~1,550 files and ~100s. Meanwhile each L1 tick compacts one more L0 file and L0 retention deletes it, so the restore opens a planned file that is gone and fails with open ltx file: file does not exist on every attempt.

Environment

Litestream version: v0.5.11 in production; the code path is unchanged through v0.5.17.

Operating system & version: Kubernetes (AKS), official litestream/litestream image.

Installation method: Docker.

Storage backend: Azure Blob Storage.

Steps to Reproduce

  1. Replicate a WAL-mode DB to an abs:// replica with default compaction levels.
  2. Commit writes faster than one sync per 30s for a few minutes (or restart the replicator so it writes a fresh snapshot to L0 alongside a burst of syncs).
  3. Watch the L1 compaction complete log lines. Every one has txid.min == txid.max, advancing by one each tick.
  4. List ltx/0/: the backlog grows. List ltx/2/: its newest file stops advancing.
  5. Run litestream restore against the replica while the replicator is running.

Expected behavior: Each L1 compaction folds in every L0 file after the current L1 max. Higher levels keep compacting. Restores succeed while replication is running.

Actual behavior: One L0 file per tick. L2/L3 frozen. Restores fail with open ltx file: file does not exist.

Configuration

litestream.yml
yaml
dbs:
  - path: /data/app.sqlite
    replicas:
      - url: abs://<account>@<container>/<path>

Logs

Log output

Replicator (L1 compaction: one TXID per tick; retention deletes one L0 file per tick):

level=INFO msg="compaction complete" level=1 txid.min=00000000000054aa txid.max=00000000000054aa size=1185059
level=INFO msg="l0 retention enforced" deleted_count=1 max_l1_txid=00000000000054ab
level=INFO msg="compaction complete" level=1 txid.min=00000000000054ab txid.max=00000000000054ab size=2932983
level=INFO msg="l0 retention enforced" deleted_count=1 max_l1_txid=00000000000054ac
level=INFO msg="compaction complete" level=1 txid.min=00000000000054ac txid.max=00000000000054ac size=206

Replica contents at the time (DB TXID 570d):

L0: 531 files, 54fb..570d, oldest 3.5h old, 9.4 GB
L1: 1018 files, one per TXID, 5101..54fa
L2: 1 file, 00e1, last written 2026-08-06
L3: 1 file, 001e, last written 2026-08-05
L9: 0001-5101, written today

Concurrent restore (fails every attempt, ~106s in):

level=ERROR msg="failed to run" error="open ltx file: file does not exist"

Additional Context

A second replica in the same state has a low write rate: its L0 has caught up (1 file), and it restores fine. Its L2/L3 are also frozen since 2026-08-06, and its L1 is likewise one file per TXID.

Suggested fix: drop seek from the prefix in the ABS and GCS clients and rely on the MinTXID < seek filter, as S3 does. Using the listing's start-after/marker would avoid a full-level list, but the filter alone fixes correctness.

Related: #1270 (restore TOCTOU against L0 retention). Fixing #1270 alone would make restores succeed, but the compaction stall stays.