Skip to content
This repository was archived by the owner on Jun 23, 2025. It is now read-only.

Commit 3415b9f

Browse files
addressing deadlocks in wal
1 parent 565613d commit 3415b9f

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

internal/wal/wal_forge.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -192,12 +192,8 @@ func (wl *walForge) rotateLogIfNeeded(entrySize uint32) error {
192192

193193
// rotateLog rotates the log by closing the current segment file,
194194
// incrementing the current segment index, and opening a new segment file.
195-
// This method is thread safe.
196195
func (wl *walForge) rotateLog() error {
197196
fmt.Println("rotating log")
198-
wl.mu.Lock()
199-
defer wl.mu.Unlock()
200-
201197
// TODO: Ideally this function should not return any error
202198
// Check for the conditions where it can return an error
203199
// and handle them gracefully.
@@ -237,11 +233,7 @@ func (wl *walForge) rotateLog() error {
237233

238234
// Writes out any data in the WAL's in-memory buffer to the segment file.
239235
// and syncs the segment file to disk.
240-
// This method is thread safe.
241236
func (wl *walForge) sync() error {
242-
wl.mu.Lock()
243-
defer wl.mu.Unlock()
244-
245237
// Flush the buffer to the segment file
246238
if err := wl.csWriter.Flush(); err != nil {
247239
return err
@@ -262,6 +254,8 @@ func (wl *walForge) sync() error {
262254
}
263255

264256
func (wl *walForge) periodicSyncBuffer() {
257+
wl.mu.Lock()
258+
defer wl.mu.Unlock()
265259
for {
266260
select {
267261
case <-wl.bufferSyncTicker.C:
@@ -277,6 +271,8 @@ func (wl *walForge) periodicSyncBuffer() {
277271

278272
func (wl *walForge) periodicRotateSegment() {
279273
fmt.Println("rotating segment")
274+
wl.mu.Lock()
275+
defer wl.mu.Unlock()
280276
for {
281277
select {
282278
case <-wl.segmentRotationTicker.C:

0 commit comments

Comments
 (0)