Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion src/java/org/apache/cassandra/hints/HintsDescriptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,40 @@ final class HintsDescriptor
*/
static int currentStorageVersion()
{
return StorageCompatibilityMode.current().storageMessagingVersion();
return hintsVersionFromMessagingVersion(StorageCompatibilityMode.current().storageMessagingVersion());
}

/**
* Translates a messaging version to the corresponding hints file version.
* This is necessary because hints versions have their own numbering scheme
* (1, 2, 3 for OSS versions 3.0, 4.0, 5.0) that differs from messaging versions.
*
* @param messagingVersion the messaging protocol version
* @return the hints file version corresponding to the messaging version
*/
@VisibleForTesting
static int hintsVersionFromMessagingVersion(int messagingVersion)
{
switch (messagingVersion)
{
case MessagingService.VERSION_30:
case MessagingService.VERSION_3014:
return VERSION_30;
case MessagingService.VERSION_40:
return VERSION_40;
case MessagingService.VERSION_50:
return VERSION_50;
case MessagingService.VERSION_DS_10:
return VERSION_DS_10;
case MessagingService.VERSION_DS_11:
return VERSION_DS_11;
case MessagingService.VERSION_DS_12:
return VERSION_DS_12;
case MessagingService.VERSION_DS_20:
return VERSION_DS_20;
default:
throw new IllegalStateException("Unknown messaging version " + messagingVersion);
}
}

@SuppressWarnings("unchecked")
Expand Down
42 changes: 42 additions & 0 deletions test/unit/org/apache/cassandra/hints/HintsDescriptorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -248,4 +248,46 @@ public void testCurrentStorageVersionCC4ReturnsVersion40()
assertEquals("CC_4 mode should produce VERSION_40 hints for rollback compatibility",
MessagingService.VERSION_40, version);
}

@Test
public void testHintsVersionFromMessagingVersion()
{
// Test that all supported messaging versions can be translated to valid hints versions
int[] messagingVersions = {
MessagingService.VERSION_30,
MessagingService.VERSION_3014,
MessagingService.VERSION_40,
MessagingService.VERSION_50,
MessagingService.VERSION_DS_10,
MessagingService.VERSION_DS_11,
MessagingService.VERSION_DS_12,
MessagingService.VERSION_DS_20
};

for (int msgVersion : messagingVersions)
{
int hintsVersion = HintsDescriptor.hintsVersionFromMessagingVersion(msgVersion);
// Verify the translated version is valid by calling messagingVersion() on it
// This will throw if the hints version is not recognized
int roundTripped = HintsDescriptor.messagingVersion(hintsVersion);
assertThat(roundTripped).as("Messaging version for hints version derived from " + msgVersion)
.isGreaterThan(0);
}
}

@Test
public void testHintsVersionFromMessagingVersionCC4Compatibility()
{
int messagingVersion = StorageCompatibilityMode.CC_4.storageMessagingVersion();
assertEquals("CC_4 should return VERSION_40 messaging version", MessagingService.VERSION_40, messagingVersion);

int hintsVersion = HintsDescriptor.hintsVersionFromMessagingVersion(messagingVersion);
assertEquals("VERSION_40 messaging version should translate to hints VERSION_40",
HintsDescriptor.VERSION_40, hintsVersion);

// Verify the hints version can be used without throwing AssertionError
int resolvedMsgVersion = HintsDescriptor.messagingVersion(hintsVersion);
assertEquals("Hints VERSION_40 should resolve back to messaging VERSION_40",
MessagingService.Version.VERSION_40.value, resolvedMsgVersion);
}
}