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. // Create a WAL checkpoint, and compare sizes.
first, last, err := db.Head().wal.Segments() first, last, err := db.Head().wal.Segments()
testutil.Ok(t, err) 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) testutil.Ok(t, err)
blockSize = int64(prom_testutil.ToFloat64(db.metrics.blocksBytes)) // Use the actual internal metrics. blockSize = int64(prom_testutil.ToFloat64(db.metrics.blocksBytes)) // Use the actual internal metrics.
walSize, err = db.Head().wal.Size() walSize, err = db.Head().wal.Size()

View File

@ -835,7 +835,7 @@ func (h *Head) Truncate(mint int64) (err error) {
return ok return ok
} }
h.metrics.checkpointCreationTotal.Inc() 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() h.metrics.checkpointCreationFail.Inc()
if _, ok := errors.Cause(err).(*wal.CorruptionErr); ok { if _, ok := errors.Cause(err).(*wal.CorruptionErr); ok {
h.metrics.walCorruptionsTotal.Inc() h.metrics.walCorruptionsTotal.Inc()

View File

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

View File

@ -16,6 +16,7 @@ package wal
import ( import (
"fmt" "fmt"
"github.com/go-kit/kit/log"
"io/ioutil" "io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
@ -177,7 +178,7 @@ func TestCheckpoint(t *testing.T) {
} }
testutil.Ok(t, w.Close()) 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 return x%2 == 0
}, last/2) }, last/2)
testutil.Ok(t, err) testutil.Ok(t, err)
@ -236,7 +237,7 @@ func TestCheckpointNoTmpFolderAfterError(t *testing.T) {
w.Close() w.Close()
// Run the checkpoint and since the wal contains an invalid records this should return an error. // 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) testutil.NotOk(t, err)
// Walk the wal dir to make sure there are no tmp folder left behind after the error. // 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 ( import (
"fmt" "fmt"
"github.com/go-kit/kit/log"
"io/ioutil" "io/ioutil"
"math/rand" "math/rand"
"os" "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) w.Truncate(1)
// Write more records after checkpointing. // Write more records after checkpointing.
@ -360,7 +361,7 @@ func TestReadCheckpoint(t *testing.T) {
testutil.Ok(t, w.Log(sample)) 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) w.Truncate(32)
// Start read after checkpoint, no more data written. // Start read after checkpoint, no more data written.
@ -520,7 +521,7 @@ func TestCheckpointSeriesReset(t *testing.T) {
}) })
testutil.Equals(t, seriesCount, wt.checkNumLabels()) 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) testutil.Ok(t, err)
err = w.Truncate(5) err = w.Truncate(5)