Skip to content

Commit 20a51a3

Browse files
committed
Remove MinLevel.
1 parent 2dbcc48 commit 20a51a3

File tree

4 files changed

+6
-61
lines changed

4 files changed

+6
-61
lines changed

litestream/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ The `"litestream"` SQLite VFS implements Litestream
99

1010
See the [example](example_test.go) for how to use.
1111

12-
To improve performance,
13-
increase `PollInterval` (and `MinLevel`) as much as you can,
12+
To improve performance, increase `PollInterval` as much as you can,
1413
and set [`PRAGMA cache_size=N`](https://www.sqlite.org/pragma.html#pragma_cache_size)
1514
(or use `_pragma=cache_size(N)`).
1615

litestream/api.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@ type ReplicaOptions struct {
4040
// used by the replica at MinLevel+1.
4141
PollInterval time.Duration
4242

43-
// Minimum compaction level to track.
44-
MinLevel int
45-
4643
// CacheSize is the maximum size of the page cache in bytes.
4744
// Zero means DefaultCacheSize, negative disables caching.
4845
CacheSize int
@@ -61,7 +58,6 @@ func NewReplica(name string, client ReplicaClient, options ReplicaOptions) {
6158
if options.CacheSize == 0 {
6259
options.CacheSize = DefaultCacheSize
6360
}
64-
options.MinLevel = max(0, min(options.MinLevel, litestream.SnapshotLevel))
6561

6662
liteMtx.Lock()
6763
defer liteMtx.Unlock()

litestream/vfs.go

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ func (f *liteFile) Pragma(name, value string) (string, error) {
168168
if txid == 0 {
169169
// Outside transaction.
170170
f.db.mtx.Lock()
171-
txid = f.db.txids[f.db.opts.MinLevel]
171+
txid = f.db.txids[0]
172172
f.db.mtx.Unlock()
173173
}
174174
return txid.String(), nil
@@ -245,18 +245,18 @@ func (f *liteDB) pollReplica(ctx context.Context) (*pageIndex, ltx.TXID, error)
245245

246246
// Limit polling interval.
247247
if time.Since(f.lastPoll) < f.opts.PollInterval {
248-
return f.pages, f.txids[f.opts.MinLevel], nil
248+
return f.pages, f.txids[0], nil
249249
}
250250

251-
for level := range pollLevels(f.opts.MinLevel) {
251+
for level := range []int{0, 1, litestream.SnapshotLevel} {
252252
if err := f.updateLevel(ctx, level); err != nil {
253253
f.opts.Logger.Error("cannot poll replica", "error", err)
254254
return nil, 0, err
255255
}
256256
}
257257

258258
f.lastPoll = time.Now()
259-
return f.pages, f.txids[f.opts.MinLevel], nil
259+
return f.pages, f.txids[0], nil
260260
}
261261

262262
// +checklocks:f.mtx
@@ -313,26 +313,10 @@ func (f *liteDB) updateInfo(ctx context.Context, info *ltx.FileInfo) error {
313313
// Track the MaxTXID for each level.
314314
maxTXID := &f.txids[info.Level]
315315
*maxTXID = max(*maxTXID, info.MaxTXID)
316+
f.txids[0] = max(f.txids[0], *maxTXID)
316317
return nil
317318
}
318319

319-
func pollLevels(minLevel int) (r []int) {
320-
// Updating from lower to upper levels is non-racy,
321-
// since LTX files are compacted into higher levels
322-
// before the lower level LTX files are deleted.
323-
324-
// Also, only level 0 compactions and snapshots delete files,
325-
// so the intermediate levels never need to be updated.
326-
327-
if minLevel <= 0 {
328-
return append(r, 0, 1, litestream.SnapshotLevel)
329-
}
330-
if minLevel >= litestream.SnapshotLevel {
331-
return append(r, litestream.SnapshotLevel)
332-
}
333-
return append(r, minLevel, litestream.SnapshotLevel)
334-
}
335-
336320
// Type aliases; these are a mouthful.
337321
type pageIndex = wbt.Tree[uint32, ltx.PageIndexElem]
338322
type levelTXIDs = [litestream.SnapshotLevel + 1]ltx.TXID

litestream/vfs_test.go

Lines changed: 0 additions & 34 deletions
This file was deleted.

0 commit comments

Comments
 (0)