mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-06 02:57:37 +01:00
The broker and the Kafka gateway each scanned a partition's files for the high water mark and counted a maximum only when it was above 0, so a partition holding one message still read as empty. Both now share mq.OffsetRange, which tracks whether a range was found apart from its value.
35 lines
940 B
Go
35 lines
940 B
Go
package mq
|
|
|
|
import "encoding/binary"
|
|
|
|
// OffsetRange accumulates the offset ranges recorded on a partition's files.
|
|
type OffsetRange struct {
|
|
earliest, latest int64
|
|
hasEarliest, hasLatest bool
|
|
}
|
|
|
|
func (r *OffsetRange) Add(extended map[string][]byte) {
|
|
if b, ok := extended[ExtendedAttrOffsetMin]; ok && len(b) == 8 {
|
|
if v := int64(binary.BigEndian.Uint64(b)); !r.hasEarliest || v < r.earliest {
|
|
r.earliest, r.hasEarliest = v, true
|
|
}
|
|
}
|
|
if b, ok := extended[ExtendedAttrOffsetMax]; ok && len(b) == 8 {
|
|
if v := int64(binary.BigEndian.Uint64(b)); !r.hasLatest || v > r.latest {
|
|
r.latest, r.hasLatest = v, true
|
|
}
|
|
}
|
|
}
|
|
|
|
// Bounds is the earliest recorded offset and the offset after the latest,
|
|
// both 0 when no file records a range.
|
|
func (r *OffsetRange) Bounds() (earliestOffset, highWaterMark int64) {
|
|
if r.hasEarliest {
|
|
earliestOffset = r.earliest
|
|
}
|
|
if r.hasLatest {
|
|
highWaterMark = r.latest + 1
|
|
}
|
|
return
|
|
}
|