You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@cassandra.apache.org by "Suhel0328 (via GitHub)" <gi...@apache.org> on 2026/09/07 06:09:29 UTC
[PR] CASSANDRA-21417: Fix non-printable characters in Gossiper log for TOKENS [cassandra]
Suhel0328 opened a new pull request, #5124:
URL: https://github.com/apache/cassandra/pull/5124
toString() on EndpointState was printing the raw TOKENS bytes directly. TOKENS is a serialized token collection stored as an ISO-8859-1 string just to preserve the raw bytes, so printing it as text dumps non-printable control characters into gossip debug logs.
Now TOKENS renders as Value(<N tokens>,<version>), same shape as every other application state's Value(<value>,<version>). If it can't be deserialized for any reason, including a corrupt length prefix that could otherwise blow up with an OutOfMemoryError, it falls back to Value(<N undecodable bytes>,<version>) instead of printing raw bytes.
Added two tests in EndpointStateTest.java: testToStringDoesNotLeakRawTokenBytes and testToStringHandlesUndecodableTokensValue.
ant test -Dtest.name=EndpointStateTest passes, 4/4.
[CASSANDRA-21417](https://issues.apache.org/jira/browse/CASSANDRA-21417)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSANDRA-21417: Fix non-printable characters in Gossiper log for TOKENS [cassandra]
Posted by "AshenScribe (via GitHub)" <gi...@apache.org>.
AshenScribe commented on code in PR #5124:
URL: https://github.com/apache/cassandra/pull/5124#discussion_r3954257415
##########
src/java/org/apache/cassandra/gms/EndpointState.java:
##########
@@ -328,7 +331,51 @@ public CassandraVersion getReleaseVersion()
public String toString()
{
View view = ref.get();
- return "EndpointState: HeartBeatState = " + view.hbState + ", AppStateMap = " + view.applicationState + ", isAlive = " + isAlive;
+ return "EndpointState: HeartBeatState = " + view.hbState + ", AppStateMap = " + appStateMapToString(view.applicationState) + ", isAlive = " + isAlive;
+ }
+
+ /**
+ * Renders the application state map for logging/debugging purposes. This differs from the map's default
+ * toString() only in how it handles {@link ApplicationState#TOKENS}: that value is a serialized token
+ * collection stored as an ISO-8859-1-encoded string purely to round-trip the raw bytes losslessly, and is
+ * never meant to be printed as text - doing so produces unreadable, control-character-laden output
+ * (see CASSANDRA-21417). All other states are rendered normally.
+ */
+ private static String appStateMapToString(Map<ApplicationState, VersionedValue> applicationState)
Review Comment:
how about renaming to `formatAppStateMapForLogging` for a showing an explicit purpose?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSANDRA-21417: Fix non-printable characters in Gossiper log for TOKENS [cassandra]
Posted by "AshenScribe (via GitHub)" <gi...@apache.org>.
AshenScribe commented on PR #5124:
URL: https://github.com/apache/cassandra/pull/5124#issuecomment-5579364891
@Suhel0328 make the status of ticket to "Patch Available" by "Open Issue" -> "Patch Available".
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSANDRA-21417: Fix non-printable characters in Gossiper log for TOKENS [cassandra]
Posted by "Suhel0328 (via GitHub)" <gi...@apache.org>.
Suhel0328 commented on PR #5124:
URL: https://github.com/apache/cassandra/pull/5124#issuecomment-5580831649
Hi @AshenScribe, done changes as per the suggestion
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSANDRA-21417: Fix non-printable characters in Gossiper log for TOKENS [cassandra]
Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #5124:
URL: https://github.com/apache/cassandra/pull/5124#discussion_r3958312214
##########
src/java/org/apache/cassandra/gms/EndpointState.java:
##########
@@ -328,7 +332,33 @@ public CassandraVersion getReleaseVersion()
public String toString()
{
View view = ref.get();
- return "EndpointState: HeartBeatState = " + view.hbState + ", AppStateMap = " + view.applicationState + ", isAlive = " + isAlive;
+ return "EndpointState: HeartBeatState = " + view.hbState + ", AppStateMap = " + formatAppStateMapForLogging(view.applicationState) + ", isAlive = " + isAlive;
+ }
+
+ /**
+ * TOKENS is stored as an ISO-8859-1 string just to hold raw bytes, so printing it as-is dumps unreadable
+ * control characters into the logs. This renders it as a token count instead (see CASSANDRA-21417).
+ */
+ static String formatAppStateMapForLogging(Map<ApplicationState, VersionedValue> applicationState)
+ {
+ IPartitioner partitioner = DatabaseDescriptor.getPartitioner();
+ return applicationState.entrySet().stream().map(entry -> {
+ if (entry.getKey() != ApplicationState.TOKENS)
+ return entry.getKey() + "=" + entry.getValue();
+
+ final VersionedValue value = entry.getValue();
+ try
+ {
+ int numTokens = TokenSerializer.deserialize(partitioner, new DataInputStream(new ByteArrayInputStream(value.toBytes())))
Review Comment:
can you do try-with-resources? just take a look into my patch
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSANDRA-21417: Fix non-printable characters in Gossiper log for TOKENS [cassandra]
Posted by "AshenScribe (via GitHub)" <gi...@apache.org>.
AshenScribe commented on PR #5124:
URL: https://github.com/apache/cassandra/pull/5124#issuecomment-5584358138
@Suhel0328 Aah nice. it even shows TOKENS=Value(<16 tokens>,0) for a node with STATUS_WITH_PORT=BOOT as expected.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSANDRA-21417: Fix non-printable characters in Gossiper log for TOKENS [cassandra]
Posted by "AshenScribe (via GitHub)" <gi...@apache.org>.
AshenScribe commented on code in PR #5124:
URL: https://github.com/apache/cassandra/pull/5124#discussion_r3955631226
##########
src/java/org/apache/cassandra/gms/EndpointState.java:
##########
@@ -328,7 +331,33 @@ public CassandraVersion getReleaseVersion()
public String toString()
{
View view = ref.get();
- return "EndpointState: HeartBeatState = " + view.hbState + ", AppStateMap = " + view.applicationState + ", isAlive = " + isAlive;
+ return "EndpointState: HeartBeatState = " + view.hbState + ", AppStateMap = " + formatAppStateMapForLogging(view.applicationState) + ", isAlive = " + isAlive;
+ }
+
+ /**
+ * TOKENS is stored as an ISO-8859-1 string just to hold raw bytes, so printing it as-is dumps unreadable
+ * control characters into the logs. This renders it as a token count instead (see CASSANDRA-21417).
+ */
+ static String formatAppStateMapForLogging(Map<ApplicationState, VersionedValue> applicationState)
+ {
+ return applicationState.entrySet().stream().map(entry -> {
+ if (entry.getKey() != ApplicationState.TOKENS)
+ return entry.getKey() + "=" + entry.getValue();
+
+ VersionedValue value = entry.getValue();
+ try
+ {
+ int numTokens = TokenSerializer.deserialize(DatabaseDescriptor.getPartitioner(),
Review Comment:
`DatabaseDescriptor.getPartitioner()` is called for every iteration, extract it into a variable.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSANDRA-21417: Fix non-printable characters in Gossiper log for TOKENS [cassandra]
Posted by "AshenScribe (via GitHub)" <gi...@apache.org>.
AshenScribe commented on code in PR #5124:
URL: https://github.com/apache/cassandra/pull/5124#discussion_r3955660811
##########
src/java/org/apache/cassandra/gms/EndpointState.java:
##########
@@ -328,7 +331,33 @@ public CassandraVersion getReleaseVersion()
public String toString()
{
View view = ref.get();
- return "EndpointState: HeartBeatState = " + view.hbState + ", AppStateMap = " + view.applicationState + ", isAlive = " + isAlive;
+ return "EndpointState: HeartBeatState = " + view.hbState + ", AppStateMap = " + formatAppStateMapForLogging(view.applicationState) + ", isAlive = " + isAlive;
+ }
+
+ /**
+ * TOKENS is stored as an ISO-8859-1 string just to hold raw bytes, so printing it as-is dumps unreadable
+ * control characters into the logs. This renders it as a token count instead (see CASSANDRA-21417).
+ */
+ static String formatAppStateMapForLogging(Map<ApplicationState, VersionedValue> applicationState)
+ {
+ return applicationState.entrySet().stream().map(entry -> {
+ if (entry.getKey() != ApplicationState.TOKENS)
+ return entry.getKey() + "=" + entry.getValue();
+
+ VersionedValue value = entry.getValue();
+ try
+ {
+ int numTokens = TokenSerializer.deserialize(DatabaseDescriptor.getPartitioner(),
+ new DataInputStream(new ByteArrayInputStream(value.toBytes())))
+ .size();
+ return entry.getKey() + "=Value(<" + numTokens + " tokens>," + value.version + ')';
Review Comment:
`numTokens` is not used anywhere, please inline it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSANDRA-21417: Fix non-printable characters in Gossiper log for TOKENS [cassandra]
Posted by "AshenScribe (via GitHub)" <gi...@apache.org>.
AshenScribe commented on code in PR #5124:
URL: https://github.com/apache/cassandra/pull/5124#discussion_r3954443670
##########
test/unit/org/apache/cassandra/gms/EndpointStateTest.java:
##########
@@ -165,4 +168,50 @@ public void run()
assertTrue(values.containsKey(ApplicationState.INTERNAL_IP));
assertTrue(values.containsKey(ApplicationState.HOST_ID));
}
+
+ /**
+ * TOKENS is stored as a serialized token collection wrapped in an ISO-8859-1 string purely to round-trip
+ * the raw bytes losslessly, and toString() must not print that raw data (see CASSANDRA-21417).
+ */
+ @Test
+ public void testToStringDoesNotLeakRawTokenBytes()
+ {
+ List<Token> tokens = new ArrayList<>();
+ for (int i = 0; i < 16; i++)
+ tokens.add(DatabaseDescriptor.getPartitioner().getRandomToken());
+
+ HeartBeatState hb = new HeartBeatState(0);
+ EndpointState state = new EndpointState(hb);
+ VersionedValue tokensValue = valueFactory.tokens(tokens);
+ state.addApplicationState(ApplicationState.TOKENS, tokensValue);
+ state.addApplicationState(ApplicationState.RELEASE_VERSION, valueFactory.releaseVersion());
+
+ String rendered = state.toString();
+
+ assertTrue(rendered.contains("TOKENS=Value(<16 tokens>," + tokensValue.version + ')'));
+ assertFalse(rendered.contains(tokensValue.value));
+ // other states still render normally
+ assertTrue(rendered.contains("RELEASE_VERSION=Value("));
+ }
+
+ /**
Review Comment:
The current tests via EndpointState.toString() are correct, but I'd recommend extracting the app state formatting logic into a package-private method with dedicated tests.
* we are testing `toString()` which includes heartbeat state, alive status, etc.
* if toString() formatting changes for heartbeat or other fields, these tests might break even though the app state logic is fine
* test edge cases for appStateMapToString alone
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSANDRA-21417: Fix non-printable characters in Gossiper log for TOKENS [cassandra]
Posted by "AshenScribe (via GitHub)" <gi...@apache.org>.
AshenScribe commented on PR #5124:
URL: https://github.com/apache/cassandra/pull/5124#issuecomment-5584429350
+1 from my side.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSANDRA-21417: Fix non-printable characters in Gossiper log for TOKENS [cassandra]
Posted by "AshenScribe (via GitHub)" <gi...@apache.org>.
AshenScribe commented on code in PR #5124:
URL: https://github.com/apache/cassandra/pull/5124#discussion_r3954257415
##########
src/java/org/apache/cassandra/gms/EndpointState.java:
##########
@@ -328,7 +331,51 @@ public CassandraVersion getReleaseVersion()
public String toString()
{
View view = ref.get();
- return "EndpointState: HeartBeatState = " + view.hbState + ", AppStateMap = " + view.applicationState + ", isAlive = " + isAlive;
+ return "EndpointState: HeartBeatState = " + view.hbState + ", AppStateMap = " + appStateMapToString(view.applicationState) + ", isAlive = " + isAlive;
+ }
+
+ /**
+ * Renders the application state map for logging/debugging purposes. This differs from the map's default
+ * toString() only in how it handles {@link ApplicationState#TOKENS}: that value is a serialized token
+ * collection stored as an ISO-8859-1-encoded string purely to round-trip the raw bytes losslessly, and is
+ * never meant to be printed as text - doing so produces unreadable, control-character-laden output
+ * (see CASSANDRA-21417). All other states are rendered normally.
+ */
+ private static String appStateMapToString(Map<ApplicationState, VersionedValue> applicationState)
Review Comment:
Would it make sense to inline this since it's only called once? same with `tokensValueToString` function. We can include a concise inline comment and refer to this ticket.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSANDRA-21417: Fix non-printable characters in Gossiper log for TOKENS [cassandra]
Posted by "AshenScribe (via GitHub)" <gi...@apache.org>.
AshenScribe commented on PR #5124:
URL: https://github.com/apache/cassandra/pull/5124#issuecomment-5582023157
the patch looks good to me on code. but the [image](https://github.com/apache/cassandra/pull/5124#issuecomment-5580813731) is not a representative of this patch as opposed to the [image](https://issues.apache.org/jira/secure/attachment/13082608/screenshot-1.png) on jira showing the issue.
To properly verify the fix, could you please provide a log snippet that includes the TOKENS state, showing it rendered as TOKENS=Value(<N tokens>,X) instead of the raw bytes?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSANDRA-21417: Fix non-printable characters in Gossiper log for TOKENS [cassandra]
Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #5124:
URL: https://github.com/apache/cassandra/pull/5124#discussion_r3958335597
##########
src/java/org/apache/cassandra/gms/EndpointState.java:
##########
@@ -328,7 +332,33 @@ public CassandraVersion getReleaseVersion()
public String toString()
{
View view = ref.get();
- return "EndpointState: HeartBeatState = " + view.hbState + ", AppStateMap = " + view.applicationState + ", isAlive = " + isAlive;
+ return "EndpointState: HeartBeatState = " + view.hbState + ", AppStateMap = " + formatAppStateMapForLogging(view.applicationState) + ", isAlive = " + isAlive;
+ }
+
+ /**
+ * TOKENS is stored as an ISO-8859-1 string just to hold raw bytes, so printing it as-is dumps unreadable
+ * control characters into the logs. This renders it as a token count instead (see CASSANDRA-21417).
+ */
+ static String formatAppStateMapForLogging(Map<ApplicationState, VersionedValue> applicationState)
+ {
+ IPartitioner partitioner = DatabaseDescriptor.getPartitioner();
+ return applicationState.entrySet().stream().map(entry -> {
+ if (entry.getKey() != ApplicationState.TOKENS)
+ return entry.getKey() + "=" + entry.getValue();
+
+ final VersionedValue value = entry.getValue();
Review Comment:
I think all of this below is not necessary, we can just say TOKENS=Value(<hidden>) and be done with it, node deserialisation or similar.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSANDRA-21417: Fix non-printable characters in Gossiper log for TOKENS [cassandra]
Posted by "Suhel0328 (via GitHub)" <gi...@apache.org>.
Suhel0328 commented on code in PR #5124:
URL: https://github.com/apache/cassandra/pull/5124#discussion_r3955936170
##########
src/java/org/apache/cassandra/gms/EndpointState.java:
##########
@@ -328,7 +331,33 @@ public CassandraVersion getReleaseVersion()
public String toString()
{
View view = ref.get();
- return "EndpointState: HeartBeatState = " + view.hbState + ", AppStateMap = " + view.applicationState + ", isAlive = " + isAlive;
+ return "EndpointState: HeartBeatState = " + view.hbState + ", AppStateMap = " + formatAppStateMapForLogging(view.applicationState) + ", isAlive = " + isAlive;
+ }
+
+ /**
+ * TOKENS is stored as an ISO-8859-1 string just to hold raw bytes, so printing it as-is dumps unreadable
+ * control characters into the logs. This renders it as a token count instead (see CASSANDRA-21417).
+ */
+ static String formatAppStateMapForLogging(Map<ApplicationState, VersionedValue> applicationState)
+ {
+ return applicationState.entrySet().stream().map(entry -> {
+ if (entry.getKey() != ApplicationState.TOKENS)
+ return entry.getKey() + "=" + entry.getValue();
+
+ VersionedValue value = entry.getValue();
+ try
+ {
+ int numTokens = TokenSerializer.deserialize(DatabaseDescriptor.getPartitioner(),
+ new DataInputStream(new ByteArrayInputStream(value.toBytes())))
+ .size();
+ return entry.getKey() + "=Value(<" + numTokens + " tokens>," + value.version + ')';
Review Comment:
I would prefer keeping `numTokens` as a separate variable here, it clearly documents what `deserialize().size()` returns, and inlining a multi-line deserialization call directly inside string concatenation gets pretty dense to read.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSANDRA-21417: Fix non-printable characters in Gossiper log for TOKENS [cassandra]
Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #5124:
URL: https://github.com/apache/cassandra/pull/5124#discussion_r3958335597
##########
src/java/org/apache/cassandra/gms/EndpointState.java:
##########
@@ -328,7 +332,33 @@ public CassandraVersion getReleaseVersion()
public String toString()
{
View view = ref.get();
- return "EndpointState: HeartBeatState = " + view.hbState + ", AppStateMap = " + view.applicationState + ", isAlive = " + isAlive;
+ return "EndpointState: HeartBeatState = " + view.hbState + ", AppStateMap = " + formatAppStateMapForLogging(view.applicationState) + ", isAlive = " + isAlive;
+ }
+
+ /**
+ * TOKENS is stored as an ISO-8859-1 string just to hold raw bytes, so printing it as-is dumps unreadable
+ * control characters into the logs. This renders it as a token count instead (see CASSANDRA-21417).
+ */
+ static String formatAppStateMapForLogging(Map<ApplicationState, VersionedValue> applicationState)
+ {
+ IPartitioner partitioner = DatabaseDescriptor.getPartitioner();
+ return applicationState.entrySet().stream().map(entry -> {
+ if (entry.getKey() != ApplicationState.TOKENS)
+ return entry.getKey() + "=" + entry.getValue();
+
+ final VersionedValue value = entry.getValue();
Review Comment:
I think all of this below is not necessary, we can just say TOKENS=Value(<hidden>) and be done with it, node deserialisation or similar can go away, just follow https://issues.apache.org/jira/secure/attachment/12755869/10330.txt
##########
src/java/org/apache/cassandra/gms/EndpointState.java:
##########
@@ -328,7 +332,33 @@ public CassandraVersion getReleaseVersion()
public String toString()
{
View view = ref.get();
- return "EndpointState: HeartBeatState = " + view.hbState + ", AppStateMap = " + view.applicationState + ", isAlive = " + isAlive;
+ return "EndpointState: HeartBeatState = " + view.hbState + ", AppStateMap = " + formatAppStateMapForLogging(view.applicationState) + ", isAlive = " + isAlive;
+ }
+
+ /**
+ * TOKENS is stored as an ISO-8859-1 string just to hold raw bytes, so printing it as-is dumps unreadable
+ * control characters into the logs. This renders it as a token count instead (see CASSANDRA-21417).
+ */
+ static String formatAppStateMapForLogging(Map<ApplicationState, VersionedValue> applicationState)
+ {
+ IPartitioner partitioner = DatabaseDescriptor.getPartitioner();
+ return applicationState.entrySet().stream().map(entry -> {
+ if (entry.getKey() != ApplicationState.TOKENS)
+ return entry.getKey() + "=" + entry.getValue();
+
+ final VersionedValue value = entry.getValue();
Review Comment:
I think all of this below is not necessary, we can just say `TOKENS=Value(<hidden>)` and be done with it, node deserialisation or similar can go away, just follow https://issues.apache.org/jira/secure/attachment/12755869/10330.txt
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSANDRA-21417: Fix non-printable characters in Gossiper log for TOKENS [cassandra]
Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #5124:
URL: https://github.com/apache/cassandra/pull/5124#discussion_r3958312214
##########
src/java/org/apache/cassandra/gms/EndpointState.java:
##########
@@ -328,7 +332,33 @@ public CassandraVersion getReleaseVersion()
public String toString()
{
View view = ref.get();
- return "EndpointState: HeartBeatState = " + view.hbState + ", AppStateMap = " + view.applicationState + ", isAlive = " + isAlive;
+ return "EndpointState: HeartBeatState = " + view.hbState + ", AppStateMap = " + formatAppStateMapForLogging(view.applicationState) + ", isAlive = " + isAlive;
+ }
+
+ /**
+ * TOKENS is stored as an ISO-8859-1 string just to hold raw bytes, so printing it as-is dumps unreadable
+ * control characters into the logs. This renders it as a token count instead (see CASSANDRA-21417).
+ */
+ static String formatAppStateMapForLogging(Map<ApplicationState, VersionedValue> applicationState)
+ {
+ IPartitioner partitioner = DatabaseDescriptor.getPartitioner();
+ return applicationState.entrySet().stream().map(entry -> {
+ if (entry.getKey() != ApplicationState.TOKENS)
+ return entry.getKey() + "=" + entry.getValue();
+
+ final VersionedValue value = entry.getValue();
+ try
+ {
+ int numTokens = TokenSerializer.deserialize(partitioner, new DataInputStream(new ByteArrayInputStream(value.toBytes())))
Review Comment:
can you do try-with-resources? just take a look into my patch
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSANDRA-21417: Fix non-printable characters in Gossiper log for TOKENS [cassandra]
Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #5124:
URL: https://github.com/apache/cassandra/pull/5124#discussion_r3958307292
##########
src/java/org/apache/cassandra/gms/EndpointState.java:
##########
@@ -328,7 +332,33 @@ public CassandraVersion getReleaseVersion()
public String toString()
{
View view = ref.get();
- return "EndpointState: HeartBeatState = " + view.hbState + ", AppStateMap = " + view.applicationState + ", isAlive = " + isAlive;
+ return "EndpointState: HeartBeatState = " + view.hbState + ", AppStateMap = " + formatAppStateMapForLogging(view.applicationState) + ", isAlive = " + isAlive;
+ }
+
+ /**
+ * TOKENS is stored as an ISO-8859-1 string just to hold raw bytes, so printing it as-is dumps unreadable
+ * control characters into the logs. This renders it as a token count instead (see CASSANDRA-21417).
+ */
+ static String formatAppStateMapForLogging(Map<ApplicationState, VersionedValue> applicationState)
+ {
+ IPartitioner partitioner = DatabaseDescriptor.getPartitioner();
+ return applicationState.entrySet().stream().map(entry -> {
+ if (entry.getKey() != ApplicationState.TOKENS)
Review Comment:
imho just leave it like this
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSANDRA-21417: Fix non-printable characters in Gossiper log for TOKENS [cassandra]
Posted by "Suhel0328 (via GitHub)" <gi...@apache.org>.
Suhel0328 commented on PR #5124:
URL: https://github.com/apache/cassandra/pull/5124#issuecomment-5582861903
> the patch looks good to me on code. but the [image](https://github.com/apache/cassandra/pull/5124#issuecomment-5580813731) is not a representative of this patch as opposed to the [image](https://issues.apache.org/jira/secure/attachment/13082608/screenshot-1.png) on jira showing the issue.
>
> To properly verify the fix, could you please provide a log snippet that includes the TOKENS state, showing it rendered as TOKENS=Value(,X) instead of the raw bytes?
The previous screenshot did already show it correctly (last line, TOKENS=Value(<16 tokens>,35) at Gossiper.java:2406), just easy to miss in a wide capture. Here's a clearer TOKENS rendered correctly, repeated across multiple lines:
```
DEBUG [GossipStage:1] 2026-09-08T09:19:54,946 Gossiper.java:2406 - Updated epstates for /127.0.0.1:38000: EndpointState: HeartBeatState = HeartBeat: generation = 1788859185, version = 0, AppStateMap = {SCHEMA=Value(00000000-0000-0000-0000-000000000002,17), DC=Value(datacenter1,0), RACK=Value(rack1,0), RELEASE_VERSION=Value(7.0.0-SNAPSHOT,0), RPC_ADDRESS=Value(127.0.0.1,0), NET_VERSION=Value(14,5), HOST_ID=Value(6d194555-f6eb-41d0-c000-000000000002,0), TOKENS=Value(<16 tokens>,0), INTERNAL_ADDRESS_AND_PORT=Value(127.0.0.1:38000,0), NATIVE_ADDRESS_AND_PORT=Value(127.0.0.1:40042,0), STATUS_WITH_PORT=Value(BOOT,4821400658802826711,0), SSTABLE_VERSIONS=Value(big-pa,7)}, isAlive = true
DEBUG [GossipStage:1] 2026-09-08T09:19:56,513 Gossiper.java:2406 - Updated epstates for /127.0.0.1:38000: EndpointState: HeartBeatState = HeartBeat: generation = 1788859185, version = 0, AppStateMap = {SCHEMA=Value(00000000-0000-0000-0000-000000000002,21), DC=Value(datacenter1,22), RACK=Value(rack1,23), RELEASE_VERSION=Value(7.0.0-SNAPSHOT,24), RPC_ADDRESS=Value(127.0.0.1,0), NET_VERSION=Value(14,5), HOST_ID=Value(6d194555-f6eb-41d0-c000-000000000002,26), TOKENS=Value(<16 tokens>,27), INTERNAL_ADDRESS_AND_PORT=Value(127.0.0.1:38000,28), NATIVE_ADDRESS_AND_PORT=Value(127.0.0.1:40042,29), STATUS_WITH_PORT=Value(NORMAL,-9180886933987773365,30), SSTABLE_VERSIONS=Value(big-pa,7)}, isAlive = true
DEBUG [main] 2026-09-08T09:19:51,511 Gossiper.java:2079 - Gossip looks settled. {localhost/127.0.0.1:38000=EndpointState: HeartBeatState = HeartBeat: generation = 1788859185, version = 13, AppStateMap = {NET_VERSION=Value(14,5), SSTABLE_VERSIONS=Value(big-pa,7)}, isAlive = true, /127.0.0.1:37000=EndpointState: HeartBeatState = HeartBeat: generation = 1788859012, version = 218, AppStateMap = {LOAD=Value(74541.0,172), SCHEMA=Value(00000000-0000-0000-0000-000000000002,30), DC=Value(datacenter1,31), RACK=Value(rack1,32), RELEASE_VERSION=Value(7.0.0-SNAPSHOT,33), NET_VERSION=Value(14,16), HOST_ID=Value(6d194555-f6eb-41d0-c000-000000000001,35), TOKENS=Value(<16 tokens>,36), RPC_READY=Value(true,44), INTERNAL_ADDRESS_AND_PORT=Value(127.0.0.1:37000,37), NATIVE_ADDRESS_AND_PORT=Value(127.0.0.1:39042,38), STATUS_WITH_PORT=Value(NORMAL,-8773856934580577011,39), SSTABLE_VERSIONS=Value(big-pa,18)}, isAlive = true}
DEBUG [main] 2026-09-08T09:19:52,512 Gossiper.java:2079 - Gossip looks settled. {localhost/127.0.0.1:38000=EndpointState: HeartBeatState = HeartBeat: generation = 1788859185, version = 14, AppStateMap = {NET_VERSION=Value(14,5), SSTABLE_VERSIONS=Value(big-pa,7)}, isAlive = true, /127.0.0.1:37000=EndpointState: HeartBeatState = HeartBeat: generation = 1788859012, version = 219, AppStateMap = {LOAD=Value(74541.0,172), SCHEMA=Value(00000000-0000-0000-0000-000000000002,30), DC=Value(datacenter1,31), RACK=Value(rack1,32), RELEASE_VERSION=Value(7.0.0-SNAPSHOT,33), NET_VERSION=Value(14,16), HOST_ID=Value(6d194555-f6eb-41d0-c000-000000000001,35), TOKENS=Value(<16 tokens>,36), RPC_READY=Value(true,44), INTERNAL_ADDRESS_AND_PORT=Value(127.0.0.1:37000,37), NATIVE_ADDRESS_AND_PORT=Value(127.0.0.1:39042,38), STATUS_WITH_PORT=Value(NORMAL,-8773856934580577011,39), SSTABLE_VERSIONS=Value(big-pa,18)}, isAlive = true}
DEBUG [main] 2026-09-08T09:19:53,513 Gossiper.java:2079 - Gossip looks settled. {localhost/127.0.0.1:38000=EndpointState: HeartBeatState = HeartBeat: generation = 1788859185, version = 15, AppStateMap = {NET_VERSION=Value(14,5), SSTABLE_VERSIONS=Value(big-pa,7)}, isAlive = true, /127.0.0.1:37000=EndpointState: HeartBeatState = HeartBeat: generation = 1788859012, version = 220, AppStateMap = {LOAD=Value(74541.0,172), SCHEMA=Value(00000000-0000-0000-0000-000000000002,30), DC=Value(datacenter1,31), RACK=Value(rack1,32), RELEASE_VERSION=Value(7.0.0-SNAPSHOT,33), NET_VERSION=Value(14,16), HOST_ID=Value(6d194555-f6eb-41d0-c000-000000000001,35), TOKENS=Value(<16 tokens>,36), RPC_READY=Value(true,44), INTERNAL_ADDRESS_AND_PORT=Value(127.0.0.1:37000,37), NATIVE_ADDRESS_AND_PORT=Value(127.0.0.1:39042,38), STATUS_WITH_PORT=Value(NORMAL,-8773856934580577011,39), SSTABLE_VERSIONS=Value(big-pa,18)}, isAlive = true}
```
Both call sites (2406 and 2079) show TOKENS=Value(<16 tokens>,X) instead of raw bytes across all 5 lines here, from two separate real nodes gossiping with each other.
<img width="1850" height="420" alt="image" src="https://github.com/user-attachments/assets/a92d79e5-fcc1-4fe7-8874-07f2b69db238" />
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSANDRA-21417: Fix non-printable characters in Gossiper log for TOKENS [cassandra]
Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #5124:
URL: https://github.com/apache/cassandra/pull/5124#discussion_r3958335597
##########
src/java/org/apache/cassandra/gms/EndpointState.java:
##########
@@ -328,7 +332,33 @@ public CassandraVersion getReleaseVersion()
public String toString()
{
View view = ref.get();
- return "EndpointState: HeartBeatState = " + view.hbState + ", AppStateMap = " + view.applicationState + ", isAlive = " + isAlive;
+ return "EndpointState: HeartBeatState = " + view.hbState + ", AppStateMap = " + formatAppStateMapForLogging(view.applicationState) + ", isAlive = " + isAlive;
+ }
+
+ /**
+ * TOKENS is stored as an ISO-8859-1 string just to hold raw bytes, so printing it as-is dumps unreadable
+ * control characters into the logs. This renders it as a token count instead (see CASSANDRA-21417).
+ */
+ static String formatAppStateMapForLogging(Map<ApplicationState, VersionedValue> applicationState)
+ {
+ IPartitioner partitioner = DatabaseDescriptor.getPartitioner();
+ return applicationState.entrySet().stream().map(entry -> {
+ if (entry.getKey() != ApplicationState.TOKENS)
+ return entry.getKey() + "=" + entry.getValue();
+
+ final VersionedValue value = entry.getValue();
Review Comment:
I think all of this below is not necessary, we can just say `TOKENS=Value(<hidden>)` and be done with it, no deserialisation or similar can go away, just follow https://issues.apache.org/jira/secure/attachment/12755869/10330.txt
##########
src/java/org/apache/cassandra/gms/EndpointState.java:
##########
@@ -328,7 +332,33 @@ public CassandraVersion getReleaseVersion()
public String toString()
{
View view = ref.get();
- return "EndpointState: HeartBeatState = " + view.hbState + ", AppStateMap = " + view.applicationState + ", isAlive = " + isAlive;
+ return "EndpointState: HeartBeatState = " + view.hbState + ", AppStateMap = " + formatAppStateMapForLogging(view.applicationState) + ", isAlive = " + isAlive;
+ }
+
+ /**
+ * TOKENS is stored as an ISO-8859-1 string just to hold raw bytes, so printing it as-is dumps unreadable
+ * control characters into the logs. This renders it as a token count instead (see CASSANDRA-21417).
+ */
+ static String formatAppStateMapForLogging(Map<ApplicationState, VersionedValue> applicationState)
+ {
+ IPartitioner partitioner = DatabaseDescriptor.getPartitioner();
+ return applicationState.entrySet().stream().map(entry -> {
+ if (entry.getKey() != ApplicationState.TOKENS)
+ return entry.getKey() + "=" + entry.getValue();
+
+ final VersionedValue value = entry.getValue();
Review Comment:
I think all of this below is not necessary, we can just say `TOKENS=Value(<hidden>)` and be done with it, no deserialisation or similar, that can go away, just follow https://issues.apache.org/jira/secure/attachment/12755869/10330.txt
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSANDRA-21417: Fix non-printable characters in Gossiper log for TOKENS [cassandra]
Posted by "Suhel0328 (via GitHub)" <gi...@apache.org>.
Suhel0328 commented on PR #5124:
URL: https://github.com/apache/cassandra/pull/5124#issuecomment-5580813731
Here is the screenshot of logs after the change:
<img width="1848" height="387" alt="Screenshot from 2026-09-08 12-28-30" src="https://github.com/user-attachments/assets/2b297b11-699f-4bc2-b89e-4129f64ea1fd" />
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSANDRA-21417: Fix non-printable characters in Gossiper log for TOKENS [cassandra]
Posted by "Suhel0328 (via GitHub)" <gi...@apache.org>.
Suhel0328 commented on code in PR #5124:
URL: https://github.com/apache/cassandra/pull/5124#discussion_r3955925042
##########
src/java/org/apache/cassandra/gms/EndpointState.java:
##########
@@ -328,7 +331,33 @@ public CassandraVersion getReleaseVersion()
public String toString()
{
View view = ref.get();
- return "EndpointState: HeartBeatState = " + view.hbState + ", AppStateMap = " + view.applicationState + ", isAlive = " + isAlive;
+ return "EndpointState: HeartBeatState = " + view.hbState + ", AppStateMap = " + formatAppStateMapForLogging(view.applicationState) + ", isAlive = " + isAlive;
+ }
+
+ /**
+ * TOKENS is stored as an ISO-8859-1 string just to hold raw bytes, so printing it as-is dumps unreadable
+ * control characters into the logs. This renders it as a token count instead (see CASSANDRA-21417).
+ */
+ static String formatAppStateMapForLogging(Map<ApplicationState, VersionedValue> applicationState)
+ {
+ return applicationState.entrySet().stream().map(entry -> {
+ if (entry.getKey() != ApplicationState.TOKENS)
+ return entry.getKey() + "=" + entry.getValue();
+
+ VersionedValue value = entry.getValue();
+ try
+ {
+ int numTokens = TokenSerializer.deserialize(DatabaseDescriptor.getPartitioner(),
Review Comment:
Extracted partitioner into a local variable before the stream loop.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSANDRA-21417: Fix non-printable characters in Gossiper log for TOKENS [cassandra]
Posted by "AshenScribe (via GitHub)" <gi...@apache.org>.
AshenScribe commented on code in PR #5124:
URL: https://github.com/apache/cassandra/pull/5124#discussion_r3954298051
##########
src/java/org/apache/cassandra/gms/EndpointState.java:
##########
@@ -328,7 +331,51 @@ public CassandraVersion getReleaseVersion()
public String toString()
{
View view = ref.get();
- return "EndpointState: HeartBeatState = " + view.hbState + ", AppStateMap = " + view.applicationState + ", isAlive = " + isAlive;
+ return "EndpointState: HeartBeatState = " + view.hbState + ", AppStateMap = " + appStateMapToString(view.applicationState) + ", isAlive = " + isAlive;
+ }
+
+ /**
+ * Renders the application state map for logging/debugging purposes. This differs from the map's default
+ * toString() only in how it handles {@link ApplicationState#TOKENS}: that value is a serialized token
+ * collection stored as an ISO-8859-1-encoded string purely to round-trip the raw bytes losslessly, and is
+ * never meant to be printed as text - doing so produces unreadable, control-character-laden output
+ * (see CASSANDRA-21417). All other states are rendered normally.
+ */
+ private static String appStateMapToString(Map<ApplicationState, VersionedValue> applicationState)
+ {
+ StringBuilder sb = new StringBuilder("{");
+ boolean first = true;
+ for (Map.Entry<ApplicationState, VersionedValue> entry : applicationState.entrySet())
+ {
+ if (!first)
+ sb.append(", ");
+ first = false;
+
+ sb.append(entry.getKey()).append('=');
+ if (entry.getKey() == ApplicationState.TOKENS)
+ sb.append(tokensValueToString(entry.getValue()));
+ else
+ sb.append(entry.getValue());
+ }
+ return sb.append('}').toString();
Review Comment:
wondering if we can use Streams API here.
##########
test/unit/org/apache/cassandra/gms/EndpointStateTest.java:
##########
@@ -165,4 +168,50 @@ public void run()
assertTrue(values.containsKey(ApplicationState.INTERNAL_IP));
assertTrue(values.containsKey(ApplicationState.HOST_ID));
}
+
+ /**
+ * TOKENS is stored as a serialized token collection wrapped in an ISO-8859-1 string purely to round-trip
+ * the raw bytes losslessly, and toString() must not print that raw data (see CASSANDRA-21417).
+ */
+ @Test
+ public void testToStringDoesNotLeakRawTokenBytes()
+ {
+ List<Token> tokens = new ArrayList<>();
+ for (int i = 0; i < 16; i++)
+ tokens.add(DatabaseDescriptor.getPartitioner().getRandomToken());
+
+ HeartBeatState hb = new HeartBeatState(0);
+ EndpointState state = new EndpointState(hb);
+ VersionedValue tokensValue = valueFactory.tokens(tokens);
+ state.addApplicationState(ApplicationState.TOKENS, tokensValue);
+ state.addApplicationState(ApplicationState.RELEASE_VERSION, valueFactory.releaseVersion());
+
+ String rendered = state.toString();
+
+ assertTrue(rendered.contains("TOKENS=Value(<16 tokens>," + tokensValue.version + ')'));
+ assertFalse(rendered.contains(tokensValue.value));
+ // other states still render normally
+ assertTrue(rendered.contains("RELEASE_VERSION=Value("));
+ }
+
+ /**
+ * If the TOKENS value can't be deserialized for some reason, toString() must still avoid printing the
+ * raw bytes rather than throwing. Uses a truncated-but-otherwise-valid length-prefixed token blob (claims
+ * a 5 byte token but only supplies 2) so deserialization fails with a plain EOFException, rather than
+ * arbitrary garbage bytes whose first 4 bytes can decode to a huge length prefix and make
+ * TokenSerializer attempt a multi-gigabyte array allocation (see CASSANDRA-21417 discussion).
+ */
+ @Test
+ public void testToStringHandlesUndecodableTokensValue()
Review Comment:
is this function's name self-explanatory? does it need the above comment?
##########
test/unit/org/apache/cassandra/gms/EndpointStateTest.java:
##########
@@ -165,4 +168,50 @@ public void run()
assertTrue(values.containsKey(ApplicationState.INTERNAL_IP));
assertTrue(values.containsKey(ApplicationState.HOST_ID));
}
+
+ /**
+ * TOKENS is stored as a serialized token collection wrapped in an ISO-8859-1 string purely to round-trip
+ * the raw bytes losslessly, and toString() must not print that raw data (see CASSANDRA-21417).
+ */
+ @Test
+ public void testToStringDoesNotLeakRawTokenBytes()
Review Comment:
how about renaming to `testToStringSummarizesTokensInsteadOfPrintingRawBinaryData`, is it self-containing?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSANDRA-21417: Fix non-printable characters in Gossiper log for TOKENS [cassandra]
Posted by "AshenScribe (via GitHub)" <gi...@apache.org>.
AshenScribe commented on code in PR #5124:
URL: https://github.com/apache/cassandra/pull/5124#discussion_r3955657115
##########
src/java/org/apache/cassandra/gms/EndpointState.java:
##########
@@ -328,7 +331,33 @@ public CassandraVersion getReleaseVersion()
public String toString()
{
View view = ref.get();
- return "EndpointState: HeartBeatState = " + view.hbState + ", AppStateMap = " + view.applicationState + ", isAlive = " + isAlive;
+ return "EndpointState: HeartBeatState = " + view.hbState + ", AppStateMap = " + formatAppStateMapForLogging(view.applicationState) + ", isAlive = " + isAlive;
+ }
+
+ /**
+ * TOKENS is stored as an ISO-8859-1 string just to hold raw bytes, so printing it as-is dumps unreadable
+ * control characters into the logs. This renders it as a token count instead (see CASSANDRA-21417).
+ */
+ static String formatAppStateMapForLogging(Map<ApplicationState, VersionedValue> applicationState)
+ {
+ return applicationState.entrySet().stream().map(entry -> {
+ if (entry.getKey() != ApplicationState.TOKENS)
+ return entry.getKey() + "=" + entry.getValue();
+
+ VersionedValue value = entry.getValue();
Review Comment:
can you make `VersionedValue value` final?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSANDRA-21417: Fix non-printable characters in Gossiper log for TOKENS [cassandra]
Posted by "AshenScribe (via GitHub)" <gi...@apache.org>.
AshenScribe commented on code in PR #5124:
URL: https://github.com/apache/cassandra/pull/5124#discussion_r3955660811
##########
src/java/org/apache/cassandra/gms/EndpointState.java:
##########
@@ -328,7 +331,33 @@ public CassandraVersion getReleaseVersion()
public String toString()
{
View view = ref.get();
- return "EndpointState: HeartBeatState = " + view.hbState + ", AppStateMap = " + view.applicationState + ", isAlive = " + isAlive;
+ return "EndpointState: HeartBeatState = " + view.hbState + ", AppStateMap = " + formatAppStateMapForLogging(view.applicationState) + ", isAlive = " + isAlive;
+ }
+
+ /**
+ * TOKENS is stored as an ISO-8859-1 string just to hold raw bytes, so printing it as-is dumps unreadable
+ * control characters into the logs. This renders it as a token count instead (see CASSANDRA-21417).
+ */
+ static String formatAppStateMapForLogging(Map<ApplicationState, VersionedValue> applicationState)
+ {
+ return applicationState.entrySet().stream().map(entry -> {
+ if (entry.getKey() != ApplicationState.TOKENS)
+ return entry.getKey() + "=" + entry.getValue();
+
+ VersionedValue value = entry.getValue();
+ try
+ {
+ int numTokens = TokenSerializer.deserialize(DatabaseDescriptor.getPartitioner(),
+ new DataInputStream(new ByteArrayInputStream(value.toBytes())))
+ .size();
+ return entry.getKey() + "=Value(<" + numTokens + " tokens>," + value.version + ')';
Review Comment:
`numTokens` is not used anywhere except once, please inline it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSANDRA-21417: Fix non-printable characters in Gossiper log for TOKENS [cassandra]
Posted by "AshenScribe (via GitHub)" <gi...@apache.org>.
AshenScribe commented on PR #5124:
URL: https://github.com/apache/cassandra/pull/5124#issuecomment-5579356152
@Suhel0328 can you put a picture of the logs verifying the change on ticket?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSANDRA-21417: Fix non-printable characters in Gossiper log for TOKENS [cassandra]
Posted by "Suhel0328 (via GitHub)" <gi...@apache.org>.
Suhel0328 commented on code in PR #5124:
URL: https://github.com/apache/cassandra/pull/5124#discussion_r3955927724
##########
src/java/org/apache/cassandra/gms/EndpointState.java:
##########
@@ -328,7 +331,33 @@ public CassandraVersion getReleaseVersion()
public String toString()
{
View view = ref.get();
- return "EndpointState: HeartBeatState = " + view.hbState + ", AppStateMap = " + view.applicationState + ", isAlive = " + isAlive;
+ return "EndpointState: HeartBeatState = " + view.hbState + ", AppStateMap = " + formatAppStateMapForLogging(view.applicationState) + ", isAlive = " + isAlive;
+ }
+
+ /**
+ * TOKENS is stored as an ISO-8859-1 string just to hold raw bytes, so printing it as-is dumps unreadable
+ * control characters into the logs. This renders it as a token count instead (see CASSANDRA-21417).
+ */
+ static String formatAppStateMapForLogging(Map<ApplicationState, VersionedValue> applicationState)
+ {
+ return applicationState.entrySet().stream().map(entry -> {
+ if (entry.getKey() != ApplicationState.TOKENS)
+ return entry.getKey() + "=" + entry.getValue();
+
+ VersionedValue value = entry.getValue();
Review Comment:
Added `final`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSANDRA-21417: Fix non-printable characters in Gossiper log for TOKENS [cassandra]
Posted by "AshenScribe (via GitHub)" <gi...@apache.org>.
AshenScribe commented on code in PR #5124:
URL: https://github.com/apache/cassandra/pull/5124#discussion_r3957416816
##########
src/java/org/apache/cassandra/gms/EndpointState.java:
##########
@@ -328,7 +332,33 @@ public CassandraVersion getReleaseVersion()
public String toString()
{
View view = ref.get();
- return "EndpointState: HeartBeatState = " + view.hbState + ", AppStateMap = " + view.applicationState + ", isAlive = " + isAlive;
+ return "EndpointState: HeartBeatState = " + view.hbState + ", AppStateMap = " + formatAppStateMapForLogging(view.applicationState) + ", isAlive = " + isAlive;
+ }
+
+ /**
+ * TOKENS is stored as an ISO-8859-1 string just to hold raw bytes, so printing it as-is dumps unreadable
+ * control characters into the logs. This renders it as a token count instead (see CASSANDRA-21417).
+ */
+ static String formatAppStateMapForLogging(Map<ApplicationState, VersionedValue> applicationState)
+ {
+ IPartitioner partitioner = DatabaseDescriptor.getPartitioner();
+ return applicationState.entrySet().stream().map(entry -> {
+ if (entry.getKey() != ApplicationState.TOKENS)
Review Comment:
@smiklosovic as `ApplicationState.TOKENS` is "deprecated since version CEP-21", is there an alternate way?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSANDRA-21417: Fix non-printable characters in Gossiper log for TOKENS [cassandra]
Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic closed pull request #5124: CASSANDRA-21417: Fix non-printable characters in Gossiper log for TOKENS
URL: https://github.com/apache/cassandra/pull/5124
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org
Re: [PR] CASSANDRA-21417: Fix non-printable characters in Gossiper log for TOKENS [cassandra]
Posted by "Suhel0328 (via GitHub)" <gi...@apache.org>.
Suhel0328 commented on code in PR #5124:
URL: https://github.com/apache/cassandra/pull/5124#discussion_r3959336775
##########
src/java/org/apache/cassandra/gms/EndpointState.java:
##########
@@ -328,7 +332,33 @@ public CassandraVersion getReleaseVersion()
public String toString()
{
View view = ref.get();
- return "EndpointState: HeartBeatState = " + view.hbState + ", AppStateMap = " + view.applicationState + ", isAlive = " + isAlive;
+ return "EndpointState: HeartBeatState = " + view.hbState + ", AppStateMap = " + formatAppStateMapForLogging(view.applicationState) + ", isAlive = " + isAlive;
+ }
+
+ /**
+ * TOKENS is stored as an ISO-8859-1 string just to hold raw bytes, so printing it as-is dumps unreadable
+ * control characters into the logs. This renders it as a token count instead (see CASSANDRA-21417).
+ */
+ static String formatAppStateMapForLogging(Map<ApplicationState, VersionedValue> applicationState)
+ {
+ IPartitioner partitioner = DatabaseDescriptor.getPartitioner();
+ return applicationState.entrySet().stream().map(entry -> {
+ if (entry.getKey() != ApplicationState.TOKENS)
+ return entry.getKey() + "=" + entry.getValue();
+
+ final VersionedValue value = entry.getValue();
Review Comment:
Updated! Removed the deserialization logic entirely and formatted TOKENS as `Value(<hidden>)` when present, or not present when missing, aligning directly with CASSANDRA-10330.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org