Skip to content

Commit

Permalink
Set wasRetrievedFromDisk properly (#1156)
Browse files Browse the repository at this point in the history
* Set wasRetrievedFromDisk properly

* Add unit test
  • Loading branch information
justinjc authored Nov 7, 2018
1 parent 0fd715a commit 95dbe5a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/dbnode/storage/block/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ func (b *dbBlock) ResetFromDisk(start time.Time, blockSize time.Duration, segmen
// resetSegmentWithLock sets seriesID to nil
b.resetSegmentWithLock(segment)
b.seriesID = id
b.wasRetrievedFromDisk = true
}

func (b *dbBlock) streamWithRLock(ctx context.Context) (xio.BlockReader, error) {
Expand Down
19 changes: 19 additions & 0 deletions src/dbnode/storage/block/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/m3db/m3/src/dbnode/ts"
"github.com/m3db/m3/src/dbnode/x/xio"
"github.com/m3db/m3x/context"
"github.com/m3db/m3x/ident"
xtime "github.com/m3db/m3x/time"

"github.com/golang/mock/gomock"
Expand Down Expand Up @@ -678,3 +679,21 @@ func TestDatabaseSeriesBlocksReset(t *testing.T) {
require.True(t, blocks.min.Equal(time.Time{}))
require.True(t, blocks.max.Equal(time.Time{}))
}

func TestBlockResetFromDisk(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

bl := testDatabaseBlock(ctrl)
now := time.Now()
blockSize := 2 * time.Hour
id := ident.StringID("testID")
segment := ts.Segment{}
bl.ResetFromDisk(now, blockSize, segment, id)

assert.True(t, now.Equal(bl.StartTime()))
assert.Equal(t, blockSize, bl.BlockSize())
assert.Equal(t, segment, bl.segment)
assert.Equal(t, id, bl.seriesID)
assert.True(t, bl.WasRetrievedFromDisk())
}

0 comments on commit 95dbe5a

Please sign in to comment.