From 543c87cc3824c035f484d7a899122c9c3765ec4a Mon Sep 17 00:00:00 2001 From: ahrtr Date: Mon, 4 Apr 2022 18:58:18 +0800 Subject: [PATCH] etcd-dump-logs will panic if there is no WAL entry after the snapshot --- tools/etcd-dump-logs/main.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tools/etcd-dump-logs/main.go b/tools/etcd-dump-logs/main.go index cda3dd5b8..82789c810 100644 --- a/tools/etcd-dump-logs/main.go +++ b/tools/etcd-dump-logs/main.go @@ -123,8 +123,10 @@ and output a hex encoded line of binary for each input line`) fmt.Printf("WAL metadata:\nnodeID=%s clusterID=%s term=%d commitIndex=%d vote=%s\n", id, cid, state.Term, state.Commit, vid) - fmt.Printf("WAL entries:\n") - fmt.Printf("lastIndex=%d\n", ents[len(ents)-1].Index) + fmt.Printf("WAL entries: %d\n", len(ents)) + if len(ents) > 0 { + fmt.Printf("lastIndex=%d\n", ents[len(ents)-1].Index) + } fmt.Printf("%4s\t%10s\ttype\tdata", "term", "index") if *streamdecoder != "" {