From fbddfc515fe7ef683c2fc511f25195dc55d007ff Mon Sep 17 00:00:00 2001 From: baptiste-b-pegasys <85155432+baptiste-b-pegasys@users.noreply.github.com> Date: Tue, 3 May 2022 13:14:48 +0200 Subject: [PATCH] trim first empty entries, EOF error is a warning --- raft/handler.go | 6 +++++- raft/wal.go | 7 ++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/raft/handler.go b/raft/handler.go index f8833e7b46..d68981ddc6 100644 --- a/raft/handler.go +++ b/raft/handler.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "io" "net" "net/http" "net/url" @@ -487,7 +488,10 @@ func (pm *ProtocolManager) startRaft() { for _, entry := range entries { if entry.Type == raftpb.EntryNormal { var block types.Block - if err := rlp.DecodeBytes(entry.Data, &block); err != nil { + if err := rlp.DecodeBytes(entry.Data, &block); err == io.EOF { + log.Warn("empty entry from raft") + continue + } else if err != nil { log.Error("error decoding block: ", "err", err) continue } diff --git a/raft/wal.go b/raft/wal.go index 0665428e88..96f3ad86e4 100644 --- a/raft/wal.go +++ b/raft/wal.go @@ -47,11 +47,12 @@ func (pm *ProtocolManager) replayWAL(maybeRaftSnapshot *raftpb.Snapshot) (*wal.W fatalf("failed to read WAL: %s", err) } - // filter empty entries + // trim first empty entries newEntries := make([]raftpb.Entry, 0, len(entries)) for i := range entries { - if len(entries[i].Data) > 0 { - newEntries = append(newEntries, entries[i]) + if len(entries[i].Data) > 0 { // find 1st non empty entry, append everything from this entry + newEntries = append(newEntries, entries[i:]...) + break } }