From 73fbfc0e22fd3b068c687205f793017d87e4985f Mon Sep 17 00:00:00 2001 From: Toni Spets Date: Fri, 15 Dec 2023 10:38:48 +0200 Subject: [PATCH] Always sort WAL segments on restore point calc Some S3 implementations, like Storj, don't return objects in order unlike the real S3 API. It's against AWS documentation but they have their reasons not to pre-sort them. Since there's only one place where the order matters and we're going to iterate all of them anyway and there's a sort implementation for a WAL segment slice we can do just that to add compatibility without any meaningful performance hit. This same sorting is already done when listing snapshots. Fixes #535 --- replica.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/replica.go b/replica.go index bf858836..b4052ee1 100644 --- a/replica.go +++ b/replica.go @@ -1287,10 +1287,15 @@ func (r *Replica) walSegmentMap(ctx context.Context, generation string, maxIndex } defer itr.Close() - m := make(map[int][]int64) + a := []WALSegmentInfo{} for itr.Next() { - info := itr.WALSegment() + a = append(a, itr.WALSegment()) + } + sort.Sort(WALSegmentInfoSlice(a)) + + m := make(map[int][]int64) + for _, info := range a { // Exit if we go past the max timestamp or index. if !maxTimestamp.IsZero() && info.CreatedAt.After(maxTimestamp) { break // after max timestamp, skip