diff --git a/cmd/litestream/generations.go b/cmd/litestream/generations.go index 2b0e177..aceaafe 100644 --- a/cmd/litestream/generations.go +++ b/cmd/litestream/generations.go @@ -5,6 +5,7 @@ import ( "flag" "fmt" "os" + "sort" "text/tabwriter" "time" @@ -90,6 +91,8 @@ func (c *GenerationsCommand) Run(ctx context.Context, args []string) (err error) continue } + sort.Strings(generations) + // Iterate over each generation for the replica. for _, generation := range generations { createdAt, updatedAt, err := r.GenerationTimeBounds(ctx, generation) diff --git a/file/replica_client.go b/file/replica_client.go index 3b8508a..adbdbf0 100644 --- a/file/replica_client.go +++ b/file/replica_client.go @@ -6,7 +6,6 @@ import ( "io" "os" "path/filepath" - "sort" "github.com/benbjohnson/litestream" "github.com/benbjohnson/litestream/internal" @@ -180,8 +179,6 @@ func (c *ReplicaClient) Snapshots(ctx context.Context, generation string) (lites }) } - sort.Sort(litestream.SnapshotInfoSlice(infos)) - return litestream.NewSnapshotInfoSliceIterator(infos), nil } @@ -297,8 +294,6 @@ func (c *ReplicaClient) WALSegments(ctx context.Context, generation string) (lit }) } - sort.Sort(litestream.WALSegmentInfoSlice(infos)) - return litestream.NewWALSegmentInfoSliceIterator(infos), nil } diff --git a/replica.go b/replica.go index 6872bca..3d2b099 100644 --- a/replica.go +++ b/replica.go @@ -1302,10 +1302,15 @@ func (r *Replica) walSegmentMap(ctx context.Context, generation string, minIndex } 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 diff --git a/replica_client.go b/replica_client.go index 3a914e4..3d3f508 100644 --- a/replica_client.go +++ b/replica_client.go @@ -10,13 +10,13 @@ type ReplicaClient interface { // Returns the type of client. Type() string - // Returns a list of available generations. + // Returns a list of available generations. Order is undefined. Generations(ctx context.Context) ([]string, error) // Deletes all snapshots & WAL segments within a generation. DeleteGeneration(ctx context.Context, generation string) error - // Returns an iterator of all snapshots within a generation on the replica. + // Returns an iterator of all snapshots within a generation on the replica. Order is undefined. Snapshots(ctx context.Context, generation string) (SnapshotIterator, error) // Writes LZ4 compressed snapshot data to the replica at a given index @@ -31,7 +31,7 @@ type ReplicaClient interface { // the snapshot does not exist. SnapshotReader(ctx context.Context, generation string, index int) (io.ReadCloser, error) - // Returns an iterator of all WAL segments within a generation on the replica. + // Returns an iterator of all WAL segments within a generation on the replica. Order is undefined. WALSegments(ctx context.Context, generation string) (WALSegmentIterator, error) // Writes an LZ4 compressed WAL segment at a given position. diff --git a/sftp/replica_client.go b/sftp/replica_client.go index 6b082b4..1b8168c 100644 --- a/sftp/replica_client.go +++ b/sftp/replica_client.go @@ -8,7 +8,6 @@ import ( "net" "os" "path" - "sort" "sync" "time" @@ -141,8 +140,6 @@ func (c *ReplicaClient) Generations(ctx context.Context) (_ []string, err error) generations = append(generations, name) } - sort.Strings(generations) - return generations, nil } @@ -229,8 +226,6 @@ func (c *ReplicaClient) Snapshots(ctx context.Context, generation string) (_ lit }) } - sort.Sort(litestream.SnapshotInfoSlice(infos)) - return litestream.NewSnapshotInfoSliceIterator(infos), nil } @@ -363,8 +358,6 @@ func (c *ReplicaClient) WALSegments(ctx context.Context, generation string) (_ l }) } - sort.Sort(litestream.WALSegmentInfoSlice(infos)) - return litestream.NewWALSegmentInfoSliceIterator(infos), nil }