| index c963b9398..1ed56bbef 100644 |
| --- a/internal/lease/lease.go |
| +++ b/internal/lease/lease.go |
| @@ -545,6 +545,12 @@ func (h *Held) newStore(dbPath string, syncInterval time.Duration) (*litestream. |
| h.mu.Lock() |
| oneShot := h.oneShot |
| h.mu.Unlock() |
| + if storeMonitorsOff.Load() > 0 { |
| + // SetStoreMonitorsOffForTest: no background compaction, snapshot |
| + // or retention pass. |
| + store.CompactionMonitorEnabled = false |
| + store.L0RetentionCheckInterval = 0 |
| + } |
| if oneShot { |
| // A checkpoint writes its L0 sync and nothing else. Each monitor |
| // runs one pass at store.Open, concurrently with the sync, and |
| @@ -1034,6 +1040,24 @@ func SetShutdownSyncTimeoutForTest(d time.Duration) (restore func()) { |
| return func() { shutdownSyncTimeout.Store(prev) } |
| } |
| |
| +// storeMonitorsOff counts the callers that turned off the background |
| +// passes of stores created from now on (SetStoreMonitorsOffForTest). |
| +var storeMonitorsOff atomic.Int32 |
| + |
| +// SetStoreMonitorsOffForTest turns off the background compaction, |
| +// snapshot and L0 retention passes of the stores of replicators created |
| +// from now on, until every caller has run its restore. A test seam: with |
| +// the store ready inside a wake (replicate before start, #1290), those |
| +// passes can run while a test counts the wake's requests or tears its |
| +// replicator down, and litestream v0.5.14 lets a store close while its |
| +// own snapshot is still reading the database (a race the race detector |
| +// reports). Process-global, counted, so parallel callers nest. |
| +func SetStoreMonitorsOffForTest() (restore func()) { |
| + storeMonitorsOff.Add(1) |
| + var once sync.Once |
| + return func() { once.Do(func() { storeMonitorsOff.Add(-1) }) } |
| +} |
| + |
| // Restore pulls the newest replicated state of s3://bucket/prefix into |
| // dbPath via litestream's restore API — the cold-wake path when the local DB |
| // is missing. prefix is the instance's location: the replica is the |