MINOR: [java] bound zero-byte allocation in standalone fast reader - #3946
Open
arib06 wants to merge 1 commit into
Open
MINOR: [java] bound zero-byte allocation in standalone fast reader#3946arib06 wants to merge 1 commit into
arib06 wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What is the purpose of the change
AVRO-4241 made the zero-byte collection-element allocation cap (SystemLimitException) cumulative across a decoded datum, so a record with many
array<null>-style fields cannot over-allocate in aggregate even when each field stays under the per-collection limit. That cumulative accounting only holds while an allocation scope is open.GenericDatumReader.readopens one for the whole datum, and the fast array reader opens one around its block loop, but the datum-level fast readers do not. When the fast reader is used standalone viaFastReaderBuilder.createDatumReader(...)(i.e. not reached throughGenericDatumReader.read), decoding a record resets the running total per array field, because each field's array reader opens and closes its own outermost scope. Each field then passes the per-collection check while the aggregate exceeds the cap, so a small payload can drive a large allocation. The fix wraps the reader returned bycreateDatumReaderin a scope, matchingGenericDatumReader.read. Scopes nest, so the delegated path (whereGenericDatumReader.readalready opened the outer scope) is unchanged, and valid input decodes exactly as before.Verifying this change
This change added tests and can be verified as follows:
standaloneFastReaderRecordRejectedCumulativelyAcrossDatum: a record with twoarray<null>fields of 600 nulls each (cap set to 1000) decoded through the standalone fast reader is rejected on the second field withSystemLimitException. Before the change both fields decoded, bypassing the cap.standaloneFastReaderRecordWithinCumulativeLimitStillDecodes: two fields totalling 800 elements (under the cap) still decode, and the per-datum budget resets between reads.Documentation