From c9fc2af6c00d7e00ef7d16815654d3cdcc9961af Mon Sep 17 00:00:00 2001 From: Dimitrij Denissenko Date: Tue, 3 Oct 2017 13:06:26 +0100 Subject: [PATCH 1/2] Add test for snapshot --- db_test.go | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/db_test.go b/db_test.go index 8f5ad543a..30ecf26f3 100644 --- a/db_test.go +++ b/db_test.go @@ -312,6 +312,48 @@ func TestSkippingInvalidValuesInSameTxn(t *testing.T) { require.NoError(t, q.Close()) } +func TestDB_Snapshot(t *testing.T) { + db, close := openTestDB(t, nil) + defer close() + + // append data + app := db.Appender() + mint := int64(1414141414000) + for i := 0; i < 1000; i++ { + _, err := app.Add(labels.FromStrings("foo", "bar"), mint+int64(i), 1.0) + require.NoError(t, err) + } + require.NoError(t, app.Commit()) + require.NoError(t, app.Rollback()) + + // create snapshot + snap, err := ioutil.TempDir("", "snap") + require.NoError(t, err) + require.NoError(t, db.Snapshot(snap)) + require.NoError(t, db.Close()) + + // reopen DB from snapshot + db, err = Open(snap, nil, nil, nil) + require.NoError(t, err) + + querier := db.Querier(mint, mint+1000) + defer querier.Close() + + // sum values + seriesSet := querier.Select(labels.NewEqualMatcher("foo", "bar")) + sum := 0.0 + for seriesSet.Next() { + series := seriesSet.At().Iterator() + for series.Next() { + _, v := series.At() + sum += v + } + require.NoError(t, series.Err()) + } + require.NoError(t, seriesSet.Err()) + require.Equal(t, sum, 1000.0) +} + func TestDB_e2e(t *testing.T) { const ( numDatapoints = 1000 From 203012169adc56dd43986f74d1979f45f9bffbcd Mon Sep 17 00:00:00 2001 From: Goutham Veeramachaneni Date: Wed, 4 Oct 2017 16:58:07 +0530 Subject: [PATCH 2/2] snapshot: Remove truncation check to restore func. Signed-off-by: Goutham Veeramachaneni --- head.go | 3 --- head_test.go | 4 ++-- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/head.go b/head.go index 00f51e007..82a3459bd 100644 --- a/head.go +++ b/head.go @@ -249,9 +249,6 @@ func (h *Head) ReadWAL() error { func (h *Head) Truncate(mint int64) error { initialize := h.MinTime() == math.MinInt64 - if mint%h.chunkRange != 0 { - return errors.Errorf("truncating at %d not aligned", mint) - } if h.MinTime() >= mint { return nil } diff --git a/head_test.go b/head_test.go index b7603e78e..31713b9c1 100644 --- a/head_test.go +++ b/head_test.go @@ -187,8 +187,8 @@ func TestHead_Truncate(t *testing.T) { } s4.chunks = []*memChunk{} - // Truncation must be aligned. - require.Error(t, h.Truncate(1)) + // Truncation need not be aligned. + require.NoError(t, h.Truncate(1)) h.Truncate(2000)