Implement live read replication

This commit adds an http server and client for streaming snapshots
and WAL pages from an upstream Litestream primary to a read-only
replica.
This commit is contained in:
Ben Johnson
2022-02-19 07:46:01 -07:00
parent 4898fc2fc1
commit a090706421
19 changed files with 1241 additions and 57 deletions

21
db_bsd.go Normal file
View File

@@ -0,0 +1,21 @@
//go:build !linux
package litestream
import (
"io"
"os"
)
// WithFile executes fn with a file handle for the main database file.
// On Linux, this is a unique file handle for each call. On non-Linux
// systems, the file handle is shared because of lock semantics.
func (db *DB) WithFile(fn func(f *os.File) error) error {
db.mu.Lock()
defer db.mu.Unlock()
if _, err := db.f.Seek(0, io.SeekStart); err != nil {
return err
}
return fn(db.f)
}