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] Introduce Aggregator type #2840

Merged
merged 9 commits into from
Nov 11, 2020
Merged
Show file tree
Hide file tree
Changes from 5 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/server/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ type StorageOptions struct {
TChanNodeServerFn node.NewTChanNodeServerFn
BackgroundProcessFns []storage.NewBackgroundProcessFn
NamespaceHooks storage.NamespaceHooks
NewAggregatorFn storage.NewAggregatorFn
}
5 changes: 5 additions & 0 deletions src/dbnode/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,11 @@ func Run(runOpts RunOptions) {
opts = opts.SetNamespaceHooks(runOpts.StorageOptions.NamespaceHooks)
}

if runOpts.StorageOptions.NewAggregatorFn != nil {
aggregator := runOpts.StorageOptions.NewAggregatorFn(iopts)
opts = opts.SetAggregator(aggregator)
}

// Set bootstrap options - We need to create a topology map provider from the
// same topology that will be passed to the cluster so that when we make
// bootstrapping decisions they are in sync with the clustered database
Expand Down
25 changes: 25 additions & 0 deletions src/dbnode/storage/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ type options struct {
wideBatchSize int
newBackgroundProcessFns []NewBackgroundProcessFn
namespaceHooks NamespaceHooks
aggregator Aggregator
}

// NewOptions creates a new set of storage options with defaults
Expand Down Expand Up @@ -249,6 +250,7 @@ func newOptions(poolOpts pool.ObjectPoolOptions) Options {
mediatorTickInterval: defaultMediatorTickInterval,
wideBatchSize: defaultWideBatchSize,
namespaceHooks: &noopNamespaceHooks{},
aggregator: &noopAggregator{},
}
return o.SetEncodingM3TSZPooled()
}
Expand Down Expand Up @@ -863,6 +865,17 @@ func (o *options) NamespaceHooks() NamespaceHooks {
return o.namespaceHooks
}

func (o *options) SetAggregator(value Aggregator) Options {
opts := *o
opts.aggregator = value

return &opts
}

func (o *options) Aggregator() Aggregator {
return o.aggregator
}

type noOpColdFlush struct{}

func (n *noOpColdFlush) ColdFlushNamespace(Namespace) (OnColdFlushNamespace, error) {
Expand All @@ -874,3 +887,15 @@ type noopNamespaceHooks struct{}
func (h *noopNamespaceHooks) OnCreatedNamespace(Namespace, GetNamespaceFn) error {
return nil
}

type noopAggregator struct{}

func (a *noopAggregator) AggregateTiles(
opts AggregateTilesOptions,
ns Namespace,
shardID uint32,
readers []fs.DataFileSetReader,
writer fs.StreamingWriter,
) (int64, error) {
return 0, nil
}
66 changes: 66 additions & 0 deletions src/dbnode/storage/storage_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions src/dbnode/storage/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1323,6 +1323,12 @@ type Options interface {

// NamespaceHooks returns the NamespaceHooks.
NamespaceHooks() NamespaceHooks

// SetAggregator sets the Aggregator.
SetAggregator(aggregator Aggregator) Options

// Aggregator returns the Aggregator.
Aggregator() Aggregator
}

// MemoryTracker tracks memory.
Expand Down Expand Up @@ -1394,6 +1400,21 @@ type AggregateTilesOptions struct {
InsOptions instrument.Options
}

// Aggregator is the interface for AggregateTiles.
type Aggregator interface {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Note: I'm not completely sure of the naming here. I'm afraid this might get confused with m3aggregator.
Would putting it into a tile package (to make it a tile.Aggregaor) be a better option? I'm open to other suggestions as well.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe just TileAggregator? There's also the AggregateQuery query type (which handles tag completion and was named after the ES concept) to add further confusion here

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Renamed as suggested 👍 .

// AggregateTiles does tile aggregation.
AggregateTiles(
opts AggregateTilesOptions,
ns Namespace,
shardID uint32,
readers []fs.DataFileSetReader,
writer fs.StreamingWriter,
) (int64, error)
}

// NewAggregatorFn creates a new Aggregator.
type NewAggregatorFn func(iOpts instrument.Options) Aggregator

// NamespaceHooks allows dynamic plugging into the namespace lifecycle.
type NamespaceHooks interface {
// OnCreatedNamespace gets invoked after each namespace is created.
Expand Down