Skip to content

Commit cb2e0a1

Browse files
committed
raftengine/etcd: remove redundant sort.Strings in purgeOldSnapFiles
os.ReadDir returns entries sorted by name per Go spec. Since snap file names are zero-padded hex, directory order already equals chronological order, making the explicit sort unnecessary.
1 parent af84810 commit cb2e0a1

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

internal/raftengine/etcd/wal_store.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"bytes"
55
"os"
66
"path/filepath"
7-
"sort"
87

98
"github.com/cockroachdb/errors"
109
"go.etcd.io/etcd/server/v3/etcdserver/api/snap"
@@ -367,9 +366,9 @@ func purgeOldSnapFiles(snapDir string) error {
367366
return nil
368367
}
369368

370-
// Sort ascending (oldest first) — snap names are zero-padded hex so
371-
// lexicographic order equals chronological order.
372-
sort.Strings(snaps)
369+
// snaps is already sorted ascending (oldest first) because os.ReadDir
370+
// returns entries in directory order which, for zero-padded hex names,
371+
// equals chronological order.
373372

374373
var combined error
375374
for _, name := range snaps[:len(snaps)-defaultMaxSnapFiles] {

0 commit comments

Comments
 (0)