Skip to content

Commit

Permalink
S3 Select: Workaround java buffer size (#8312)
Browse files Browse the repository at this point in the history
Updates #7475

The Java implementation has a 128KB buffer and a message must be emitted before that is used. #7475 therefore limits the message size to 128KB. But up to 256 bytes are written to the buffer in each call. This means we must emit a message before shorter than 128KB.

Therefore we change the limit to 128KB minus 256 bytes.
  • Loading branch information
klauspost authored and kannappanr committed Sep 25, 2019
1 parent 704be85 commit be313f1
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions pkg/s3select/message.go
Expand Up @@ -62,7 +62,12 @@ var recordsHeader = []byte{
}

const (
maxRecordMessageLength = 128 * 1024 // Chosen for compatibility with AWS JAVA SDK
// Chosen for compatibility with AWS JAVA SDK
// It has a a buffer size of 128K:
// https://github.com/aws/aws-sdk-java/blob/master/aws-java-sdk-s3/src/main/java/com/amazonaws/services/s3/internal/eventstreaming/MessageDecoder.java#L26
// but we must make sure there is always space to add 256 bytes:
// https://github.com/aws/aws-sdk-java/blob/master/aws-java-sdk-s3/src/main/java/com/amazonaws/services/s3/model/SelectObjectContentEventStream.java#L197
maxRecordMessageLength = (128 << 10) - 256
)

var (
Expand All @@ -83,7 +88,7 @@ func newRecordsMessage(payload []byte) []byte {
}

// payloadLenForMsgLen computes the length of the payload in a record
// message given the length of the message.
// message given the total length of the message.
func payloadLenForMsgLen(messageLength int) int {
headerLength := len(recordsHeader)
payloadLength := messageLength - 4 - 4 - 4 - headerLength - 4
Expand Down

0 comments on commit be313f1

Please sign in to comment.