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).