Log when starting to create a checkpoint (#7581)

Signed-off-by: Ganesh Vernekar <cs15btech11018@iith.ac.in>
This commit is contained in:
Ganesh Vernekar 2020-07-15 19:15:37 +05:30 committed by GitHub
parent dc10763027
commit ea013343ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 14 additions and 8 deletions

View File

@ -1169,7 +1169,7 @@ func TestSizeRetention(t *testing.T) {
// Create a WAL checkpoint, and compare sizes.
first, last, err := db.Head().wal.Segments()
testutil.Ok(t, err)
_, err = wal.Checkpoint(db.Head().wal, first, last-1, func(x uint64) bool { return false }, 0)
_, err = wal.Checkpoint(log.NewNopLogger(), db.Head().wal, first, last-1, func(x uint64) bool { return false }, 0)
testutil.Ok(t, err)
blockSize = int64(prom_testutil.ToFloat64(db.metrics.blocksBytes)) // Use the actual internal metrics.
walSize, err = db.Head().wal.Size()

View File

@ -835,7 +835,7 @@ func (h *Head) Truncate(mint int64) (err error) {
return ok
}
h.metrics.checkpointCreationTotal.Inc()
if _, err = wal.Checkpoint(h.wal, first, last, keep, mint); err != nil {
if _, err = wal.Checkpoint(h.logger, h.wal, first, last, keep, mint); err != nil {
h.metrics.checkpointCreationFail.Inc()
if _, ok := errors.Cause(err).(*wal.CorruptionErr); ok {
h.metrics.walCorruptionsTotal.Inc()

View File

@ -25,6 +25,8 @@ import (
"strconv"
"strings"
"github.com/go-kit/kit/log"
"github.com/go-kit/kit/log/level"
"github.com/pkg/errors"
tsdb_errors "github.com/prometheus/prometheus/tsdb/errors"
"github.com/prometheus/prometheus/tsdb/fileutil"
@ -87,10 +89,12 @@ const checkpointPrefix = "checkpoint."
// segmented format as the original WAL itself.
// This makes it easy to read it through the WAL package and concatenate
// it with the original WAL.
func Checkpoint(w *WAL, from, to int, keep func(id uint64) bool, mint int64) (*CheckpointStats, error) {
func Checkpoint(logger log.Logger, w *WAL, from, to int, keep func(id uint64) bool, mint int64) (*CheckpointStats, error) {
stats := &CheckpointStats{}
var sgmReader io.ReadCloser
level.Info(logger).Log("msg", "Creating checkpoint", "from_segment", from, "to_segment", to, "mint", mint)
{
var sgmRange []SegmentRange

View File

@ -16,6 +16,7 @@ package wal
import (
"fmt"
"github.com/go-kit/kit/log"
"io/ioutil"
"os"
"path/filepath"
@ -177,7 +178,7 @@ func TestCheckpoint(t *testing.T) {
}
testutil.Ok(t, w.Close())
_, err = Checkpoint(w, 100, 106, func(x uint64) bool {
_, err = Checkpoint(log.NewNopLogger(), w, 100, 106, func(x uint64) bool {
return x%2 == 0
}, last/2)
testutil.Ok(t, err)
@ -236,7 +237,7 @@ func TestCheckpointNoTmpFolderAfterError(t *testing.T) {
w.Close()
// Run the checkpoint and since the wal contains an invalid records this should return an error.
_, err = Checkpoint(w, 0, 1, nil, 0)
_, err = Checkpoint(log.NewNopLogger(), w, 0, 1, nil, 0)
testutil.NotOk(t, err)
// Walk the wal dir to make sure there are no tmp folder left behind after the error.

View File

@ -14,6 +14,7 @@ package wal
import (
"fmt"
"github.com/go-kit/kit/log"
"io/ioutil"
"math/rand"
"os"
@ -275,7 +276,7 @@ func TestReadToEndWithCheckpoint(t *testing.T) {
}
}
Checkpoint(w, 0, 1, func(x uint64) bool { return true }, 0)
Checkpoint(log.NewNopLogger(), w, 0, 1, func(x uint64) bool { return true }, 0)
w.Truncate(1)
// Write more records after checkpointing.
@ -360,7 +361,7 @@ func TestReadCheckpoint(t *testing.T) {
testutil.Ok(t, w.Log(sample))
}
}
Checkpoint(w, 30, 31, func(x uint64) bool { return true }, 0)
Checkpoint(log.NewNopLogger(), w, 30, 31, func(x uint64) bool { return true }, 0)
w.Truncate(32)
// Start read after checkpoint, no more data written.
@ -520,7 +521,7 @@ func TestCheckpointSeriesReset(t *testing.T) {
})
testutil.Equals(t, seriesCount, wt.checkNumLabels())
_, err = Checkpoint(w, 2, 4, func(x uint64) bool { return true }, 0)
_, err = Checkpoint(log.NewNopLogger(), w, 2, 4, func(x uint64) bool { return true }, 0)
testutil.Ok(t, err)
err = w.Truncate(5)