Skip to content

Commit

Permalink
store: use old behaviour when nil has been passed
Browse files Browse the repository at this point in the history
Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com>
  • Loading branch information
GiedriusS committed Aug 11, 2021
1 parent a459162 commit 23c18e2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
4 changes: 0 additions & 4 deletions pkg/store/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1547,17 +1547,13 @@ type storeSeriesServer struct {
SeriesSet []storepb.Series
Warnings []string
HintsSet []*types.Any

Size int64
}

func newStoreSeriesServer(ctx context.Context) *storeSeriesServer {
return &storeSeriesServer{ctx: ctx}
}

func (s *storeSeriesServer) Send(r *storepb.SeriesResponse) error {
s.Size += int64(r.Size())

if r.GetWarning() != "" {
s.Warnings = append(s.Warnings, r.GetWarning())
return nil
Expand Down
22 changes: 11 additions & 11 deletions pkg/store/storepb/custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ func NewWarnSeriesResponse(err error) *SeriesResponse {
}

func NewSeriesResponse(series *Series, respBuf **[]byte, respPool *sync.Pool) *SeriesResponse {
if respPool == nil {
buf := []byte{}
bufPtr := &buf
respBuf = &bufPtr
}
return &SeriesResponse{
respPool: respPool,
respBuf: respBuf,
Expand Down Expand Up @@ -481,14 +476,19 @@ type syncPool = sync.Pool
func (m *SeriesResponse) Marshal() (dAtA []byte, err error) {
size := m.Size()

if cap(**m.respBuf) < size {
if m.respPool != nil {
m.respPool.Put(*m.respBuf)
var respBuf []byte
if m.respBuf == nil {
respBuf = make([]byte, size)
} else {
if cap(**m.respBuf) < size {
if m.respPool != nil {
m.respPool.Put(*m.respBuf)
}
buf := make([]byte, size)
*m.respBuf = &buf
}
buf := make([]byte, size)
*m.respBuf = &buf
respBuf = **m.respBuf
}
respBuf := **m.respBuf

marshalBuf := respBuf[:size]
n, err := m.MarshalToSizedBuffer(marshalBuf)
Expand Down

0 comments on commit 23c18e2

Please sign in to comment.