Skip to content
Open
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
15 changes: 12 additions & 3 deletions internal/bft/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -983,14 +983,23 @@ func (c *Controller) sync() (viewNum uint64, seq uint64, decisions uint64, carri
// A sync that brings a reconfiguration closed the controller, which restarts in the node's view (see run), so the
// sync doesn't save a new view.
saveNewView := !syncResponse.Reconfig.InReplicatedDecisions && response != nil && response.View > newViewNum && response.Seq == latestDecisionSeq+1
if saveNewView {
c.viewTransitionLock.Lock()
// Like changeView, sync doesn't move to a view the node left (see minStartView), whose record would also hide
// the view change record from a restart.
if response.View < c.minStartView {
c.viewTransitionLock.Unlock()
c.Logger.Infof("Node %d collected state with view %d, which it left, so it doesn't move to it", c.ID, response.View)
saveNewView = false
}
}
if saveNewView {
c.Logger.Infof("Node %d collected state with view %d and sequence %d", c.ID, response.View, response.Seq)

// The record of the new view replaces the state of the current view, so the
// view has to be stopped first, and no other view may start until the record
// is written. Otherwise a view could append a commit after that record and
// leave a sequence that recovery rejects.
c.viewTransitionLock.Lock()
// is written (viewTransitionLock is held). Otherwise a view could append a
// commit after that record and leave a sequence that recovery rejects.
c.abortCurrentView()

// The fate of the in-flight proposal has to be decided before the record of the
Expand Down
19 changes: 19 additions & 0 deletions internal/bft/controller_sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,25 @@ func TestSyncAbortsViewBeforeSavingNewView(t *testing.T) {
require.Equal(t, []bool{false}, fixture.state.TruncateTo)
}

// TestSyncDoesNotMoveToALeftView makes sure that a sync that collects the state of a view the node left, since it sent
// its view data for a later one, neither stops the current view nor saves a record of the left view.
func TestSyncDoesNotMoveToALeftView(t *testing.T) {
// the node is in view 5 after sequence 10, and the others are in view 6 at sequence 11
fixture := newSyncFixture(t, 10, 5, 10, 5)
running := &View{Number: 5, abortChan: make(chan struct{})}
fixture.controller.currView = running
fixture.controller.LeaveViewsBelow(7) // the node left views 5 and 6, and sent its view data for view 7

view, seq, _, carried := fixture.controller.sync()
require.Equal(t, uint64(5), view, "the sync moved the node to a view it left")
require.Equal(t, uint64(11), seq)
require.Nil(t, carried)
require.False(t, running.Stopped(), "the sync stopped the current view")
for _, saved := range fixture.state.SavedMessages {
require.Nil(t, saved.GetNewView(), "the sync saved a record of a view the node left")
}
}

// TestSyncHoldsViewTransitionLockUntilTheNewViewIsSaved covers the read side
// of the record ordering: while sync() is between the abort and the new view
// record, changeView must not start another view.
Expand Down