Skip to content

SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.

fix(log_buffer): re-check buffer before bailing with ResumeFromDiskError (#9804)

Chris Luf711868fb618
diff --git a/weed/util/log_buffer/log_read.go b/weed/util/log_buffer/log_read.go
index d62eea428d..364047f74f 100644
--- a/weed/util/log_buffer/log_read.go
+++ b/weed/util/log_buffer/log_read.go
@@ -147,7 +147,17 @@ func (logBuffer *LogBuffer) LoopProcessLogData(readerName string, startPosition
glog.V(4).Infof("%s: Caught up to disk head, backing off to %s poll", readerName, caughtUpDiskPollInterval)
}
} else if logBuffer.HasData() {
- return lastReadPosition, isDone, ResumeFromDiskError
+ // HasData() and ReadFromBuffer lock separately, so a racing write can make
+ // HasData() see data the empty-buffer read missed. Re-read; only bail if the
+ // position is genuinely behind the in-memory window (flushed to disk).
+ reBuf, _, reErr := logBuffer.ReadFromBuffer(lastReadPosition)
+ if reErr == ResumeFromDiskError {
+ return lastReadPosition, isDone, ResumeFromDiskError
+ }
+ if reBuf != nil {
+ logBuffer.ReleaseMemory(reBuf)
+ }
+ continue
}
// CRITICAL: Check if client is still connected
@@ -362,7 +372,17 @@ func (logBuffer *LogBuffer) LoopProcessLogDataWithOffset(readerName string, star
glog.V(4).Infof("%s: Caught up to disk head, backing off to %s poll", readerName, caughtUpDiskPollInterval)
}
} else if logBuffer.HasData() {
- return lastReadPosition, isDone, ResumeFromDiskError
+ // HasData() and ReadFromBuffer lock separately, so a racing write can make
+ // HasData() see data the empty-buffer read missed. Re-read; only bail if the
+ // position is genuinely behind the in-memory window (flushed to disk).
+ reBuf, _, reErr := logBuffer.ReadFromBuffer(lastReadPosition)
+ if reErr == ResumeFromDiskError {
+ return lastReadPosition, isDone, ResumeFromDiskError
+ }
+ if reBuf != nil {
+ logBuffer.ReleaseMemory(reBuf)
+ }
+ continue
}
// CRITICAL: Check if client is still connected after disk read