Skip to content

Instantly share code, notes, and snippets.

@jwilder
Created April 11, 2015 04:20
Show Gist options
  • Save jwilder/e46cdb9e7f9cb902d80e to your computer and use it in GitHub Desktop.
Save jwilder/e46cdb9e7f9cb902d80e to your computer and use it in GitHub Desktop.
DQ remote_mapper.go
diff --git a/remote_mapper.go b/remote_mapper.go
index ee03e8a..3b520fb 100644
--- a/remote_mapper.go
+++ b/remote_mapper.go
@@ -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
@@ -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"`
@@ -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
}
@@ -94,19 +98,9 @@ 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
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment