Skip to content
This repository has been archived by the owner on Oct 17, 2018. It is now read-only.

Commit

Permalink
Address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
xichen2020 committed Apr 12, 2018
1 parent d0f18b1 commit 5878f74
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 24 deletions.
8 changes: 4 additions & 4 deletions aggregation/id.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ package aggregation
import (
"fmt"

schema "github.com/m3db/m3metrics/generated/proto/aggregationpb"
"github.com/m3db/m3metrics/generated/proto/aggregationpb"
)

const (
Expand All @@ -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
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down
20 changes: 10 additions & 10 deletions aggregation/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand All @@ -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)
}
Expand All @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
18 changes: 9 additions & 9 deletions encoding/protobuf/buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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)]
}
2 changes: 1 addition & 1 deletion encoding/protobuf/unaggregated_iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 5878f74

Please sign in to comment.