From e65536f81d7fc5c31cea1593a4e6f9691d18799e Mon Sep 17 00:00:00 2001 From: Ben Johnson Date: Sat, 16 Jan 2021 07:47:02 -0700 Subject: [PATCH] Stop waiting for replica if generation changes --- replica.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/replica.go b/replica.go index d6e53f4..39bb207 100644 --- a/replica.go +++ b/replica.go @@ -1072,10 +1072,14 @@ func waitForReplica(ctx context.Context, r Replica, pos Pos) error { continue } - ready := true + // Exit if the generation has changed while waiting as there will be + // no further progress on the old generation. if curr.Generation != pos.Generation { - ready = false - } else if curr.Index < pos.Index { + return fmt.Errorf("generation changed") + } + + ready := true + if curr.Index < pos.Index { ready = false } else if curr.Index == pos.Index && curr.Offset < pos.Offset { ready = false