Skip to content

putShortVolatile is not volatile in InMemoryTrie#4820

Open
frankgh wants to merge 3 commits into
apache:trunkfrom
frankgh:CASSANDRA-21353
Open

putShortVolatile is not volatile in InMemoryTrie#4820
frankgh wants to merge 3 commits into
apache:trunkfrom
frankgh:CASSANDRA-21353

Conversation

@frankgh

@frankgh frankgh commented May 18, 2026

Copy link
Copy Markdown
Contributor

This commit fixes several issues found using the cassandra edge case explorer skill for the BTI feature. The majority are small findings.

Patch by Francisco Guerrero; reviewed by TBD for CASSANDRA-21353

This commit fixes several issues found using the Cassandra
edge case explorer skill for the BTI feature. The majority are
small findings.

Patch by Francisco Guerrero; reviewed by TBD for CASSANDRA-21353
final void putShortVolatile(int pos, short value)
{
getChunk(pos).putShort(inChunkPointer(pos), value);
getChunk(pos).putShortVolatile(inChunkPointer(pos), value);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

potentially a copy-paste bug

ensuringInBuildInternalContext(operationType),
getIOOptions().flushCompression,
getCompressionDictionaryManager());
dataWriterOpened = true;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is missing setting dataWriterOpened. This doesn't seem to have any functional issues at the moment, but adding the fix for completeness

{
sstable.markSuspect();

if (reader != null)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when an exception occurs, we have a reader that might not get closed properly

// Follow end position while we still have a prefix, stacking path.
go(root);
while (true)
try

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is conforming to the implementation in org.apache.cassandra.io.tries.ValueIterator#initializeWithLeftBound

@iamaleksey iamaleksey self-requested a review June 9, 2026 13:29

@iamaleksey iamaleksey left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR looks good, and does what it says it does, and doesn't introduce any new (non-latent) issues, but there are a few things that can be tightened up.

@@ -140,6 +144,19 @@ protected AbstractSSTableIterator(SSTableReader sstable,
catch (IOException e)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UnfilteredValidation.handleInvalid() can throw a CorruptSSTableException which is an RTE so it wouldn't be caught here and we'd still have a leak.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point, I'm thinking of handling both CorruptSSTableException | IOException. For the CorruptSSTableException case we rethrow after closing.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, both here and for ValueIterator it would probably be better to wrap the entire if-else block in the constructors. So that if e.g. limit.next() call throws, we still clean up. It would also reduce the visual nesting where it matters more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This minimizes the diff, but it actually makes more sense to handle it at the contractor instead

@iamaleksey iamaleksey left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with the extra commits 👍

On commit though, can you take a look at the other constructors of ValueIterator / ReverseValueIterator and ensure they also can't leak?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants