mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
tsdb: Replay m-map chunk only when required
M-map chunks replayed on startup are discarded if there was no WAL and no snapshot loaded, because there is no series created in the Head that it can map to. So only load m-map chunks from disk if there is either a snapshot loaded or there is WAL on disk. Signed-off-by: Ganesh Vernekar <ganeshvern@gmail.com>
This commit is contained in:
parent
6c008ec56a
commit
c9d06f2826
16
tsdb/head.go
16
tsdb/head.go
|
@ -590,6 +590,7 @@ func (h *Head) Init(minValidTime int64) error {
|
||||||
snapIdx, snapOffset := -1, 0
|
snapIdx, snapOffset := -1, 0
|
||||||
refSeries := make(map[chunks.HeadSeriesRef]*memSeries)
|
refSeries := make(map[chunks.HeadSeriesRef]*memSeries)
|
||||||
|
|
||||||
|
snapshotLoaded := false
|
||||||
if h.opts.EnableMemorySnapshotOnShutdown {
|
if h.opts.EnableMemorySnapshotOnShutdown {
|
||||||
level.Info(h.logger).Log("msg", "Chunk snapshot is enabled, replaying from the snapshot")
|
level.Info(h.logger).Log("msg", "Chunk snapshot is enabled, replaying from the snapshot")
|
||||||
// If there are any WAL files, there should be at least one WAL file with an index that is current or newer
|
// If there are any WAL files, there should be at least one WAL file with an index that is current or newer
|
||||||
|
@ -619,6 +620,7 @@ func (h *Head) Init(minValidTime int64) error {
|
||||||
var err error
|
var err error
|
||||||
snapIdx, snapOffset, refSeries, err = h.loadChunkSnapshot()
|
snapIdx, snapOffset, refSeries, err = h.loadChunkSnapshot()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
snapshotLoaded = true
|
||||||
level.Info(h.logger).Log("msg", "Chunk snapshot loading time", "duration", time.Since(start).String())
|
level.Info(h.logger).Log("msg", "Chunk snapshot loading time", "duration", time.Since(start).String())
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -636,7 +638,16 @@ func (h *Head) Init(minValidTime int64) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
mmapChunkReplayStart := time.Now()
|
mmapChunkReplayStart := time.Now()
|
||||||
mmappedChunks, oooMmappedChunks, lastMmapRef, err := h.loadMmappedChunks(refSeries)
|
var (
|
||||||
|
mmappedChunks map[chunks.HeadSeriesRef][]*mmappedChunk
|
||||||
|
oooMmappedChunks map[chunks.HeadSeriesRef][]*mmappedChunk
|
||||||
|
lastMmapRef chunks.ChunkDiskMapperRef
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
if snapshotLoaded || h.wal != nil {
|
||||||
|
// If snapshot was not loaded and if there is no WAL, then m-map chunks will be discarded
|
||||||
|
// anyway. So we only load m-map chunks when it won't be discarded.
|
||||||
|
mmappedChunks, oooMmappedChunks, lastMmapRef, err = h.loadMmappedChunks(refSeries)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// TODO(codesome): clear out all m-map chunks here for refSeries.
|
// TODO(codesome): clear out all m-map chunks here for refSeries.
|
||||||
level.Error(h.logger).Log("msg", "Loading on-disk chunks failed", "err", err)
|
level.Error(h.logger).Log("msg", "Loading on-disk chunks failed", "err", err)
|
||||||
|
@ -654,8 +665,9 @@ func (h *Head) Init(minValidTime int64) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
level.Info(h.logger).Log("msg", "On-disk memory mappable chunks replay completed", "duration", time.Since(mmapChunkReplayStart).String())
|
level.Info(h.logger).Log("msg", "On-disk memory mappable chunks replay completed", "duration", time.Since(mmapChunkReplayStart).String())
|
||||||
|
}
|
||||||
|
|
||||||
if h.wal == nil {
|
if h.wal == nil {
|
||||||
level.Info(h.logger).Log("msg", "WAL not found")
|
level.Info(h.logger).Log("msg", "WAL not found")
|
||||||
return nil
|
return nil
|
||||||
|
|
Loading…
Reference in a new issue