From d8f27d0fe34ef41879fd068bd4256cefd88a06f0 Mon Sep 17 00:00:00 2001 From: Linas Naginionis Date: Thu, 11 Nov 2021 12:38:32 +0200 Subject: [PATCH 1/5] Use `persist.FileSetFlushType` instead of `persist.FileSetSnapshotType` for second target data and index ranges if bootstrapping namespace is read only. Because of this change, bootstrappers won't keep second range blocks in memory for read only namespaces (`shouldPersist` will evaluate to true for them). --- src/dbnode/storage/bootstrap.go | 1 + src/dbnode/storage/bootstrap/process.go | 66 ++++++++++++-------- src/dbnode/storage/bootstrap/process_test.go | 31 +++++++++ src/dbnode/storage/bootstrap/types.go | 4 ++ src/dbnode/storage/bootstrap_test.go | 9 +-- 5 files changed, 82 insertions(+), 29 deletions(-) diff --git a/src/dbnode/storage/bootstrap.go b/src/dbnode/storage/bootstrap.go index 3151edfcb7..fff62ece99 100644 --- a/src/dbnode/storage/bootstrap.go +++ b/src/dbnode/storage/bootstrap.go @@ -331,6 +331,7 @@ func (m *bootstrapManager) bootstrap() error { Shards: bootstrapShards, Hooks: hooks, DataAccumulator: accumulator, + ReadOnly: ns.namespace.ReadOnly(), }) } diff --git a/src/dbnode/storage/bootstrap/process.go b/src/dbnode/storage/bootstrap/process.go index 904370cc70..0694447074 100644 --- a/src/dbnode/storage/bootstrap/process.go +++ b/src/dbnode/storage/bootstrap/process.go @@ -188,19 +188,24 @@ func (b bootstrapProcess) Run( } namespaceDetails := make([]NamespaceDetails, 0, len(namespaces)) for _, namespace := range namespaces { - ropts := namespace.Metadata.Options().RetentionOptions() - idxopts := namespace.Metadata.Options().IndexOptions() - dataRanges := b.targetRangesForData(at, ropts) - indexRanges := b.targetRangesForIndex(at, ropts, idxopts) - firstRanges := b.newShardTimeRanges( - dataRanges.firstRangeWithPersistTrue.Range, - namespace.Shards, + var ( + ropts = namespace.Metadata.Options().RetentionOptions() + idxopts = namespace.Metadata.Options().IndexOptions() + readOnly = namespace.ReadOnly + dataRanges = b.targetRangesForData(at, ropts, readOnly) + indexRanges = b.targetRangesForIndex(at, ropts, idxopts, readOnly) + firstRanges = b.newShardTimeRanges( + dataRanges.firstRangeWithPersistTrue.Range, + namespace.Shards, + ) ) + namespacesRunFirst.Namespaces.Set(namespace.Metadata.ID(), Namespace{ Metadata: namespace.Metadata, Shards: namespace.Shards, DataAccumulator: namespace.DataAccumulator, Hooks: namespace.Hooks, + ReadOnly: namespace.ReadOnly, DataTargetRange: dataRanges.firstRangeWithPersistTrue, IndexTargetRange: indexRanges.firstRangeWithPersistTrue, DataRunOptions: NamespaceRunOptions{ @@ -215,23 +220,24 @@ func (b bootstrapProcess) Run( }, }) secondRanges := b.newShardTimeRanges( - dataRanges.secondRangeWithPersistFalse.Range, namespace.Shards) + dataRanges.secondRange.Range, namespace.Shards) namespacesRunSecond.Namespaces.Set(namespace.Metadata.ID(), Namespace{ Metadata: namespace.Metadata, Shards: namespace.Shards, DataAccumulator: namespace.DataAccumulator, Hooks: namespace.Hooks, - DataTargetRange: dataRanges.secondRangeWithPersistFalse, - IndexTargetRange: indexRanges.secondRangeWithPersistFalse, + ReadOnly: namespace.ReadOnly, + DataTargetRange: dataRanges.secondRange, + IndexTargetRange: indexRanges.secondRange, DataRunOptions: NamespaceRunOptions{ ShardTimeRanges: secondRanges.Copy(), TargetShardTimeRanges: secondRanges.Copy(), - RunOptions: dataRanges.secondRangeWithPersistFalse.RunOptions, + RunOptions: dataRanges.secondRange.RunOptions, }, IndexRunOptions: NamespaceRunOptions{ ShardTimeRanges: secondRanges.Copy(), TargetShardTimeRanges: secondRanges.Copy(), - RunOptions: indexRanges.secondRangeWithPersistFalse.RunOptions, + RunOptions: indexRanges.secondRange.RunOptions, }, }) namespaceDetails = append(namespaceDetails, NamespaceDetails{ @@ -248,7 +254,7 @@ func (b bootstrapProcess) Run( } bootstrapResult := NewNamespaceResults(namespacesRunFirst) - for _, namespaces := range []Namespaces{ + for runIndex, namespaces := range []Namespaces{ namespacesRunFirst, namespacesRunSecond, } { @@ -266,24 +272,23 @@ func (b bootstrapProcess) Run( continue } - // Check if snapshot-type ranges have advanced while bootstrapping previous ranges. + // If second run, check if snapshot-type ranges have advanced while bootstrapping previous ranges. // If yes, return an error to force a retry - if persistConf := ns.DataRunOptions.RunOptions.PersistConfig(); persistConf.Enabled && - persistConf.FileSetType == persist.FileSetSnapshotType { + if runIndex == 1 { var ( now = xtime.ToUnixNano(b.nowFn()) nsOptions = ns.Metadata.Options() - upToDateDataRanges = b.targetRangesForData(now, nsOptions.RetentionOptions()) + upToDateDataRanges = b.targetRangesForData(now, nsOptions.RetentionOptions(), ns.ReadOnly) ) // Only checking data ranges. Since index blocks can only be a multiple of // data block size, the ranges for index could advance only if data ranges // have advanced, too (while opposite is not necessarily true) - if !upToDateDataRanges.secondRangeWithPersistFalse.Range.Equal(ns.DataTargetRange.Range) { + if !upToDateDataRanges.secondRange.Range.Equal(ns.DataTargetRange.Range) { upToDateIndexRanges := b.targetRangesForIndex(now, nsOptions.RetentionOptions(), - nsOptions.IndexOptions()) + nsOptions.IndexOptions(), ns.ReadOnly) fields := b.logFields(ns.Metadata, ns.Shards, - upToDateDataRanges.secondRangeWithPersistFalse.Range, - upToDateIndexRanges.secondRangeWithPersistFalse.Range) + upToDateDataRanges.secondRange.Range, + upToDateIndexRanges.secondRange.Range) b.log.Error("time ranges of snapshot-type blocks advanced", fields...) return NamespaceResults{}, ErrFileSetSnapshotTypeRangeAdvanced } @@ -445,6 +450,7 @@ func (b bootstrapProcess) logBootstrapResult( func (b bootstrapProcess) targetRangesForData( at xtime.UnixNano, ropts retention.Options, + readOnly bool, ) targetRangesResult { return b.targetRanges(at, targetRangesOptions{ retentionPeriod: ropts.RetentionPeriod(), @@ -452,6 +458,7 @@ func (b bootstrapProcess) targetRangesForData( blockSize: ropts.BlockSize(), bufferPast: ropts.BufferPast(), bufferFuture: ropts.BufferFuture(), + readOnly: readOnly, }) } @@ -459,6 +466,7 @@ func (b bootstrapProcess) targetRangesForIndex( at xtime.UnixNano, ropts retention.Options, idxopts namespace.IndexOptions, + readOnly bool, ) targetRangesResult { return b.targetRanges(at, targetRangesOptions{ retentionPeriod: ropts.RetentionPeriod(), @@ -466,6 +474,7 @@ func (b bootstrapProcess) targetRangesForIndex( blockSize: idxopts.BlockSize(), bufferPast: ropts.BufferPast(), bufferFuture: ropts.BufferFuture(), + readOnly: readOnly, }) } @@ -475,11 +484,12 @@ type targetRangesOptions struct { blockSize time.Duration bufferPast time.Duration bufferFuture time.Duration + readOnly bool } type targetRangesResult struct { - firstRangeWithPersistTrue TargetRange - secondRangeWithPersistFalse TargetRange + firstRangeWithPersistTrue TargetRange + secondRange TargetRange } func (b bootstrapProcess) targetRanges( @@ -499,6 +509,12 @@ func (b bootstrapProcess) targetRanges( Truncate(opts.blockSize). Add(opts.blockSize) + secondRangeFilesetType := persist.FileSetSnapshotType + if opts.readOnly { + // NB: If namespace is read-only, we don't want to keep blocks in memory. + secondRangeFilesetType = persist.FileSetFlushType + } + // NB(r): We want the large initial time range bootstrapped to // bootstrap with persistence so we don't keep the full raw // data in process until we finish bootstrapping which could @@ -514,7 +530,7 @@ func (b bootstrapProcess) targetRanges( FileSetType: persist.FileSetFlushType, }), }, - secondRangeWithPersistFalse: TargetRange{ + secondRange: TargetRange{ Range: xtime.Range{Start: midPoint, End: cutover}, RunOptions: b.newRunOptions().SetPersistConfig(PersistConfig{ Enabled: true, @@ -522,7 +538,7 @@ func (b bootstrapProcess) targetRanges( // in memory, but we want to snapshot them as we receive them // so that once bootstrapping completes we can still recover // from just the commit log bootstrapper. - FileSetType: persist.FileSetSnapshotType, + FileSetType: secondRangeFilesetType, }), }, } diff --git a/src/dbnode/storage/bootstrap/process_test.go b/src/dbnode/storage/bootstrap/process_test.go index 6e8cb63fc0..9d95adea30 100644 --- a/src/dbnode/storage/bootstrap/process_test.go +++ b/src/dbnode/storage/bootstrap/process_test.go @@ -29,6 +29,7 @@ import ( "github.com/m3db/m3/src/cluster/shard" "github.com/m3db/m3/src/dbnode/namespace" + "github.com/m3db/m3/src/dbnode/persist" "github.com/m3db/m3/src/dbnode/persist/fs" "github.com/m3db/m3/src/dbnode/retention" "github.com/m3db/m3/src/dbnode/sharding" @@ -135,3 +136,33 @@ func TestBootstrapProcessRunActiveBlockAdvanced(t *testing.T) { }) } } + +func TestTargetRangesFileSetTypeForReadOnlyNamespace(t *testing.T) { + sut := bootstrapProcess{processOpts: NewProcessOptions()} + + rangesForData := sut.targetRangesForData(xtime.Now(), retention.NewOptions(), true) + rangesForIndex := sut.targetRangesForIndex(xtime.Now(), retention.NewOptions(), namespace.NewIndexOptions(), true) + + requireFilesetTypes(t, rangesForData, persist.FileSetFlushType) + requireFilesetTypes(t, rangesForIndex, persist.FileSetFlushType) +} + +func TestTargetRangesFileSetTypeForNonReadOnlyNamespace(t *testing.T) { + sut := bootstrapProcess{processOpts: NewProcessOptions()} + + rangesForData := sut.targetRangesForData(xtime.Now(), retention.NewOptions(), false) + rangesForIndex := sut.targetRangesForIndex(xtime.Now(), retention.NewOptions(), namespace.NewIndexOptions(), false) + + requireFilesetTypes(t, rangesForData, persist.FileSetSnapshotType) + requireFilesetTypes(t, rangesForIndex, persist.FileSetSnapshotType) +} + +func requireFilesetTypes(t *testing.T, ranges targetRangesResult, expectedSecond persist.FileSetType) { + persistConfigFirstRange := ranges.firstRangeWithPersistTrue.RunOptions.PersistConfig() + require.True(t, persistConfigFirstRange.Enabled) + require.Equal(t, persist.FileSetFlushType, persistConfigFirstRange.FileSetType) + + persistConfigSecondRange := ranges.secondRange.RunOptions.PersistConfig() + require.True(t, persistConfigSecondRange.Enabled) + require.Equal(t, expectedSecond, persistConfigSecondRange.FileSetType) +} diff --git a/src/dbnode/storage/bootstrap/types.go b/src/dbnode/storage/bootstrap/types.go index 9724997402..8c87954355 100644 --- a/src/dbnode/storage/bootstrap/types.go +++ b/src/dbnode/storage/bootstrap/types.go @@ -74,6 +74,8 @@ type ProcessNamespace struct { DataAccumulator NamespaceDataAccumulator // Hooks is a set of namespace bootstrap hooks. Hooks NamespaceHooks + // ReadOnly returns true if namespace is read-only. + ReadOnly bool } // NamespaceHooks is a set of namespace bootstrap hooks. @@ -221,6 +223,8 @@ type Namespace struct { // IndexRunOptions are the options for the index bootstrap for this // namespace. IndexRunOptions NamespaceRunOptions + // ReadOnly returns true if namespace is read-only. + ReadOnly bool } // NamespaceRunOptions are the run options for a bootstrap process run. diff --git a/src/dbnode/storage/bootstrap_test.go b/src/dbnode/storage/bootstrap_test.go index 0a69ef826e..d49a1b74c6 100644 --- a/src/dbnode/storage/bootstrap_test.go +++ b/src/dbnode/storage/bootstrap_test.go @@ -77,6 +77,7 @@ func testDatabaseBootstrapWithBootstrapError(t *testing.T, async bool) { gomock.InOrder( ns.EXPECT().PrepareBootstrap(gomock.Any()).Return([]databaseShard{}, nil), ns.EXPECT().Metadata().Return(meta), + ns.EXPECT().ReadOnly().Return(false), ns.EXPECT().ID().Return(id), ns.EXPECT(). Bootstrap(gomock.Any(), gomock.Any()). @@ -141,9 +142,9 @@ func TestDatabaseBootstrapSubsequentCallsQueued(t *testing.T) { var wg sync.WaitGroup wg.Add(1) - ns.EXPECT().PrepareBootstrap(gomock.Any()).Return([]databaseShard{}, nil).AnyTimes() - ns.EXPECT().Metadata().Return(meta).AnyTimes() - + ns.EXPECT().PrepareBootstrap(gomock.Any()).Return([]databaseShard{}, nil).Times(2) + ns.EXPECT().Metadata().Return(meta).Times(2) + ns.EXPECT().ReadOnly().Return(true).Times(2) ns.EXPECT(). Bootstrap(gomock.Any(), gomock.Any()). Return(nil). @@ -216,7 +217,7 @@ func TestDatabaseBootstrapBootstrapHooks(t *testing.T) { ns.EXPECT().PrepareBootstrap(gomock.Any()).Return(shards, nil).AnyTimes() ns.EXPECT().Metadata().Return(meta).AnyTimes() - + ns.EXPECT().ReadOnly().Return(false).Times(2) ns.EXPECT(). Bootstrap(gomock.Any(), gomock.Any()). Return(nil). From 28ceb75b293768997765872d21111a3bbc86bd66 Mon Sep 17 00:00:00 2001 From: Linas Naginionis Date: Thu, 11 Nov 2021 16:25:26 +0200 Subject: [PATCH 2/5] Inline `namespace.ReadOnly` instead of declaring it as var. --- src/dbnode/storage/bootstrap/process.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/dbnode/storage/bootstrap/process.go b/src/dbnode/storage/bootstrap/process.go index 0694447074..c9ca912f12 100644 --- a/src/dbnode/storage/bootstrap/process.go +++ b/src/dbnode/storage/bootstrap/process.go @@ -191,9 +191,8 @@ func (b bootstrapProcess) Run( var ( ropts = namespace.Metadata.Options().RetentionOptions() idxopts = namespace.Metadata.Options().IndexOptions() - readOnly = namespace.ReadOnly - dataRanges = b.targetRangesForData(at, ropts, readOnly) - indexRanges = b.targetRangesForIndex(at, ropts, idxopts, readOnly) + dataRanges = b.targetRangesForData(at, ropts, namespace.ReadOnly) + indexRanges = b.targetRangesForIndex(at, ropts, idxopts, namespace.ReadOnly) firstRanges = b.newShardTimeRanges( dataRanges.firstRangeWithPersistTrue.Range, namespace.Shards, From c4535aeffd17d8f7b34c0f21908baf0289cf5172 Mon Sep 17 00:00:00 2001 From: Linas Naginionis Date: Mon, 15 Nov 2021 16:01:36 +0200 Subject: [PATCH 3/5] Use `snapshotEnabled` instead of `namespace.ReadOnly`. --- src/dbnode/storage/bootstrap.go | 1 - src/dbnode/storage/bootstrap/process.go | 54 +++++++++----------- src/dbnode/storage/bootstrap/process_test.go | 10 ++-- src/dbnode/storage/bootstrap/types.go | 2 - src/dbnode/storage/bootstrap_test.go | 12 ++--- 5 files changed, 34 insertions(+), 45 deletions(-) diff --git a/src/dbnode/storage/bootstrap.go b/src/dbnode/storage/bootstrap.go index fff62ece99..3151edfcb7 100644 --- a/src/dbnode/storage/bootstrap.go +++ b/src/dbnode/storage/bootstrap.go @@ -331,7 +331,6 @@ func (m *bootstrapManager) bootstrap() error { Shards: bootstrapShards, Hooks: hooks, DataAccumulator: accumulator, - ReadOnly: ns.namespace.ReadOnly(), }) } diff --git a/src/dbnode/storage/bootstrap/process.go b/src/dbnode/storage/bootstrap/process.go index c9ca912f12..ca9cc2518e 100644 --- a/src/dbnode/storage/bootstrap/process.go +++ b/src/dbnode/storage/bootstrap/process.go @@ -34,7 +34,6 @@ import ( "github.com/m3db/m3/src/dbnode/namespace" "github.com/m3db/m3/src/dbnode/persist" "github.com/m3db/m3/src/dbnode/persist/fs" - "github.com/m3db/m3/src/dbnode/retention" "github.com/m3db/m3/src/dbnode/storage/bootstrap/result" "github.com/m3db/m3/src/dbnode/topology" "github.com/m3db/m3/src/dbnode/tracepoint" @@ -189,10 +188,9 @@ func (b bootstrapProcess) Run( namespaceDetails := make([]NamespaceDetails, 0, len(namespaces)) for _, namespace := range namespaces { var ( - ropts = namespace.Metadata.Options().RetentionOptions() - idxopts = namespace.Metadata.Options().IndexOptions() - dataRanges = b.targetRangesForData(at, ropts, namespace.ReadOnly) - indexRanges = b.targetRangesForIndex(at, ropts, idxopts, namespace.ReadOnly) + nsOpts = namespace.Metadata.Options() + dataRanges = b.targetRangesForData(at, nsOpts) + indexRanges = b.targetRangesForIndex(at, nsOpts) firstRanges = b.newShardTimeRanges( dataRanges.firstRangeWithPersistTrue.Range, namespace.Shards, @@ -204,7 +202,6 @@ func (b bootstrapProcess) Run( Shards: namespace.Shards, DataAccumulator: namespace.DataAccumulator, Hooks: namespace.Hooks, - ReadOnly: namespace.ReadOnly, DataTargetRange: dataRanges.firstRangeWithPersistTrue, IndexTargetRange: indexRanges.firstRangeWithPersistTrue, DataRunOptions: NamespaceRunOptions{ @@ -225,7 +222,6 @@ func (b bootstrapProcess) Run( Shards: namespace.Shards, DataAccumulator: namespace.DataAccumulator, Hooks: namespace.Hooks, - ReadOnly: namespace.ReadOnly, DataTargetRange: dataRanges.secondRange, IndexTargetRange: indexRanges.secondRange, DataRunOptions: NamespaceRunOptions{ @@ -252,12 +248,12 @@ func (b bootstrapProcess) Run( return NamespaceResults{}, err } - bootstrapResult := NewNamespaceResults(namespacesRunFirst) - for runIndex, namespaces := range []Namespaces{ - namespacesRunFirst, - namespacesRunSecond, - } { - + var ( + bootstrapResult = NewNamespaceResults(namespacesRunFirst) + namespacesToRun = []Namespaces{namespacesRunFirst, namespacesRunSecond} + lastRunIndex = len(namespacesToRun) - 1 + ) + for runIndex, namespaces := range namespacesToRun { for _, entry := range namespaces.Namespaces.Iter() { ns := entry.Value() @@ -271,20 +267,19 @@ func (b bootstrapProcess) Run( continue } - // If second run, check if snapshot-type ranges have advanced while bootstrapping previous ranges. - // If yes, return an error to force a retry - if runIndex == 1 { + // If last run, check if ranges have advanced while bootstrapping previous ranges. + // If yes, return an error to force a retry. + if runIndex == lastRunIndex { var ( now = xtime.ToUnixNano(b.nowFn()) nsOptions = ns.Metadata.Options() - upToDateDataRanges = b.targetRangesForData(now, nsOptions.RetentionOptions(), ns.ReadOnly) + upToDateDataRanges = b.targetRangesForData(now, nsOptions) ) // Only checking data ranges. Since index blocks can only be a multiple of // data block size, the ranges for index could advance only if data ranges // have advanced, too (while opposite is not necessarily true) if !upToDateDataRanges.secondRange.Range.Equal(ns.DataTargetRange.Range) { - upToDateIndexRanges := b.targetRangesForIndex(now, nsOptions.RetentionOptions(), - nsOptions.IndexOptions(), ns.ReadOnly) + upToDateIndexRanges := b.targetRangesForIndex(now, nsOptions) fields := b.logFields(ns.Metadata, ns.Shards, upToDateDataRanges.secondRange.Range, upToDateIndexRanges.secondRange.Range) @@ -448,32 +443,31 @@ func (b bootstrapProcess) logBootstrapResult( func (b bootstrapProcess) targetRangesForData( at xtime.UnixNano, - ropts retention.Options, - readOnly bool, + nsOpts namespace.Options, ) targetRangesResult { + ropts := nsOpts.RetentionOptions() return b.targetRanges(at, targetRangesOptions{ retentionPeriod: ropts.RetentionPeriod(), futureRetentionPeriod: ropts.FutureRetentionPeriod(), blockSize: ropts.BlockSize(), bufferPast: ropts.BufferPast(), bufferFuture: ropts.BufferFuture(), - readOnly: readOnly, + snapshotEnabled: nsOpts.SnapshotEnabled(), }) } func (b bootstrapProcess) targetRangesForIndex( at xtime.UnixNano, - ropts retention.Options, - idxopts namespace.IndexOptions, - readOnly bool, + nsOpts namespace.Options, ) targetRangesResult { + ropts := nsOpts.RetentionOptions() return b.targetRanges(at, targetRangesOptions{ retentionPeriod: ropts.RetentionPeriod(), futureRetentionPeriod: ropts.FutureRetentionPeriod(), - blockSize: idxopts.BlockSize(), + blockSize: nsOpts.IndexOptions().BlockSize(), bufferPast: ropts.BufferPast(), bufferFuture: ropts.BufferFuture(), - readOnly: readOnly, + snapshotEnabled: nsOpts.SnapshotEnabled(), }) } @@ -483,7 +477,7 @@ type targetRangesOptions struct { blockSize time.Duration bufferPast time.Duration bufferFuture time.Duration - readOnly bool + snapshotEnabled bool } type targetRangesResult struct { @@ -509,8 +503,8 @@ func (b bootstrapProcess) targetRanges( Add(opts.blockSize) secondRangeFilesetType := persist.FileSetSnapshotType - if opts.readOnly { - // NB: If namespace is read-only, we don't want to keep blocks in memory. + if !opts.snapshotEnabled { + // NB: If snapshots are disabled for a namespace, we want to use flush type. secondRangeFilesetType = persist.FileSetFlushType } diff --git a/src/dbnode/storage/bootstrap/process_test.go b/src/dbnode/storage/bootstrap/process_test.go index 9d95adea30..68af93254a 100644 --- a/src/dbnode/storage/bootstrap/process_test.go +++ b/src/dbnode/storage/bootstrap/process_test.go @@ -139,9 +139,10 @@ func TestBootstrapProcessRunActiveBlockAdvanced(t *testing.T) { func TestTargetRangesFileSetTypeForReadOnlyNamespace(t *testing.T) { sut := bootstrapProcess{processOpts: NewProcessOptions()} + nsOpts := namespace.NewOptions().SetSnapshotEnabled(false) - rangesForData := sut.targetRangesForData(xtime.Now(), retention.NewOptions(), true) - rangesForIndex := sut.targetRangesForIndex(xtime.Now(), retention.NewOptions(), namespace.NewIndexOptions(), true) + rangesForData := sut.targetRangesForData(xtime.Now(), nsOpts) + rangesForIndex := sut.targetRangesForIndex(xtime.Now(), nsOpts) requireFilesetTypes(t, rangesForData, persist.FileSetFlushType) requireFilesetTypes(t, rangesForIndex, persist.FileSetFlushType) @@ -149,9 +150,10 @@ func TestTargetRangesFileSetTypeForReadOnlyNamespace(t *testing.T) { func TestTargetRangesFileSetTypeForNonReadOnlyNamespace(t *testing.T) { sut := bootstrapProcess{processOpts: NewProcessOptions()} + nsOpts := namespace.NewOptions().SetSnapshotEnabled(true) - rangesForData := sut.targetRangesForData(xtime.Now(), retention.NewOptions(), false) - rangesForIndex := sut.targetRangesForIndex(xtime.Now(), retention.NewOptions(), namespace.NewIndexOptions(), false) + rangesForData := sut.targetRangesForData(xtime.Now(), nsOpts) + rangesForIndex := sut.targetRangesForIndex(xtime.Now(), nsOpts) requireFilesetTypes(t, rangesForData, persist.FileSetSnapshotType) requireFilesetTypes(t, rangesForIndex, persist.FileSetSnapshotType) diff --git a/src/dbnode/storage/bootstrap/types.go b/src/dbnode/storage/bootstrap/types.go index 8c87954355..9c69407eff 100644 --- a/src/dbnode/storage/bootstrap/types.go +++ b/src/dbnode/storage/bootstrap/types.go @@ -74,8 +74,6 @@ type ProcessNamespace struct { DataAccumulator NamespaceDataAccumulator // Hooks is a set of namespace bootstrap hooks. Hooks NamespaceHooks - // ReadOnly returns true if namespace is read-only. - ReadOnly bool } // NamespaceHooks is a set of namespace bootstrap hooks. diff --git a/src/dbnode/storage/bootstrap_test.go b/src/dbnode/storage/bootstrap_test.go index d49a1b74c6..92d49cd80f 100644 --- a/src/dbnode/storage/bootstrap_test.go +++ b/src/dbnode/storage/bootstrap_test.go @@ -26,15 +26,14 @@ import ( "testing" "time" - "github.com/m3db/m3/src/dbnode/namespace" - "github.com/m3db/m3/src/dbnode/storage/bootstrap" - "github.com/m3db/m3/src/x/context" - "github.com/m3db/m3/src/x/ident" - "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/m3db/m3/src/dbnode/namespace" + "github.com/m3db/m3/src/dbnode/storage/bootstrap" + "github.com/m3db/m3/src/x/context" + "github.com/m3db/m3/src/x/ident" xtest "github.com/m3db/m3/src/x/test" ) @@ -77,7 +76,6 @@ func testDatabaseBootstrapWithBootstrapError(t *testing.T, async bool) { gomock.InOrder( ns.EXPECT().PrepareBootstrap(gomock.Any()).Return([]databaseShard{}, nil), ns.EXPECT().Metadata().Return(meta), - ns.EXPECT().ReadOnly().Return(false), ns.EXPECT().ID().Return(id), ns.EXPECT(). Bootstrap(gomock.Any(), gomock.Any()). @@ -144,7 +142,6 @@ func TestDatabaseBootstrapSubsequentCallsQueued(t *testing.T) { ns.EXPECT().PrepareBootstrap(gomock.Any()).Return([]databaseShard{}, nil).Times(2) ns.EXPECT().Metadata().Return(meta).Times(2) - ns.EXPECT().ReadOnly().Return(true).Times(2) ns.EXPECT(). Bootstrap(gomock.Any(), gomock.Any()). Return(nil). @@ -217,7 +214,6 @@ func TestDatabaseBootstrapBootstrapHooks(t *testing.T) { ns.EXPECT().PrepareBootstrap(gomock.Any()).Return(shards, nil).AnyTimes() ns.EXPECT().Metadata().Return(meta).AnyTimes() - ns.EXPECT().ReadOnly().Return(false).Times(2) ns.EXPECT(). Bootstrap(gomock.Any(), gomock.Any()). Return(nil). From 7f2a91f2acf5f1d10f484c68c490105e37596a65 Mon Sep 17 00:00:00 2001 From: Linas Naginionis Date: Mon, 15 Nov 2021 16:18:39 +0200 Subject: [PATCH 4/5] Removed unused field. --- src/dbnode/storage/bootstrap/types.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/dbnode/storage/bootstrap/types.go b/src/dbnode/storage/bootstrap/types.go index 9c69407eff..9724997402 100644 --- a/src/dbnode/storage/bootstrap/types.go +++ b/src/dbnode/storage/bootstrap/types.go @@ -221,8 +221,6 @@ type Namespace struct { // IndexRunOptions are the options for the index bootstrap for this // namespace. IndexRunOptions NamespaceRunOptions - // ReadOnly returns true if namespace is read-only. - ReadOnly bool } // NamespaceRunOptions are the run options for a bootstrap process run. From e205a448c4139a3216b19eb2ac7a320c2e4547e2 Mon Sep 17 00:00:00 2001 From: Linas Naginionis Date: Tue, 16 Nov 2021 16:02:15 +0200 Subject: [PATCH 5/5] Updated unit test names to align with snapshotEnabled. --- src/dbnode/storage/bootstrap/process_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dbnode/storage/bootstrap/process_test.go b/src/dbnode/storage/bootstrap/process_test.go index 68af93254a..8fdc33faa5 100644 --- a/src/dbnode/storage/bootstrap/process_test.go +++ b/src/dbnode/storage/bootstrap/process_test.go @@ -137,7 +137,7 @@ func TestBootstrapProcessRunActiveBlockAdvanced(t *testing.T) { } } -func TestTargetRangesFileSetTypeForReadOnlyNamespace(t *testing.T) { +func TestTargetRangesFileSetTypeForSnapshotDisabledNamespace(t *testing.T) { sut := bootstrapProcess{processOpts: NewProcessOptions()} nsOpts := namespace.NewOptions().SetSnapshotEnabled(false) @@ -148,7 +148,7 @@ func TestTargetRangesFileSetTypeForReadOnlyNamespace(t *testing.T) { requireFilesetTypes(t, rangesForIndex, persist.FileSetFlushType) } -func TestTargetRangesFileSetTypeForNonReadOnlyNamespace(t *testing.T) { +func TestTargetRangesFileSetTypeForSnapshotEnabledNamespace(t *testing.T) { sut := bootstrapProcess{processOpts: NewProcessOptions()} nsOpts := namespace.NewOptions().SetSnapshotEnabled(true)