Skip to content

Commit

Permalink
ensure wal lock invariant in create
Browse files Browse the repository at this point in the history
add the lock for the sake for keeping the invariant during the creation.

Signed-off-by: Thomas Jungblut <[email protected]>
  • Loading branch information
tjungblu committed Dec 5, 2022
1 parent 5ff9052 commit 6927ebd
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions server/storage/wal/wal.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ func Create(lg *zap.Logger, dirpath string, metadata []byte) (*WAL, error) {
dir: dirpath,
metadata: metadata,
}

// this is actually not necessary, as w is not leaving the scope of this function yet.
w.mu.Lock()
defer w.mu.Unlock()

w.encoder, err = newFileEncoder(f.File, 0)
if err != nil {
return nil, err
Expand Down

0 comments on commit 6927ebd

Please sign in to comment.