Skip to content

Commit 8c37aa2

Browse files
committed
Remove inprocess primary.
1 parent ca93c49 commit 8c37aa2

File tree

3 files changed

+14
-58
lines changed

3 files changed

+14
-58
lines changed

litestream/README.md

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,6 @@
1-
# Litestream in-process replication and lightweight read-replicas
1+
# Litestream lightweight read-replicas
22

3-
This package adds **EXPERIMENTAL** support for in-process [Litestream](https://litestream.io/).
4-
5-
## Lightweight read-replicas
6-
7-
The `"litestream"` SQLite VFS implements Litestream
8-
[lightweight read-replicas](https://fly.io/blog/litestream-revamped/#lightweight-read-replicas).
3+
This package implements the **EXPERIMENTAL** `"litestream"` SQLite VFS
4+
that offers Litestream [lightweight read-replicas](https://fly.io/blog/litestream-revamped/#lightweight-read-replicas).
95

106
See the [example](example_test.go) for how to use.
11-
12-
To improve performance, increase `PollInterval` as much as you can,
13-
and set [`PRAGMA cache_size=N`](https://www.sqlite.org/pragma.html#pragma_cache_size)
14-
(or use `_pragma=cache_size(N)`).
15-
16-
## In-process replication
17-
18-
For disaster recovery, it is probably best if you run Litestream as a separate background process,
19-
as recommended by the [tutorial](https://litestream.io/getting-started/).
20-
21-
However, running Litestream as a background process requires
22-
compatible locking and cross-process shared memory WAL
23-
(see our [support matrix](https://github.com/ncruces/go-sqlite3/wiki/Support-matrix)).
24-
25-
If your OS lacks locking or shared memory support,
26-
you can use `NewPrimary` with the `sqlite3_dotlk` build tag to setup in-process replication.

litestream/api.go

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
package litestream
33

44
import (
5-
"context"
65
"log/slog"
76
"sync"
87
"time"
@@ -75,27 +74,4 @@ func RemoveReplica(name string) {
7574
delete(liteDBs, name)
7675
}
7776

78-
// NewPrimary creates a new primary that replicates through client.
79-
// If restore is not nil, the database is first restored.
80-
func NewPrimary(ctx context.Context, path string, client ReplicaClient, restore *RestoreOptions) (*litestream.DB, error) {
81-
lsdb := litestream.NewDB(path)
82-
lsdb.Replica = litestream.NewReplicaWithClient(lsdb, client)
83-
84-
if restore != nil {
85-
err := lsdb.Replica.Restore(ctx, *restore)
86-
if err != nil {
87-
return nil, err
88-
}
89-
}
90-
91-
err := lsdb.Open()
92-
if err != nil {
93-
return nil, err
94-
}
95-
return lsdb, nil
96-
}
97-
98-
type (
99-
ReplicaClient = litestream.ReplicaClient
100-
RestoreOptions = litestream.RestoreOptions
101-
)
77+
type ReplicaClient = litestream.ReplicaClient

litestream/vfs_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,9 @@ func Test_integration(t *testing.T) {
2323
defer db.Close()
2424

2525
client := file.NewReplicaClient(backup)
26-
NewReplica("test.db", client, ReplicaOptions{})
27-
28-
if err := setupPrimary(t, dbpath, client); err != nil {
29-
t.Fatal(err)
30-
}
26+
setupReplication(t, dbpath, client)
3127

28+
NewReplica("test.db", client, ReplicaOptions{})
3229
replica, err := driver.Open("file:test.db?vfs=litestream")
3330
if err != nil {
3431
t.Fatal(err)
@@ -114,10 +111,13 @@ func Test_integration(t *testing.T) {
114111
}
115112
}
116113

117-
func setupPrimary(tb testing.TB, path string, client ReplicaClient) error {
118-
db, err := NewPrimary(tb.Context(), path, client, nil)
119-
if err == nil {
120-
tb.Cleanup(func() { db.Close(tb.Context()) })
114+
func setupReplication(tb testing.TB, path string, client ReplicaClient) {
115+
lsdb := litestream.NewDB(path)
116+
lsdb.Replica = litestream.NewReplicaWithClient(lsdb, client)
117+
118+
err := lsdb.Open()
119+
if err != nil {
120+
tb.Fatal(err)
121121
}
122-
return err
122+
tb.Cleanup(func() { lsdb.Close(tb.Context()) })
123123
}

0 commit comments

Comments
 (0)