Skip to content
This repository was archived by the owner on Jun 23, 2025. It is now read-only.
Merged
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
12 changes: 4 additions & 8 deletions internal/wal/wal_forge.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,8 @@ func (wl *walForge) rotateLogIfNeeded(entrySize uint32) error {

// rotateLog rotates the log by closing the current segment file,
// incrementing the current segment index, and opening a new segment file.
// This method is thread safe.
func (wl *walForge) rotateLog() error {
fmt.Println("rotating log")
wl.mu.Lock()
defer wl.mu.Unlock()

// TODO: Ideally this function should not return any error
// Check for the conditions where it can return an error
// and handle them gracefully.
Expand Down Expand Up @@ -237,11 +233,7 @@ func (wl *walForge) rotateLog() error {

// Writes out any data in the WAL's in-memory buffer to the segment file.
// and syncs the segment file to disk.
// This method is thread safe.
func (wl *walForge) sync() error {
wl.mu.Lock()
defer wl.mu.Unlock()

// Flush the buffer to the segment file
if err := wl.csWriter.Flush(); err != nil {
return err
Expand All @@ -265,10 +257,12 @@ func (wl *walForge) periodicSyncBuffer() {
for {
select {
case <-wl.bufferSyncTicker.C:
wl.mu.Lock()
err := wl.sync()
if err != nil {
slog.Error("failed to sync buffer", slog.String("error", err.Error()))
}
wl.mu.Unlock()
case <-wl.ctx.Done():
return
}
Expand All @@ -281,9 +275,11 @@ func (wl *walForge) periodicRotateSegment() {
select {
case <-wl.segmentRotationTicker.C:
// TODO: Remove this error handling once we clean up the error handling in the rotateLog function.
wl.mu.Lock()
if err := wl.rotateLog(); err != nil {
slog.Error("failed to rotate segment", slog.String("error", err.Error()))
}
wl.mu.Unlock()
case <-wl.ctx.Done():
return
}
Expand Down