Merge pull request #2385 from prometheus/beorn7/storage

Fix embarrassing bug of not setting the shrink ratio
This commit is contained in:
Björn Rabenstein 2017-02-01 16:58:56 +01:00 committed by GitHub
commit 7db4447390
2 changed files with 21 additions and 1 deletions

View file

@ -310,6 +310,7 @@ func newPersistence(
dirtyFileName: dirtyPath,
fLock: fLock,
shouldSync: shouldSync,
minShrinkRatio: minShrinkRatio,
// Create buffers of length 3*chunkLenWithHeader by default because that is still reasonably small
// and at the same time enough for many uses. The contract is to never return buffer smaller than
// that to the pool so that callers can rely on a minimum buffer size.

View file

@ -42,7 +42,7 @@ var (
func newTestPersistence(t *testing.T, encoding chunk.Encoding) (*persistence, testutil.Closer) {
chunk.DefaultEncoding = encoding
dir := testutil.NewTemporaryDirectory("test_persistence", t)
p, err := newPersistence(dir.Path(), false, false, func() bool { return false }, 0.1)
p, err := newPersistence(dir.Path(), false, false, func() bool { return false }, 0.15)
if err != nil {
dir.Close()
t.Fatal(err)
@ -173,6 +173,25 @@ func testPersistLoadDropChunks(t *testing.T, encoding chunk.Encoding) {
}
}
// Try to drop one chunk, which must be prevented by the shrink ratio.
for fp, _ := range fpToChunks {
firstTime, offset, numDropped, allDropped, err := p.dropAndPersistChunks(fp, 1, nil)
if err != nil {
t.Fatal(err)
}
if offset != 0 {
t.Errorf("want offset 0, got %d", offset)
}
if firstTime != 0 {
t.Errorf("want first time 0, got %d", firstTime)
}
if numDropped != 0 {
t.Errorf("want 0 dropped chunks, got %v", numDropped)
}
if allDropped {
t.Error("all chunks dropped")
}
}
// Drop half of the chunks.
for fp, expectedChunks := range fpToChunks {
firstTime, offset, numDropped, allDropped, err := p.dropAndPersistChunks(fp, 5, nil)