mirror of
https://github.com/ncruces/go-sqlite3.git
synced 2026-01-11 21:49:13 +00:00
Remove inprocess primary.
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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()) })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user