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] Add IndexResults from subsequent bootstrap runs #4193

Merged
merged 1 commit into from
Mar 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions src/dbnode/storage/bootstrap/bootstrapper/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ func (b baseBootstrapper) Bootstrap(
finalResult.DataResult.SetUnfulfilled(currNamespace.DataResult.Unfulfilled().Copy())
if currNamespace.Metadata.Options().IndexOptions().Enabled() {
finalResult.IndexResult.SetUnfulfilled(currNamespace.IndexResult.Unfulfilled().Copy())
finalResult.IndexResult.IndexResults().AddResults(currNamespace.IndexResult.IndexResults())
}

// Map is by value, set the result altered struct.
Expand Down
72 changes: 57 additions & 15 deletions src/dbnode/storage/bootstrap/bootstrapper/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/m3db/m3/src/dbnode/namespace"
"github.com/m3db/m3/src/dbnode/storage/bootstrap"
"github.com/m3db/m3/src/dbnode/storage/bootstrap/result"
"github.com/m3db/m3/src/m3ninx/persist"
"github.com/m3db/m3/src/x/context"
"github.com/m3db/m3/src/x/ident"
xtime "github.com/m3db/m3/src/x/time"
Expand Down Expand Up @@ -80,6 +81,7 @@ func testResult(
withIndex bool,
shard uint32,
unfulfilledRange xtime.Ranges,
indexResult result.IndexBootstrapResult,
) bootstrap.NamespaceResults {
unfulfilled := result.NewShardTimeRanges()
unfulfilled.Set(shard, unfulfilledRange)
Expand All @@ -89,7 +91,6 @@ func testResult(
dataResult := result.NewDataBootstrapResult()
dataResult.SetUnfulfilled(unfulfilled.Copy())

indexResult := result.NewIndexBootstrapResult()
if withIndex {
indexResult.SetUnfulfilled(unfulfilled.Copy())
}
Expand Down Expand Up @@ -134,8 +135,8 @@ func testBaseBootstrapperEmptyRange(t *testing.T, withIndex bool) {

rngs := result.NewShardTimeRanges()
unfulfilled := xtime.NewRanges()
nsResults := testResult(testNs, withIndex, testShard, unfulfilled)
nextResult := testResult(testNs, withIndex, testShard, xtime.NewRanges())
nsResults := testResult(testNs, withIndex, testShard, unfulfilled, result.NewIndexBootstrapResult())
nextResult := testResult(testNs, withIndex, testShard, xtime.NewRanges(), result.NewIndexBootstrapResult())
shardRangeMatcher := bootstrap.ShardTimeRangesMatcher{Ranges: rngs}

tester := bootstrap.BuildNamespacesTester(t, testDefaultRunOpts, rngs, testNs)
Expand Down Expand Up @@ -185,8 +186,8 @@ func testBaseBootstrapperCurrentNoUnfulfilled(t *testing.T, withIndex bool) {
testNs := testNsMetadata(t, withIndex)

unfulfilled := xtime.NewRanges()
nsResults := testResult(testNs, withIndex, testShard, unfulfilled)
nextResult := testResult(testNs, withIndex, testShard, xtime.NewRanges())
nsResults := testResult(testNs, withIndex, testShard, unfulfilled, result.NewIndexBootstrapResult())
nextResult := testResult(testNs, withIndex, testShard, xtime.NewRanges(), result.NewIndexBootstrapResult())

targetRanges := testShardTimeRanges()

Expand Down Expand Up @@ -241,8 +242,8 @@ func testBaseBootstrapperCurrentSomeUnfulfilled(t *testing.T, withIndex bool) {
End: testTargetStart.Add(time.Hour * 2),
})

currResult := testResult(testNs, withIndex, testShard, currUnfulfilled)
nextResult := testResult(testNs, withIndex, testShard, xtime.NewRanges())
currResult := testResult(testNs, withIndex, testShard, currUnfulfilled, result.NewIndexBootstrapResult())
nextResult := testResult(testNs, withIndex, testShard, xtime.NewRanges(), result.NewIndexBootstrapResult())
tester := bootstrap.BuildNamespacesTester(t, testDefaultRunOpts, targetRanges,
testNs)
defer tester.Finish()
Expand All @@ -263,7 +264,7 @@ func testBaseBootstrapperCurrentSomeUnfulfilled(t *testing.T, withIndex bool) {
tester.TestUnfulfilledForNamespaceIsEmpty(testNs)
}

func testBasebootstrapperNext(
func testBaseBootstrapperNext(
t *testing.T,
nextUnfulfilled xtime.Ranges,
withIndex bool,
Expand All @@ -289,7 +290,7 @@ func testBasebootstrapperNext(
}

emptyResult := testEmptyResult(testNs)
nextResult := testResult(testNs, withIndex, testShard, nextUnfulfilled)
nextResult := testResult(testNs, withIndex, testShard, nextUnfulfilled, result.NewIndexBootstrapResult())
matcher := bootstrap.NamespaceMatcher{Namespaces: tester.Namespaces}
src.EXPECT().Read(gomock.Any(), matcher, cache).Return(emptyResult, nil)
next.EXPECT().Bootstrap(gomock.Any(), matcher, cache).Return(nextResult, nil)
Expand All @@ -309,13 +310,13 @@ func testBasebootstrapperNext(
}

func TestBaseBootstrapperNextNoUnfulfilled(t *testing.T) {
nextUnfulfilled := testTargetRanges()
testBasebootstrapperNext(t, nextUnfulfilled, false)
nextUnfulfilled := xtime.NewRanges()
testBaseBootstrapperNext(t, nextUnfulfilled, false)
}

func TestBaseBootstrapperNextNoUnfulfilledWithIndex(t *testing.T) {
nextUnfulfilled := testTargetRanges()
testBasebootstrapperNext(t, nextUnfulfilled, true)
nextUnfulfilled := xtime.NewRanges()
testBaseBootstrapperNext(t, nextUnfulfilled, true)
}

func TestBaseBootstrapperNextSomeUnfulfilled(t *testing.T) {
Expand All @@ -324,7 +325,7 @@ func TestBaseBootstrapperNextSomeUnfulfilled(t *testing.T) {
End: testTargetStart.Add(time.Hour),
})

testBasebootstrapperNext(t, nextUnfulfilled, false)
testBaseBootstrapperNext(t, nextUnfulfilled, false)
}

func TestBaseBootstrapperNextSomeUnfulfilledWithIndex(t *testing.T) {
Expand All @@ -333,5 +334,46 @@ func TestBaseBootstrapperNextSomeUnfulfilledWithIndex(t *testing.T) {
End: testTargetStart.Add(time.Hour),
})

testBasebootstrapperNext(t, nextUnfulfilled, true)
testBaseBootstrapperNext(t, nextUnfulfilled, true)
}

func TestBaseBootstrapperNextAddIndexResults(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
src, next, base := testBaseBootstrapper(t, ctrl)
testNs := testNsMetadata(t, true)
targetRanges := testShardTimeRanges()

tester := bootstrap.BuildNamespacesTester(t, testDefaultRunOpts, targetRanges, testNs)
defer tester.Finish()

cache := tester.Cache
src.EXPECT().
AvailableData(testNs, targetRanges, cache, testDefaultRunOpts).
Return(result.NewShardTimeRanges(), nil)
src.EXPECT().
AvailableIndex(testNs, targetRanges, cache, testDefaultRunOpts).
Return(result.NewShardTimeRanges(), nil)

var (
blockStart = xtime.UnixNano(1)

nextBlock = result.NewIndexBlock(nil, result.NewShardTimeRanges())
nextBlocks = result.NewIndexBlockByVolumeType(blockStart)
nextIndexResult = result.NewIndexBootstrapResult()
)

nextBlocks.SetBlock(persist.DefaultIndexVolumeType, nextBlock)
nextIndexResult.IndexResults().Add(nextBlocks)

emptyResult := testEmptyResult(testNs)
nextResult := testResult(testNs, true, testShard, xtime.NewRanges(), nextIndexResult)

matcher := bootstrap.NamespaceMatcher{Namespaces: tester.Namespaces}
src.EXPECT().Read(gomock.Any(), matcher, cache).Return(emptyResult, nil)
next.EXPECT().Bootstrap(gomock.Any(), matcher, cache).Return(nextResult, nil)

tester.TestBootstrapWith(base)

tester.TestIndexResultForNamespace(testNs, nextIndexResult)
}
9 changes: 9 additions & 0 deletions src/dbnode/storage/bootstrap/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,15 @@ func (nt *NamespacesTester) TestUnfulfilledForNamespace(
}
}

// TestIndexResultForNamespace verifies index result.
func (nt *NamespacesTester) TestIndexResultForNamespace(
md namespace.Metadata,
expected result.IndexBootstrapResult,
) {
ns := nt.ResultForNamespace(md.ID())
require.Equal(nt.t, expected, ns.IndexResult)
}

// TestUnfulfilledForNamespaceIsEmpty ensures the given namespace has an empty
// unfulfilled range.
func (nt *NamespacesTester) TestUnfulfilledForNamespaceIsEmpty(
Expand Down