mirror of
https://github.com/prometheus/prometheus
synced 2024-12-29 18:22:16 +00:00
Merge pull request #160 from dim/fix/snapshot-test
Restore snapshot functionality
This commit is contained in:
commit
4a7c39d9d8
42
db_test.go
42
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
|
||||
|
3
head.go
3
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
|
||||
}
|
||||
|
@ -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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user