Skip to content

Commit

Permalink
Export MaxBufferSize so that the user can tweak it when they have a m…
Browse files Browse the repository at this point in the history
…assive LDT
  • Loading branch information
khaf committed Aug 28, 2015
1 parent 84946ee commit a194ccf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
6 changes: 1 addition & 5 deletions batch_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ import (
Buffer "github.com/aerospike/aerospike-client-go/utils/buffer"
)

const (
_MAX_BUFFER_SIZE = 1024 * 1024 * 10 // 10 MB
)

type multiCommand interface {
Stop()
}
Expand Down Expand Up @@ -114,7 +110,7 @@ func (cmd *baseMultiCommand) readBytes(length int) error {
if length > len(cmd.dataBuffer) {
// Corrupted data streams can result in a huge length.
// Do a sanity check here.
if length > _MAX_BUFFER_SIZE {
if length > MaxBufferSize {
return NewAerospikeError(PARSE_ERROR, fmt.Sprintf("Invalid readBytes length: %d", length))
}
cmd.dataBuffer = make([]byte, length)
Expand Down
9 changes: 8 additions & 1 deletion command.go
Original file line number Diff line number Diff line change
Expand Up @@ -875,10 +875,17 @@ func (cmd *baseCommand) sizeBuffer() error {
return cmd.sizeBufferSz(cmd.dataOffset)
}

var (
// MaxBufferSize protects against allocating massive memory blocks
// for buffers. Tweak this number if you are returning a lot of
// LDT elements in your queries.
MaxBufferSize = 1024 * 1024 * 10 // 10 MB
)

func (cmd *baseCommand) sizeBufferSz(size int) error {
// Corrupted data streams can result in a huge length.
// Do a sanity check here.
if size > _MAX_BUFFER_SIZE {
if size > MaxBufferSize {
return NewAerospikeError(PARSE_ERROR, fmt.Sprintf("Invalid size for buffer: %d", size))
}

Expand Down

0 comments on commit a194ccf

Please sign in to comment.