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

View File

@@ -113,6 +113,21 @@ func CreateFile(filename string, mode os.FileMode, uid, gid int) (*os.File, erro
return f, nil
}
// WriteFile writes data to a named file and sets the mode & uid/gid.
func WriteFile(name string, data []byte, perm os.FileMode, uid, gid int) error {
f, err := os.OpenFile(name, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, perm)
if err != nil {
return err
}
_ = f.Chown(uid, gid)
_, err = f.Write(data)
if err1 := f.Close(); err1 != nil && err == nil {
err = err1
}
return err
}
// MkdirAll is a copy of os.MkdirAll() except that it attempts to set the
// mode/uid/gid to match fi for each created directory.
func MkdirAll(path string, mode os.FileMode, uid, gid int) error {