Skip to content

Commit

Permalink
Use Limit Reader instead of fixed 1MB/1GB slice for DQ
Browse files Browse the repository at this point in the history
Fixes #2243
  • Loading branch information
jwilder committed Apr 17, 2015
1 parent fbaa37a commit f18dbf4
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions remote_mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import (
"bytes"
"encoding/json"
"errors"
"io"
"net/http"

"github.com/influxdb/influxdb/influxql"
)

const (
MAX_MAP_RESPONSE_SIZE = 1024 * 1024
MAX_MAP_RESPONSE_SIZE = 1024 * 1024 * 1024
)

// RemoteMapper implements the influxql.Mapper interface. The engine uses the remote mapper
Expand All @@ -21,6 +22,7 @@ type RemoteMapper struct {
results chan interface{}
unmarshal influxql.UnmarshalFunc
complete bool
decoder *json.Decoder

Call string `json:",omitempty"`
Database string `json:",omitempty"`
Expand Down Expand Up @@ -83,6 +85,8 @@ func (m *RemoteMapper) Begin(c *influxql.Call, startingTime int64, chunkSize int
return err
}
m.resp = resp
lr := io.LimitReader(m.resp.Body, MAX_MAP_RESPONSE_SIZE)
m.decoder = json.NewDecoder(lr)

return nil
}
Expand All @@ -94,19 +98,8 @@ func (m *RemoteMapper) NextInterval() (interface{}, error) {
return nil, nil
}

// read the chunk
chunk := make([]byte, MAX_MAP_RESPONSE_SIZE, MAX_MAP_RESPONSE_SIZE)
n, err := m.resp.Body.Read(chunk)
if err != nil {
return nil, err
}
if n == 0 {
return nil, nil
}

// marshal the response
mr := &MapResponse{}
err = json.Unmarshal(chunk[:n], mr)
err := m.decoder.Decode(&mr)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit f18dbf4

Please sign in to comment.