Clear last position on replica sync error

This commit is contained in:
Ben Johnson
2021-01-16 07:45:08 -07:00
parent cbc2dce6dc
commit 25fec29e1a
3 changed files with 26 additions and 7 deletions

View File

@@ -566,6 +566,15 @@ func (r *FileReplica) snapshotN(generation string) (int, error) {
}
func (r *FileReplica) Sync(ctx context.Context) (err error) {
// Clear last position if if an error occurs during sync.
defer func() {
if err != nil {
r.mu.Lock()
r.pos = Pos{}
r.mu.Unlock()
}
}()
// Find current position of database.
dpos, err := r.db.Pos()
if err != nil {
@@ -588,7 +597,7 @@ func (r *FileReplica) Sync(ctx context.Context) (err error) {
}
// Determine position, if necessary.
if r.LastPos().IsZero() {
if r.LastPos().Generation != generation {
pos, err := r.CalcPos(ctx, generation)
if err != nil {
return fmt.Errorf("cannot determine replica position: %s", err)