Copy shadow WAL immediately after init

This commit is contained in:
Ben Johnson
2021-01-18 10:01:16 -07:00
parent 2ce4052300
commit 358dcd4650
2 changed files with 89 additions and 46 deletions

View File

@@ -4,7 +4,6 @@ import (
"compress/gzip"
"context"
"fmt"
"hash/crc64"
"io"
"io/ioutil"
"log"
@@ -990,11 +989,11 @@ func ValidateReplica(ctx context.Context, r Replica) error {
// Compute checksum of primary database under lock. This prevents a
// sync from occurring and the database will not be written.
chksum0, pos, err := db.CRC64()
chksum0, chksum0alt, pos, err := db.CRC64()
if err != nil {
return fmt.Errorf("cannot compute checksum: %w", err)
}
log.Printf("%s(%s): primary checksum computed: %016x @ %s", db.Path(), r.Name(), chksum0, pos)
log.Printf("%s(%s): primary checksum computed: %016x @ %s (alt=%016x)", db.Path(), r.Name(), chksum0, pos, chksum0alt)
// Wait until replica catches up to position.
log.Printf("%s(%s): waiting for replica", db.Path(), r.Name())
@@ -1021,20 +1020,16 @@ func ValidateReplica(ctx context.Context, r Replica) error {
}
// Open file handle for restored database.
f, err := os.Open(db.Path())
chksum1, err := checksumFile(restorePath)
if err != nil {
return err
}
defer f.Close()
// Compute checksum.
h := crc64.New(crc64.MakeTable(crc64.ISO))
if _, err := io.Copy(h, f); err != nil {
chksum1alt, err := checksumFileAt(restorePath, int64(db.pageSize))
if err != nil {
return err
}
chksum1 := h.Sum64()
log.Printf("%s(%s): restore complete, replica checksum=%016x", db.Path(), r.Name(), chksum1)
log.Printf("%s(%s): restore complete, replica checksum=%016x (alt=%016x)", db.Path(), r.Name(), chksum1, chksum1alt)
// Validate checksums match.
if chksum0 != chksum1 {