mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-24 21:24:05 -08:00
enhancement: 1. don't flush the page if it's last fragment of the record
2. if it's last record of the bacth, flush the page after it written into the page Signed-off-by: YaoZengzeng <yaozengzeng@zju.edu.cn>
This commit is contained in:
parent
45ee02add5
commit
104566ae53
16
wal/wal.go
16
wal/wal.go
|
@ -615,17 +615,21 @@ func (w *WAL) log(rec []byte, final bool) error {
|
||||||
copy(buf[recordHeaderSize:], part)
|
copy(buf[recordHeaderSize:], part)
|
||||||
p.alloc += len(part) + recordHeaderSize
|
p.alloc += len(part) + recordHeaderSize
|
||||||
|
|
||||||
// By definition when a record is split it means its size is bigger than
|
if w.page.full() {
|
||||||
// the page boundary so the current page would be full and needs to be flushed.
|
if err := w.flushPage(true); err != nil {
|
||||||
// On contrary if we wrote a full record, we can fit more records of the batch
|
|
||||||
// into the page before flushing it.
|
|
||||||
if final || typ != recFull || w.page.full() {
|
|
||||||
if err := w.flushPage(false); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rec = rec[l:]
|
rec = rec[l:]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If it's the final record of the batch and the page is not empty, flush it.
|
||||||
|
if final && w.page.alloc > 0 {
|
||||||
|
if err := w.flushPage(false); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue