Skip to content

Commit

Permalink
Ignore WAL indices before snapshot that is being restored
Browse files Browse the repository at this point in the history
If the replica has stray WAL files from older snapshots they will
break restoring even though they can be ignored and reaped later
through retention.
  • Loading branch information
hifi committed Nov 30, 2023
1 parent abcf103 commit e04eb44
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions replica.go
Original file line number Diff line number Diff line change
Expand Up @@ -1120,7 +1120,7 @@ func (r *Replica) Restore(ctx context.Context, opt RestoreOptions) (err error) {
}

// Compute list of offsets for each WAL index.
walSegmentMap, err := r.walSegmentMap(ctx, opt.Generation, opt.Index, opt.Timestamp)
walSegmentMap, err := r.walSegmentMap(ctx, opt.Generation, minWALIndex, opt.Index, opt.Timestamp)
if err != nil {
return fmt.Errorf("cannot find max wal index for restore: %w", err)
}
Expand Down Expand Up @@ -1328,7 +1328,7 @@ func (r *Replica) SnapshotIndexByIndex(ctx context.Context, generation string, i

// walSegmentMap returns a map of WAL indices to their segments.
// Filters by a max timestamp or a max index.
func (r *Replica) walSegmentMap(ctx context.Context, generation string, maxIndex int, maxTimestamp time.Time) (map[int][]int64, error) {
func (r *Replica) walSegmentMap(ctx context.Context, generation string, minIndex, maxIndex int, maxTimestamp time.Time) (map[int][]int64, error) {
itr, err := r.Client.WALSegments(ctx, generation)
if err != nil {
return nil, err
Expand All @@ -1344,6 +1344,8 @@ func (r *Replica) walSegmentMap(ctx context.Context, generation string, maxIndex
break // after max timestamp, skip
} else if info.Index > maxIndex {
break // after max index, skip
} else if info.Index < minIndex {
continue // ignore indices before snapshot
}

// Verify offsets are added in order.
Expand Down

0 comments on commit e04eb44

Please sign in to comment.