This commit adds an http server and client for streaming snapshots and WAL pages from an upstream Litestream primary to a read-only replica.
19 lines
410 B
Go
19 lines
410 B
Go
//go:build linux
|
|
|
|
package litestream
|
|
|
|
import "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 {
|
|
f, err := os.Open(db.path)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer f.Close()
|
|
|
|
return fn(f)
|
|
}
|