Skip to content

Commit

Permalink
Take snapshot only after closing the WAL (prometheus#9328)
Browse files Browse the repository at this point in the history
Signed-off-by: Ganesh Vernekar <[email protected]>
  • Loading branch information
codesome authored Sep 13, 2021
1 parent 05a816b commit 30534e9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 3 additions & 3 deletions tsdb/head.go
Original file line number Diff line number Diff line change
Expand Up @@ -1168,12 +1168,12 @@ func (h *Head) Close() error {
defer h.closedMtx.Unlock()
h.closed = true
errs := tsdb_errors.NewMulti(h.chunkDiskMapper.Close())
if errs.Err() == nil && h.opts.EnableMemorySnapshotOnShutdown {
errs.Add(h.performChunkSnapshot())
}
if h.wal != nil {
errs.Add(h.wal.Close())
}
if errs.Err() == nil && h.opts.EnableMemorySnapshotOnShutdown {
errs.Add(h.performChunkSnapshot())
}
return errs.Err()

}
Expand Down
8 changes: 8 additions & 0 deletions tsdb/head_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2659,6 +2659,10 @@ func TestChunkSnapshot(t *testing.T) {
// These references should be the ones used for the snapshot.
wlast, woffset, err = head.wal.LastSegmentAndOffset()
require.NoError(t, err)
if woffset != 0 && woffset < 32*1024 {
// The page is always filled before taking the snapshot.
woffset = 32 * 1024
}

{
// Creating snapshot and verifying it.
Expand Down Expand Up @@ -2725,6 +2729,10 @@ func TestChunkSnapshot(t *testing.T) {
// Creating another snapshot should delete the older snapshot and replay still works fine.
wlast, woffset, err = head.wal.LastSegmentAndOffset()
require.NoError(t, err)
if woffset != 0 && woffset < 32*1024 {
// The page is always filled before taking the snapshot.
woffset = 32 * 1024
}

{
// Close Head and verify that new snapshot was created.
Expand Down

0 comments on commit 30534e9

Please sign in to comment.