Skip to content
Open
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
25 changes: 21 additions & 4 deletions instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,17 @@ func (i *Instance) Stop() {
i.stopNonValidator()
}

// closeWAL closes the WAL currently in use, if any.
// Must be called under the lock, and only once the epoch or non-validator using it has been stopped.
func (i *Instance) closeWAL() error {
if i.wal == nil {
return nil
}
err := i.wal.Close()
i.wal = nil
return err
}

func (i *Instance) stopNonValidator() {
if i.nv != nil {
i.nv.Stop()
Expand All @@ -266,6 +277,10 @@ func (i *Instance) stopValidator() {
i.e = nil
i.epochOrNV = nil
}

if err := i.closeWAL(); err != nil {
i.Config.Logger.Error("Error closing the WAL of the previous epoch", zap.Error(err))
}
}

func (i *Instance) HandleMessage(msg *common.Message, from common.NodeID) error {
Expand Down Expand Up @@ -573,15 +588,17 @@ func (i *Instance) transitionEpochValidator(epochChange epochChange) error {
i.lock.Lock()
defer i.lock.Unlock()

// Stop the epoch before doing anything else, so that we don't process any more messages while we are changing epochs.
i.stopValidator()
// Wipe out the WALs from the config so we won't try to load them again
i.Config.WALs = nil
// On epoch change, garbage collect the WAL to remove all entries from previous epochs.
if err := i.wal.GarbageCollect(math.MaxUint64); err != nil {
i.Config.Logger.Error("Error garbage collecting epoch config on epoch change", zap.Error(err))
}

// Stop the epoch before doing anything else, so that we don't process any more messages while we are changing epochs.
i.stopValidator()

// Wipe out the WALs from the config so we won't try to load them again

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, doesn't that effectively make us load an empty WAL next invocation of createEpochConfig ?

i.Config.WALs = nil

return i.startAtEpoch(epochChange.validators, epochChange.epochNum)
}

Expand Down
Loading