Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dbnode] Refactoring dbShard #2848

Merged
merged 20 commits into from
Nov 12, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/dbnode/storage/shard.go
Original file line number Diff line number Diff line change
Expand Up @@ -2676,7 +2676,9 @@ func (s *dbShard) AggregateTiles(
openBlockReaders := make([]fs.DataFileSetReader, 0, len(blockReaders))
defer func() {
for _, reader := range openBlockReaders {
_ = reader.Close()
if err := reader.Close(); err != nil {
s.logger.Error("error closing DataFileSetReader", zap.Error(err))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: typically no error in go error returns, change to something like "could not close DataFileSetReader"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

}
}
}()

Expand Down Expand Up @@ -2737,6 +2739,7 @@ func (s *dbShard) AggregateTiles(
processedTileCount, err := s.tileAggregator.AggregateTiles(
opts, targetNs, s.ID(), openBlockReaders, writer)
if err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: add a comment here that we still need to do cleanup etc and should log any errors from that

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

// NB: cannot return on the error here, must finish writing.
multiErr = multiErr.Add(err)
}

Expand Down
35 changes: 21 additions & 14 deletions src/dbnode/storage/shard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,8 @@ func TestShardBootstrapWithFlushVersionNoCleanUp(t *testing.T) {
defer ctrl.Finish()

var (
opts = DefaultTestOptions()
fsOpts = opts.CommitLogOptions().FilesystemOptions().SetFilePathPrefix(dir)
opts = DefaultTestOptions()
fsOpts = opts.CommitLogOptions().FilesystemOptions().SetFilePathPrefix(dir)
newClOpts = opts.CommitLogOptions().SetFilesystemOptions(fsOpts)
)
opts = opts.
Expand Down Expand Up @@ -325,9 +325,9 @@ func TestShardBootstrapWithCacheShardIndices(t *testing.T) {
defer ctrl.Finish()

var (
opts = DefaultTestOptions()
fsOpts = opts.CommitLogOptions().FilesystemOptions().SetFilePathPrefix(dir)
newClOpts = opts.CommitLogOptions().SetFilesystemOptions(fsOpts)
opts = DefaultTestOptions()
fsOpts = opts.CommitLogOptions().FilesystemOptions().SetFilePathPrefix(dir)
newClOpts = opts.CommitLogOptions().SetFilesystemOptions(fsOpts)
mockRetriever = block.NewMockDatabaseBlockRetriever(ctrl)
)
opts = opts.SetCommitLogOptions(newClOpts)
Expand Down Expand Up @@ -1849,23 +1849,30 @@ func TestShardAggregateTiles(t *testing.T) {
targetBlockSize = 2 * time.Hour
start = time.Now().Truncate(targetBlockSize)
opts = AggregateTilesOptions{Start: start, End: start.Add(targetBlockSize), Step: 10 * time.Minute}
err error

firstSourceBlockEntries = 3
secondSourceBlockEntries = 2
maxSourceBlockEntries = 3

expectedProcessedTileCount = int64(4)

err error
)

aggregator := NewMockTileAggregator(ctrl)
testOpts := DefaultTestOptions().SetTileAggregator(aggregator)

sourceShard := testDatabaseShard(t, testOpts)
defer sourceShard.Close()
defer assert.NoError(t, sourceShard.Close())

sourceNsID := sourceShard.namespace.ID()

reader0, volume0 := getMockReader(ctrl, t, sourceShard, start, true)
reader0.EXPECT().Entries().Return(3)
reader0.EXPECT().Entries().Return(firstSourceBlockEntries)

secondSourceBlockStart := start.Add(sourceBlockSize)
reader1, volume1 := getMockReader(ctrl, t, sourceShard, secondSourceBlockStart, true)
reader1.EXPECT().Entries().Return(2)
reader1.EXPECT().Entries().Return(secondSourceBlockEntries)

thirdSourceBlockStart := secondSourceBlockStart.Add(sourceBlockSize)
reader2, volume2 := getMockReader(ctrl, t, sourceShard, thirdSourceBlockStart, false)
Expand All @@ -1878,7 +1885,7 @@ func TestShardAggregateTiles(t *testing.T) {
}

targetShard := testDatabaseShardWithIndexFn(t, testOpts, nil, true)
defer targetShard.Close() // nolint:errcheck
defer assert.NoError(t, targetShard.Close())

writer := fs.NewMockStreamingWriter(ctrl)
gomock.InOrder(
Expand All @@ -1888,20 +1895,20 @@ func TestShardAggregateTiles(t *testing.T) {
BlockStart: opts.Start,
BlockSize: targetBlockSize,
VolumeIndex: 1,
PlannedRecordsCount: 3,
PlannedRecordsCount: uint(maxSourceBlockEntries),
}),
writer.EXPECT().Close(),
)

targetNs := NewMockNamespace(ctrl)
aggregator.EXPECT().
AggregateTiles(opts, targetNs, sourceShard.ID(), gomock.Len(2), writer).
Return(int64(4), nil)
Return(expectedProcessedTileCount, nil)

processedTileCount, err := targetShard.AggregateTiles(
sourceNsID, targetNs, sourceShard.ID(), blockReaders, writer, sourceBlockVolumes, opts)
require.NoError(t, err)
assert.Equal(t, int64(4), processedTileCount)
assert.Equal(t, expectedProcessedTileCount, processedTileCount)
}

func TestShardAggregateTilesVerifySliceLengths(t *testing.T) {
Expand All @@ -1914,7 +1921,7 @@ func TestShardAggregateTilesVerifySliceLengths(t *testing.T) {
)

targetShard := testDatabaseShardWithIndexFn(t, DefaultTestOptions(), nil, true)
defer targetShard.Close()
defer assert.NoError(t, targetShard.Close())

var blockReaders []fs.DataFileSetReader
sourceBlockVolumes := []shardBlockVolume{{start, 0}}
Expand Down