From 039bea8f5ab83b026612b25a497abf2cc1c60b0c Mon Sep 17 00:00:00 2001 From: Linas Naginionis Date: Thu, 14 Jan 2021 15:53:40 +0200 Subject: [PATCH 1/3] set bootstrap state to Bootstrapped when it returns no errors --- src/dbnode/storage/bootstrap.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/dbnode/storage/bootstrap.go b/src/dbnode/storage/bootstrap.go index 8481389cf9..1340201cd2 100644 --- a/src/dbnode/storage/bootstrap.go +++ b/src/dbnode/storage/bootstrap.go @@ -153,8 +153,6 @@ func (m *bootstrapManager) Bootstrap() (BootstrapResult, error) { if currPending { // New bootstrap calls should now enqueue another pending bootstrap m.hasPending = false - } else { - m.state = Bootstrapped } m.Unlock() @@ -186,6 +184,7 @@ func (m *bootstrapManager) Bootstrap() (BootstrapResult, error) { // across the cluster. m.Lock() m.lastBootstrapCompletionTime = xtime.ToUnixNano(m.nowFn()) + m.state = Bootstrapped m.Unlock() return result, nil } From 4adb3290780779295125ea6014766b31ae8ae04c Mon Sep 17 00:00:00 2001 From: Linas Naginionis Date: Thu, 14 Jan 2021 16:56:54 +0200 Subject: [PATCH 2/3] added bootstrap regression test. --- src/dbnode/storage/bootstrap_test.go | 42 +++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/src/dbnode/storage/bootstrap_test.go b/src/dbnode/storage/bootstrap_test.go index 95337e996f..f97f7d1661 100644 --- a/src/dbnode/storage/bootstrap_test.go +++ b/src/dbnode/storage/bootstrap_test.go @@ -32,9 +32,10 @@ import ( "github.com/m3db/m3/src/x/ident" "github.com/golang/mock/gomock" - xtest "github.com/m3db/m3/src/x/test" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + + xtest "github.com/m3db/m3/src/x/test" ) func TestDatabaseBootstrapWithBootstrapError(t *testing.T) { @@ -90,6 +91,45 @@ func TestDatabaseBootstrapWithBootstrapError(t *testing.T) { require.Equal(t, "an error", result.ErrorsBootstrap[0].Error()) } +func TestDatabaseInBootstrappingStateWhenBootstrapError(t *testing.T) { + ctrl := gomock.NewController(xtest.Reporter{T: t}) + defer ctrl.Finish() + + opts := DefaultTestOptions() + db := NewMockdatabase(ctrl) + m := NewMockdatabaseMediator(ctrl) + m.EXPECT().DisableFileOpsAndWait() + m.EXPECT().EnableFileOps().AnyTimes() + + bsm := newBootstrapManager(db, m, opts).(*bootstrapManager) + // Don't sleep. + bsm.sleepFn = func(time.Duration) {} + bootstrapRetries := 0 + + bsm.bootstrapFn = func() error { + defer func() { + bootstrapRetries++ + }() + + require.Equal(t, Bootstrapping, bsm.state) + + if bootstrapRetries == 0 { + return fmt.Errorf("an error") + } + + return nil + } + + require.Equal(t, BootstrapNotStarted, bsm.state) + + result, err := bsm.Bootstrap() + + require.NoError(t, err) + require.Equal(t, Bootstrapped, bsm.state) + require.Equal(t, 1, len(result.ErrorsBootstrap)) + require.Equal(t, "an error", result.ErrorsBootstrap[0].Error()) +} + func TestDatabaseBootstrapSubsequentCallsQueued(t *testing.T) { ctrl := gomock.NewController(xtest.Reporter{T: t}) defer ctrl.Finish() From 173ed0d7dc4bf2928abc4ccc2ff57b8747d86a6a Mon Sep 17 00:00:00 2001 From: Linas Naginionis Date: Fri, 15 Jan 2021 11:00:06 +0200 Subject: [PATCH 3/3] removed new test and updated old test to check for bootstrap states. --- src/dbnode/storage/bootstrap_test.go | 38 ++-------------------------- 1 file changed, 2 insertions(+), 36 deletions(-) diff --git a/src/dbnode/storage/bootstrap_test.go b/src/dbnode/storage/bootstrap_test.go index f97f7d1661..c3b002b190 100644 --- a/src/dbnode/storage/bootstrap_test.go +++ b/src/dbnode/storage/bootstrap_test.go @@ -75,7 +75,9 @@ func TestDatabaseBootstrapWithBootstrapError(t *testing.T) { Return(fmt.Errorf("an error")). Do(func(ctx context.Context, bootstrapResult bootstrap.NamespaceResult) { // After returning an error, make sure we don't re-enqueue. + require.Equal(t, Bootstrapping, bsm.state) bsm.bootstrapFn = func() error { + require.Equal(t, Bootstrapping, bsm.state) return nil } }), @@ -84,42 +86,6 @@ func TestDatabaseBootstrapWithBootstrapError(t *testing.T) { ctx := context.NewContext() defer ctx.Close() - result, err := bsm.Bootstrap() - require.NoError(t, err) - - require.Equal(t, 1, len(result.ErrorsBootstrap)) - require.Equal(t, "an error", result.ErrorsBootstrap[0].Error()) -} - -func TestDatabaseInBootstrappingStateWhenBootstrapError(t *testing.T) { - ctrl := gomock.NewController(xtest.Reporter{T: t}) - defer ctrl.Finish() - - opts := DefaultTestOptions() - db := NewMockdatabase(ctrl) - m := NewMockdatabaseMediator(ctrl) - m.EXPECT().DisableFileOpsAndWait() - m.EXPECT().EnableFileOps().AnyTimes() - - bsm := newBootstrapManager(db, m, opts).(*bootstrapManager) - // Don't sleep. - bsm.sleepFn = func(time.Duration) {} - bootstrapRetries := 0 - - bsm.bootstrapFn = func() error { - defer func() { - bootstrapRetries++ - }() - - require.Equal(t, Bootstrapping, bsm.state) - - if bootstrapRetries == 0 { - return fmt.Errorf("an error") - } - - return nil - } - require.Equal(t, BootstrapNotStarted, bsm.state) result, err := bsm.Bootstrap()