[CASSANDRA-21685] Size calculation mismatch in EncodingStats and SerializationHeader local deletion time - #5176
Open
koo-taejin wants to merge 1 commit into
Open
koo-taejin wants to merge 1 commit into
koo-taejin wants to merge 1 commit into
Conversation
…alizationHeader local deletion time
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.
Description
While working on CASSANDRA-21535, CompactionsCQLTest failed (testCompactionInvalidRowDeletion and testIndexedReaderRowDeletion). The cause is that some serializers calculate the size in a different way from how they write the value.
Problem
In EncodingStats.Serializer, the write path casts the value to int, but the size path keeps it as long:
SerializationHeader has the same pattern:
If the value fits in a signed int, both give the same result. But when minLocalDeletionTime holds an invalid or capped deletion time, the delta is around 2.85e9 and does not fit in a signed int:
size path: sizeofUnsignedVInt(2852087294L) -> 5 bytes
write path: the (int) cast wraps to -1442880002, and writeUnsignedVInt32 sign-extends it -> 9 bytes
So serializedSize() returns a smaller value than the bytes actually written.
Proposed fix
Apply the same (int) cast in the size calculation, in both EncodingStats.Serializer.serializedSize() and SerializationHeader.localDeletionTimeSerializedSize(). This makes the size match the written bytes. It does not change any serialized byte, so there is no compatibility impact.
This change does not fix the root problem described below. But I think it is still clearly useful on its own, because the calculated size should always match the actual bytes written. This is why I am opening this ticket separately.
Out of scope
The written value itself does not round-trip. deserialize() reads it back with readUnsignedVInt32(), so the original value is not restored (minLocalDeletionTime comes back as -2).
Fixing this needs a change to the serialized format, which is used by both SSTables and messaging. So we would also need to handle compatibility with older versions and with data that is already written. I think the people who maintain the project over the long term should decide the policy for this, so I am leaving it out of this ticket.
patch by koo.taejin; reviewed by for CASSANDRA-21685
The Cassandra Jira