From 5878f74835407bd5ff60a9c2f7be9c83aff5051e Mon Sep 17 00:00:00 2001 From: Xi Chen Date: Thu, 12 Apr 2018 13:10:38 -0400 Subject: [PATCH] Address feedback --- aggregation/id.go | 8 ++++---- aggregation/type.go | 20 ++++++++++---------- encoding/protobuf/buffer.go | 18 +++++++++--------- encoding/protobuf/unaggregated_iterator.go | 2 +- 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/aggregation/id.go b/aggregation/id.go index 40f524b..8c84c20 100644 --- a/aggregation/id.go +++ b/aggregation/id.go @@ -23,7 +23,7 @@ package aggregation import ( "fmt" - schema "github.com/m3db/m3metrics/generated/proto/aggregationpb" + "github.com/m3db/m3metrics/generated/proto/aggregationpb" ) const ( @@ -45,7 +45,7 @@ var ( type ID [IDLen]uint64 // NewIDFromSchema creates an ID from schema. -func NewIDFromSchema(input []schema.AggregationType) (ID, error) { +func NewIDFromSchema(input []aggregationpb.AggregationType) (ID, error) { aggTypes, err := NewTypesFromSchema(input) if err != nil { return DefaultID, err @@ -100,7 +100,7 @@ func (id ID) String() string { } // ToProto converts the aggregation id to a protobuf message in place. -func (id ID) ToProto(pb *schema.AggregationID) error { +func (id ID) ToProto(pb *aggregationpb.AggregationID) error { if IDLen != 1 { return fmt.Errorf("id length %d cannot be represented by a single integer", IDLen) } @@ -109,7 +109,7 @@ func (id ID) ToProto(pb *schema.AggregationID) error { } // FromProto converts the protobuf message to an aggregation id in place. -func (id *ID) FromProto(pb schema.AggregationID) error { +func (id *ID) FromProto(pb aggregationpb.AggregationID) error { if IDLen != 1 { return fmt.Errorf("id length %d cannot be represented by a single integer", IDLen) } diff --git a/aggregation/type.go b/aggregation/type.go index 89b4d4f..1fa7d51 100644 --- a/aggregation/type.go +++ b/aggregation/type.go @@ -24,7 +24,7 @@ import ( "fmt" "strings" - schema "github.com/m3db/m3metrics/generated/proto/aggregationpb" + "github.com/m3db/m3metrics/generated/proto/aggregationpb" "github.com/m3db/m3x/pool" ) @@ -107,7 +107,7 @@ var ( type Type int // NewTypeFromSchema creates an aggregation type from a schema. -func NewTypeFromSchema(input schema.AggregationType) (Type, error) { +func NewTypeFromSchema(input aggregationpb.AggregationType) (Type, error) { aggType := Type(input) if !aggType.IsValid() { return UnknownType, fmt.Errorf("invalid aggregation type from schema: %s", input) @@ -191,10 +191,10 @@ func (a Type) Quantile() (float64, bool) { } // Schema returns the schema of the aggregation type. -func (a Type) Schema() (schema.AggregationType, error) { - s := schema.AggregationType(a) +func (a Type) Schema() (aggregationpb.AggregationType, error) { + s := aggregationpb.AggregationType(a) if err := validateSchemaType(s); err != nil { - return schema.AggregationType_UNKNOWN, err + return aggregationpb.AggregationType_UNKNOWN, err } return s, nil } @@ -214,8 +214,8 @@ func (a *Type) UnmarshalYAML(unmarshal func(interface{}) error) error { return nil } -func validateSchemaType(a schema.AggregationType) error { - _, ok := schema.AggregationType_name[int32(a)] +func validateSchemaType(a aggregationpb.AggregationType) error { + _, ok := aggregationpb.AggregationType_name[int32(a)] if !ok { return fmt.Errorf("invalid schema aggregation type: %v", a) } @@ -235,7 +235,7 @@ func ParseType(str string) (Type, error) { type Types []Type // NewTypesFromSchema creates a list of aggregation types from a schema. -func NewTypesFromSchema(input []schema.AggregationType) (Types, error) { +func NewTypesFromSchema(input []aggregationpb.AggregationType) (Types, error) { res := make([]Type, len(input)) for i, t := range input { aggType, err := NewTypeFromSchema(t) @@ -359,14 +359,14 @@ func (aggTypes Types) PooledQuantiles(p pool.FloatsPool) ([]float64, bool) { } // Schema returns the schema of the aggregation types. -func (aggTypes Types) Schema() ([]schema.AggregationType, error) { +func (aggTypes Types) Schema() ([]aggregationpb.AggregationType, error) { // This is the same as returning an empty slice from the functionality perspective. // It makes creating testing fixtures much simpler. if aggTypes == nil { return nil, nil } - res := make([]schema.AggregationType, len(aggTypes)) + res := make([]aggregationpb.AggregationType, len(aggTypes)) for i, aggType := range aggTypes { s, err := aggType.Schema() if err != nil { diff --git a/encoding/protobuf/buffer.go b/encoding/protobuf/buffer.go index b154d72..8c9b333 100644 --- a/encoding/protobuf/buffer.go +++ b/encoding/protobuf/buffer.go @@ -54,15 +54,6 @@ func (b *Buffer) Close() { b.buf = nil } -// allocate allocates a byte slice with at least the specified size. -func allocate(p pool.BytesPool, targetSize int) []byte { - if p == nil { - return make([]byte, targetSize) - } - b := p.Get(targetSize) - return b[:cap(b)] -} - type copyDataMode int const ( @@ -94,3 +85,12 @@ func ensureBufferSize( } return newBuf } + +// allocate allocates a byte slice with at least the specified size. +func allocate(p pool.BytesPool, targetSize int) []byte { + if p == nil { + return make([]byte, targetSize) + } + b := p.Get(targetSize) + return b[:cap(b)] +} diff --git a/encoding/protobuf/unaggregated_iterator.go b/encoding/protobuf/unaggregated_iterator.go index f655384..c0d6f7c 100644 --- a/encoding/protobuf/unaggregated_iterator.go +++ b/encoding/protobuf/unaggregated_iterator.go @@ -76,7 +76,7 @@ func (it *unaggregatedIterator) Close() { } it.closed = true it.reader = nil - it.pb = metricpb.MetricWithMetadatas{} + it.pb.Reset() it.msg = MessageUnion{} if it.bytesPool != nil && it.buf != nil { it.bytesPool.Put(it.buf)