From 3f538817f80230a4dbeeba2b2170125e1cd8899d Mon Sep 17 00:00:00 2001 From: Fabian Reinartz Date: Tue, 29 May 2018 11:46:06 -0400 Subject: [PATCH] move WAL lock Signed-off-by: Fabian Reinartz --- wal/wal.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/wal/wal.go b/wal/wal.go index 4ba3aec4d..89369195b 100644 --- a/wal/wal.go +++ b/wal/wal.go @@ -429,6 +429,8 @@ func (w *WAL) pagesPerSegment() int { // Log writes the records into the log. // Multiple records can be passed at once to reduce writes and increase throughput. func (w *WAL) Log(recs ...[]byte) error { + w.mtx.Lock() + defer w.mtx.Unlock() // Callers could just implement their own list record format but adding // a bit of extra logic here frees them from that overhead. for i, r := range recs { @@ -442,9 +444,6 @@ func (w *WAL) Log(recs ...[]byte) error { // log writes rec to the log and forces a flush of the current page if its // the final record of a batch. func (w *WAL) log(rec []byte, final bool) error { - w.mtx.Lock() - defer w.mtx.Unlock() - // If the record is too big to fit within pages in the current // segment, terminate the active segment and advance to the next one. // This ensures that records do not cross segment boundaries.