mirror of
https://github.com/prometheus/prometheus.git
synced 2025-01-12 14:27:27 -08:00
Add Head.compactable method (#542)
* Add Head.compactable method Signed-off-by: zhulongcheng <zhulongcheng.me@gmail.com>
This commit is contained in:
parent
fd188be052
commit
aed16621c0
8
db.go
8
db.go
|
@ -391,7 +391,7 @@ func (a dbAppender) Commit() error {
|
||||||
|
|
||||||
// We could just run this check every few minutes practically. But for benchmarks
|
// We could just run this check every few minutes practically. But for benchmarks
|
||||||
// and high frequency use cases this is the safer way.
|
// and high frequency use cases this is the safer way.
|
||||||
if a.db.head.MaxTime()-a.db.head.MinTime() > a.db.head.chunkRange/2*3 {
|
if a.db.head.compactable() {
|
||||||
select {
|
select {
|
||||||
case a.db.compactc <- struct{}{}:
|
case a.db.compactc <- struct{}{}:
|
||||||
default:
|
default:
|
||||||
|
@ -418,13 +418,11 @@ func (db *DB) compact() (err error) {
|
||||||
return nil
|
return nil
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
// The head has a compactable range if 1.5 level 0 ranges are between the oldest
|
if !db.head.compactable() {
|
||||||
// and newest timestamp. The 0.5 acts as a buffer of the appendable window.
|
|
||||||
if db.head.MaxTime()-db.head.MinTime() <= db.opts.BlockRanges[0]/2*3 {
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
mint := db.head.MinTime()
|
mint := db.head.MinTime()
|
||||||
maxt := rangeForTimestamp(mint, db.opts.BlockRanges[0])
|
maxt := rangeForTimestamp(mint, db.head.chunkRange)
|
||||||
|
|
||||||
// Wrap head into a range that bounds all reads to it.
|
// Wrap head into a range that bounds all reads to it.
|
||||||
head := &rangeHead{
|
head := &rangeHead{
|
||||||
|
|
7
head.go
7
head.go
|
@ -1020,6 +1020,13 @@ func (h *Head) MaxTime() int64 {
|
||||||
return atomic.LoadInt64(&h.maxTime)
|
return atomic.LoadInt64(&h.maxTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// compactable returns whether the head has a compactable range.
|
||||||
|
// The head has a compactable range when the head time range is 1.5 times the chunk range.
|
||||||
|
// The 0.5 acts as a buffer of the appendable window.
|
||||||
|
func (h *Head) compactable() bool {
|
||||||
|
return h.MaxTime()-h.MinTime() > h.chunkRange/2*3
|
||||||
|
}
|
||||||
|
|
||||||
// Close flushes the WAL and closes the head.
|
// Close flushes the WAL and closes the head.
|
||||||
func (h *Head) Close() error {
|
func (h *Head) Close() error {
|
||||||
if h.wal == nil {
|
if h.wal == nil {
|
||||||
|
|
Loading…
Reference in a new issue