Skip to content
Open
Changes from 1 commit
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
20 changes: 20 additions & 0 deletions instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,18 @@ func (i *Instance) Stop() {

i.stopValidator()
i.stopNonValidator()
if err := i.closeWAL(); err != nil {
i.Config.Logger.Error("Error closing WAL on shutdown", zap.Error(err))
}
}

// 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
}
return i.wal.Close()
Comment thread
samliok marked this conversation as resolved.
Outdated
}

func (i *Instance) stopNonValidator() {
Expand Down Expand Up @@ -429,6 +441,14 @@ func (i *Instance) createEpochConfig() (simplex.EpochConfig, error) {
return simplex.EpochConfig{}, err
}

// The epoch that used the previous WAL has already been stopped by now,
// so close it before replacing it, otherwise we leak the files it holds open.
// Failing to close it doesn't prevent the new epoch from running, so as with
// garbage collecting the WAL on an epoch change, we only log the error.
Comment thread
samliok marked this conversation as resolved.
Outdated
if err := i.closeWAL(); err != nil {
i.Config.Logger.Error("Error closing the WAL of the previous epoch", zap.Error(err))
}

wal, err := wal.NewGarbageCollectedWAL(i.Config.WALs, i.Config.WalCreator, &common.WALRetentionReader{}, i.Config.ParameterConfig.WALMaxEntryCount)
if err != nil {
return simplex.EpochConfig{}, fmt.Errorf("error creating garbage collected wal: %w", err)
Expand Down
Loading