Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tools/etcd-dump-logs] Fix the usage of --start-index in etcd-dump-logs #19082

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions tools/etcd-dump-logs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,15 @@ and output a hex encoded line of binary for each input line`)
log.Fatal("start-snap and start-index flags cannot be used together.")
}

startFromIndex := false
flag.Visit(func(f *flag.Flag) {
if f.Name == "start-index" {
startFromIndex = true
}
})

if !*raw {
ents := readUsingReadAll(lg, index, snapfile, dataDir, waldir)
ents := readUsingReadAll(lg, startFromIndex, index, snapfile, dataDir, waldir)

fmt.Printf("WAL entries: %d\n", len(ents))
if len(ents) > 0 {
Expand Down Expand Up @@ -104,16 +111,14 @@ and output a hex encoded line of binary for each input line`)
}
}

func readUsingReadAll(lg *zap.Logger, index *uint64, snapfile *string, dataDir string, waldir *string) []raftpb.Entry {
func readUsingReadAll(lg *zap.Logger, startFromIndex bool, index *uint64, snapfile *string, dataDir string, waldir *string) []raftpb.Entry {
var (
walsnap walpb.Snapshot
snapshot *raftpb.Snapshot
err error
)

isIndex := *index != 0

if isIndex {
if startFromIndex {
fmt.Printf("Start dumping log entries from index %d.\n", *index)
walsnap.Index = *index
} else {
Expand Down Expand Up @@ -154,7 +159,7 @@ func readUsingReadAll(lg *zap.Logger, index *uint64, snapfile *string, dataDir s
}
wmetadata, state, ents, err := w.ReadAll()
w.Close()
if err != nil && (!isIndex || !errors.Is(err, wal.ErrSnapshotNotFound)) {
if err != nil && (!startFromIndex || !errors.Is(err, wal.ErrSnapshotNotFound)) {
log.Fatalf("Failed reading WAL: %v", err)
}
id, cid := parseWALMetadata(wmetadata)
Expand Down
Loading