Skip to content

Commit

Permalink
[aggregator] Checking if metadata is set to default should not cause …
Browse files Browse the repository at this point in the history
…copying (#3198)
  • Loading branch information
vdarulis authored Feb 9, 2021
1 parent 59e5e2e commit 7bf4a4e
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 10 deletions.
14 changes: 10 additions & 4 deletions src/metrics/metadata/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ func (m PipelineMetadata) Equal(other PipelineMetadata) bool {

// IsDefault returns whether this is the default standard pipeline metadata.
func (m PipelineMetadata) IsDefault() bool {
return m.AggregationID.IsDefault() &&
m.StoragePolicies.IsDefault() &&
return m.AggregationID == aggregation.DefaultID &&
len(m.StoragePolicies) == 0 &&
m.Pipeline.IsEmpty() &&
m.DropPolicy.IsDefault()
m.DropPolicy == policy.DefaultDropPolicy
}

// IsMappingRule returns whether this is a rollup rule pipeline metadata.
Expand Down Expand Up @@ -435,7 +435,13 @@ func (sms StagedMetadatas) Equal(other StagedMetadatas) bool {

// IsDefault determines whether the list of staged metadata is a default list.
func (sms StagedMetadatas) IsDefault() bool {
return len(sms) == 1 && sms[0].IsDefault()
// very ugly but need to help out the go compiler here, as function calls have a high inlining cost
return len(sms) == 1 && len(sms[0].Pipelines) == 1 &&
sms[0].CutoverNanos == 0 && !sms[0].Tombstoned &&
sms[0].Pipelines[0].AggregationID == aggregation.DefaultID &&
len(sms[0].Pipelines[0].StoragePolicies) == 0 &&
sms[0].Pipelines[0].Pipeline.IsEmpty() &&
sms[0].Pipelines[0].DropPolicy == policy.DefaultDropPolicy
}

// IsDropPolicyApplied returns whether the list of staged metadata is the
Expand Down
22 changes: 18 additions & 4 deletions src/metrics/metadata/metadata_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,32 @@ package metadata
import (
"runtime"
"testing"

"github.com/m3db/m3/src/metrics/aggregation"
"github.com/m3db/m3/src/metrics/policy"
)

func isDefault(m StagedMetadatas) bool {
return m.IsDefault()
}

func BenchmarkMetadata_IsDefault(b *testing.B) {
m := testLargeStagedMetadatas
m = append(m, testLargeStagedMetadatas...)
m := StagedMetadatas{
StagedMetadata{
CutoverNanos: 0,
Tombstoned: false,
Metadata: Metadata{
Pipelines: []PipelineMetadata{
{
AggregationID: aggregation.DefaultID,
StoragePolicies: []policy.StoragePolicy{},
},
},
},
},
}
for i := 0; i < b.N; i++ {
m[0].CutoverNanos = int64(i)
if isDefault(m) {
if !isDefault(m) {
b.Fail()
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/metrics/metadata/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,10 @@ func TestStagedMetadatasIsDefault(t *testing.T) {
}

for _, input := range inputs {
require.Equal(t, input.expected, input.metadatas.IsDefault())
input := input
t.Run(fmt.Sprintf("%v", input.metadatas), func(t *testing.T) {
require.Equal(t, input.expected, input.metadatas.IsDefault())
})
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/metrics/pipeline/applied/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func NewPipeline(ops []OpUnion) Pipeline {
func (p Pipeline) Len() int { return len(p.operations) }

// IsEmpty determines whether a pipeline is empty.
func (p Pipeline) IsEmpty() bool { return p.Len() == 0 }
func (p Pipeline) IsEmpty() bool { return len(p.operations) == 0 }

// At returns the operation at a given step.
func (p Pipeline) At(i int) OpUnion { return p.operations[i] }
Expand Down

0 comments on commit 7bf4a4e

Please sign in to comment.