Repository navigation
[Go] Fix flyweight DecodeLength() and version-gated groups for messages from other schema versions - #1197
Open
QuantIntellect wants to merge 2 commits into
Open
[Go] Fix flyweight DecodeLength() and version-gated groups for messages from other schema versions#1197QuantIntellect wants to merge 2 commits into
QuantIntellect wants to merge 2 commits into
Conversation
DecodeLength() wrapped its skipper with the schema's SbeBlockLength() instead of the block length from the message header, so it returned a wrong length, or panicked with E100, when the message was encoded with a different schema version. This is the same fix as aeron-io#1045 for C++. The test ports the C++ VersionedMessageTest case (V1 decodes V2) and adds the reverse.
A flyweight group's WrapForDecode() always read a group header at the current position, even when the group's sinceVersion is above the acting version and the group is not on the wire. A decoder for a newer schema then read the following bytes as a group header, and the generated Skip(), DecodeLength() and String() walked phantom entries even when the caller checked <Group>InActingVersion() first. A group with a sinceVersion now has a notPresent() method, as in the C++ codecs, and WrapForDecode() calls it to leave the group empty without moving the position. The check is in WrapForDecode() rather than in the accessor, where C++ has it, so that the accessor stays inlinable.
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.
Two schema-versioning bugs in the Go flyweight codecs, one commit each. Either one makes
DecodeLength()wrong when a message was encoded with a different schema version.DecodeLength()uses the schema's block length. It wraps its skipper withSbeBlockLength()instead of the block length from the message header. Once a field has been added to the root block, groups and var data are read from the wrong offset. C++ had the same code and fixed it in #1045 (#1044). With theversioned-message-v1/v2.xmlschemas from that PR, a V1 decoder of a V2 message returns 13 instead of 26, the value the C++VersionedMessageTestexpects. A V2 decoder of a V1 message panics withbuffer too short [E100]instead of returning 14. The fix passesm.actingBlockLengthandm.actingVersion, assbeRewind()already does.Groups ignore their
sinceVersionwhen decoding. A group'sWrapForDecode()always reads a group header at the current position. It does this even when the acting version is below the group'ssinceVersionand the group is not on the wire. A decoder for the newer schema then reads the following bytes (the next group entry, the var data, or the next message in a batch) as a group header. The generatedSkip(),DecodeLength()andString()go through the group accessors, so they walk phantom entries even when the caller checks<Group>InActingVersion()first. Field and var data accessors in the same generator already handle this case.A group with a
sinceVersionnow has anotPresent()method like the C++ one. ItsWrapForDecode()calls it to return an empty group without moving the position. Java returns a count of 0 here and Rust returnsNone. C++ does the check in the accessor. Here it is inWrapForDecode(), because a branch in the accessor puts the accessor over Go's inlining budget; this way the accessors still inline as before. The encode path is unchanged.To reproduce the second bug:
gocode/resources/versioned-groups-v2.xmladds two groups withsinceVersion="2"toversioned-groups-v1.xml, both before the var data: a nested group insideGroup1and a top-levelGroup2. All groups share onegroupSizeEncoding. With V1 data and V2 codecs:Group1,Group2InActingVersion()is false butGroup2().Count()is 29537, read from theString1bytes.String1()then panics withbuffer too short [E100], andDecodeLength()withbuffer too short for next group index [E108].Group1entries, the first entry'sNestedGroup2header is read from the second entry. The second entry'sFieldB1then comes back as 1935736836 (theString1length and bytes), and itsNestedGroup2()panics withbuffer too short for flyweight [E107].With this change the groups are empty,
String1()is"asdf"andDecodeLength()equals the encoded length.Tests:
gocode/flyweight/src/versmsg/VersionedMessage_test.goports the C++VersionedMessageTestcase (V1 decodes V2) and adds the reverse. A newgenerateGolangFlyweightCodecTestVersionedMessagetask generates the codecs. The versioned-message schemas have nosbe:namespace, so they can't go in the XSD-validated task.gocode/flyweight/src/versgroup/VersionedGroups_test.godecodes V1 data with an emptyGroup1and with a two-entryGroup1, then decodes V2 data, all with the V2 codecs. Its schemas are added togenerateGolangFlyweightCodecsWithXSD.versmsgandversgroupare added to the flyweight loop ingocode/Makefile.Verified:
versmsgtests fail on master and pass after the first commit.versgrouptest fails on master and after the first commit, and passes after the second../gradlew clean buildand./gradlew assemble && cd gocode && makeboth pass.go build -gcflags=-mstill reports the group accessors as inlinable.This overlaps with #1188, which also adds an argument to the group
WrapForDecode()template inGolangFlyweightGenerator. The conflict is in that one format call, and I can rebase onto it if it goes in first.