mirror of
https://github.com/prometheus/prometheus.git
synced 2025-01-11 13:57:36 -08:00
Reload after reading the WAL. (#460)
This causes the head to be GCed at startup, removing any series that were read from the WAL but have since been written to a block. In systems with low ingestion rates, this potentially could be many many hours of data. Signed-off-by: Brian Brazil <brian.brazil@robustperception.io>
This commit is contained in:
parent
407e12d051
commit
d50b9a5619
6
db.go
6
db.go
|
@ -271,12 +271,12 @@ func Open(dir string, l log.Logger, r prometheus.Registerer, opts *Options) (db
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if err := db.reload(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if err := db.head.Init(); err != nil {
|
if err := db.head.Init(); err != nil {
|
||||||
return nil, errors.Wrap(err, "read WAL")
|
return nil, errors.Wrap(err, "read WAL")
|
||||||
}
|
}
|
||||||
|
if err := db.reload(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
go db.run()
|
go db.run()
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,8 @@ import (
|
||||||
|
|
||||||
"github.com/oklog/ulid"
|
"github.com/oklog/ulid"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
prom_testutil "github.com/prometheus/client_golang/prometheus/testutil"
|
||||||
"github.com/prometheus/tsdb/chunks"
|
"github.com/prometheus/tsdb/chunks"
|
||||||
"github.com/prometheus/tsdb/index"
|
"github.com/prometheus/tsdb/index"
|
||||||
"github.com/prometheus/tsdb/labels"
|
"github.com/prometheus/tsdb/labels"
|
||||||
|
@ -1295,11 +1297,15 @@ func TestInitializeHeadTimestamp(t *testing.T) {
|
||||||
testutil.Ok(t, err)
|
testutil.Ok(t, err)
|
||||||
testutil.Ok(t, w.Close())
|
testutil.Ok(t, w.Close())
|
||||||
|
|
||||||
db, err := Open(dir, nil, nil, nil)
|
r := prometheus.NewRegistry()
|
||||||
|
|
||||||
|
db, err := Open(dir, nil, r, nil)
|
||||||
testutil.Ok(t, err)
|
testutil.Ok(t, err)
|
||||||
|
|
||||||
testutil.Equals(t, int64(6000), db.head.MinTime())
|
testutil.Equals(t, int64(6000), db.head.MinTime())
|
||||||
testutil.Equals(t, int64(15000), db.head.MaxTime())
|
testutil.Equals(t, int64(15000), db.head.MaxTime())
|
||||||
|
// Check that old series has been GCed.
|
||||||
|
testutil.Equals(t, 1.0, prom_testutil.ToFloat64(db.head.metrics.series))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue