Skip to content

Conversation

@smiklosovic
Copy link
Contributor

Thanks for sending a pull request! Here are some tips if you're new here:

  • Ensure you have added or run the appropriate tests for your PR.
  • Be sure to keep the PR description updated to reflect all changes.
  • Write your PR title to summarize what this PR proposes.
  • If possible, provide a concise example to reproduce the issue for a faster review.
  • Read our contributor guidelines
  • If you're making a documentation change, see our guide to documentation contribution

Commit messages should follow the following format:

<One sentence description, usually Jira title or CHANGES.txt summary>

<Optional lengthier description (context on patch)>

patch by <Authors>; reviewed by <Reviewers> for CASSANDRA-#####

Co-authored-by: Name1 <email1>
Co-authored-by: Name2 <email2>

The Cassandra Jira

@bschoening bschoening requested a review from Copilot November 28, 2025 23:06
@bschoening bschoening self-assigned this Nov 28, 2025
Copilot finished reviewing on behalf of bschoening November 28, 2025 23:08
@bschoening
Copy link
Contributor

@smiklosovic I don't see a PR for 5.0, only 4.1 and 4.0

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR backports CASSANDRA-19022 to the 4.1 branch, adding support for tracking direct memory in nodetool gcstats across different Java versions.

Key changes:

  • Separates handling of Java 8's totalCapacity (long) and Java 11's TOTAL_CAPACITY (AtomicLong) fields
  • Refactors the static initialization to attempt loading both field variants
  • Introduces helper methods getField() and getFieldValue() for cleaner field access

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

private static long getAllocatedDirectMemory()
{
if (BITS_TOTAL_CAPACITY == null) return -1;
long fieldValue = getFieldValue(BITS_TOTAL_CAPACITY_JAVA_8, true);
Copy link

Copilot AI Nov 28, 2025

Choose a reason for hiding this comment

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

The isAtomicLong parameter should be false for the Java 8 field. In Java 8, totalCapacity is a regular long field, not an AtomicLong. Only in Java 11 was it changed to TOTAL_CAPACITY as an AtomicLong.

This will cause a ClassCastException when running on Java 8, as the code will attempt to cast a Long to AtomicLong.

Suggested fix:

long fieldValue = getFieldValue(BITS_TOTAL_CAPACITY_JAVA_8, false);
Suggested change
long fieldValue = getFieldValue(BITS_TOTAL_CAPACITY_JAVA_8, true);
long fieldValue = getFieldValue(BITS_TOTAL_CAPACITY_JAVA_8, false);

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

bad bot! This is not true, both of them are AtomicLong, it is just in Java 8 and 11 they differ on names.

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