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

Remove unncessary locking in encoder #14877

Closed
wants to merge 2 commits into from
Closed
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
7 changes: 0 additions & 7 deletions server/storage/wal/encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"hash"
"io"
"os"
"sync"

"go.etcd.io/etcd/pkg/v3/crc"
"go.etcd.io/etcd/pkg/v3/ioutil"
Expand All @@ -32,7 +31,6 @@ import (
const walPageBytes = 8 * minSectorSize

type encoder struct {
mu sync.Mutex
bw *ioutil.PageWriter

crc hash.Hash32
Expand Down Expand Up @@ -60,9 +58,6 @@ func newFileEncoder(f *os.File, prevCrc uint32) (*encoder, error) {
}

func (e *encoder) encode(rec *walpb.Record) error {
e.mu.Lock()
defer e.mu.Unlock()

e.crc.Write(rec.Data)
rec.Crc = e.crc.Sum32()
var (
Expand Down Expand Up @@ -108,8 +103,6 @@ func encodeFrameSize(dataBytes int) (lenField uint64, padBytes int) {
}

func (e *encoder) flush() error {
e.mu.Lock()
defer e.mu.Unlock()
return e.bw.Flush()
}

Expand Down
3 changes: 3 additions & 0 deletions server/storage/wal/wal.go
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,9 @@ func (w *WAL) sync() error {
}

func (w *WAL) Sync() error {
w.mu.Lock()
defer w.mu.Unlock()

return w.sync()
}

Expand Down