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

Restrict WAL usage to node.go (backport #4201) #4267

Merged
merged 1 commit into from
Jun 7, 2023
Merged
Show file tree
Hide file tree
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
4 changes: 1 addition & 3 deletions orderer/consensus/etcdraft/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -1149,10 +1149,8 @@ func (c *Chain) apply(ents []raftpb.Entry) {
continue
}

// persist the WAL entries into disk
c.Node.storage.WALSyncC <- struct{}{}

c.confState = *c.Node.ApplyConfChange(cc)

switch cc.Type {
case raftpb.ConfChangeAddNode:
c.logger.Infof("Applied config change to add node %d, current nodes in channel: %+v", cc.NodeID, c.confState.Voters)
Expand Down
24 changes: 19 additions & 5 deletions orderer/consensus/etcdraft/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ func (n *node) run(campaign bool) {

// skip empty apply
if len(rd.CommittedEntries) != 0 || rd.SoftState != nil {
n.maybeSyncWAL(rd.CommittedEntries)
n.chain.applyC <- apply{rd.CommittedEntries, rd.SoftState}
}

Expand All @@ -171,11 +172,6 @@ func (n *node) run(campaign bool) {
// to the followers and them writing to their disks. Check 10.2.1 in thesis
n.send(rd.Messages)

case <-n.storage.WALSyncC:
if err := n.storage.Sync(); err != nil {
n.logger.Warnf("Failed to sync raft log, error: %s", err)
}

case <-n.chain.haltC:
raftTicker.Stop()
n.Stop()
Expand Down Expand Up @@ -224,6 +220,24 @@ func (n *node) send(msgs []raftpb.Message) {
}
}

func (n *node) maybeSyncWAL(entries []raftpb.Entry) {
allNormal := true
for _, entry := range entries {
if entry.Type == raftpb.EntryNormal {
continue
}
allNormal = false
}

if allNormal {
return
}

if err := n.storage.Sync(); err != nil {
n.logger.Errorf("Failed to sync raft log, error: %s", err)
}
}

// abdicateLeadership picks a node that is recently active, and attempts to transfer leadership to it.
// Blocks until leadership transfer happens or when a timeout expires.
// Returns error upon failure.
Expand Down
2 changes: 0 additions & 2 deletions orderer/consensus/etcdraft/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ type RaftStorage struct {

// a queue that keeps track of indices of snapshots on disk
snapshotIndex []uint64
WALSyncC chan struct{}
}

// CreateStorage attempts to create a storage to persist etcd/raft data.
Expand Down Expand Up @@ -114,7 +113,6 @@ func CreateStorage(
walDir: walDir,
snapDir: snapDir,
snapshotIndex: ListSnapshots(lg, snapDir),
WALSyncC: make(chan struct{}),
}, nil
}

Expand Down