From 8c37aa2d976d439c0615c57af7db835aa182cb07 Mon Sep 17 00:00:00 2001 From: Nuno Cruces Date: Thu, 4 Dec 2025 16:31:41 +0000 Subject: [PATCH] Remove inprocess primary. --- litestream/README.md | 26 +++----------------------- litestream/api.go | 26 +------------------------- litestream/vfs_test.go | 20 ++++++++++---------- 3 files changed, 14 insertions(+), 58 deletions(-) diff --git a/litestream/README.md b/litestream/README.md index b8c7516..4c68253 100644 --- a/litestream/README.md +++ b/litestream/README.md @@ -1,26 +1,6 @@ -# Litestream in-process replication and lightweight read-replicas +# Litestream lightweight read-replicas -This package adds **EXPERIMENTAL** support for in-process [Litestream](https://litestream.io/). - -## Lightweight read-replicas - -The `"litestream"` SQLite VFS implements Litestream -[lightweight read-replicas](https://fly.io/blog/litestream-revamped/#lightweight-read-replicas). +This package implements the **EXPERIMENTAL** `"litestream"` SQLite VFS +that offers Litestream [lightweight read-replicas](https://fly.io/blog/litestream-revamped/#lightweight-read-replicas). See the [example](example_test.go) for how to use. - -To improve performance, increase `PollInterval` as much as you can, -and set [`PRAGMA cache_size=N`](https://www.sqlite.org/pragma.html#pragma_cache_size) -(or use `_pragma=cache_size(N)`). - -## In-process replication - -For disaster recovery, it is probably best if you run Litestream as a separate background process, -as recommended by the [tutorial](https://litestream.io/getting-started/). - -However, running Litestream as a background process requires -compatible locking and cross-process shared memory WAL -(see our [support matrix](https://github.com/ncruces/go-sqlite3/wiki/Support-matrix)). - -If your OS lacks locking or shared memory support, -you can use `NewPrimary` with the `sqlite3_dotlk` build tag to setup in-process replication. diff --git a/litestream/api.go b/litestream/api.go index ff54fe3..1608c91 100644 --- a/litestream/api.go +++ b/litestream/api.go @@ -2,7 +2,6 @@ package litestream import ( - "context" "log/slog" "sync" "time" @@ -75,27 +74,4 @@ func RemoveReplica(name string) { delete(liteDBs, name) } -// NewPrimary creates a new primary that replicates through client. -// If restore is not nil, the database is first restored. -func NewPrimary(ctx context.Context, path string, client ReplicaClient, restore *RestoreOptions) (*litestream.DB, error) { - lsdb := litestream.NewDB(path) - lsdb.Replica = litestream.NewReplicaWithClient(lsdb, client) - - if restore != nil { - err := lsdb.Replica.Restore(ctx, *restore) - if err != nil { - return nil, err - } - } - - err := lsdb.Open() - if err != nil { - return nil, err - } - return lsdb, nil -} - -type ( - ReplicaClient = litestream.ReplicaClient - RestoreOptions = litestream.RestoreOptions -) +type ReplicaClient = litestream.ReplicaClient diff --git a/litestream/vfs_test.go b/litestream/vfs_test.go index 7102bf8..dd2dd77 100644 --- a/litestream/vfs_test.go +++ b/litestream/vfs_test.go @@ -23,12 +23,9 @@ func Test_integration(t *testing.T) { defer db.Close() client := file.NewReplicaClient(backup) + setupReplication(t, dbpath, client) + NewReplica("test.db", client, ReplicaOptions{}) - - if err := setupPrimary(t, dbpath, client); err != nil { - t.Fatal(err) - } - replica, err := driver.Open("file:test.db?vfs=litestream") if err != nil { t.Fatal(err) @@ -114,10 +111,13 @@ func Test_integration(t *testing.T) { } } -func setupPrimary(tb testing.TB, path string, client ReplicaClient) error { - db, err := NewPrimary(tb.Context(), path, client, nil) - if err == nil { - tb.Cleanup(func() { db.Close(tb.Context()) }) +func setupReplication(tb testing.TB, path string, client ReplicaClient) { + lsdb := litestream.NewDB(path) + lsdb.Replica = litestream.NewReplicaWithClient(lsdb, client) + + err := lsdb.Open() + if err != nil { + tb.Fatal(err) } - return err + tb.Cleanup(func() { lsdb.Close(tb.Context()) }) }