Skip to content

Commit

Permalink
trim first empty entries, EOF error is a warning
Browse files Browse the repository at this point in the history
  • Loading branch information
baptiste-b-pegasys committed May 3, 2022
1 parent bc0552f commit fbddfc5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
6 changes: 5 additions & 1 deletion raft/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"io"
"net"
"net/http"
"net/url"
Expand Down Expand Up @@ -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
}
Expand Down
7 changes: 4 additions & 3 deletions raft/wal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down

0 comments on commit fbddfc5

Please sign in to comment.