Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SubnetAddressTranslator #2013

Open
wants to merge 1 commit into
base: 4.x
Choose a base branch
from

Conversation

jahstreet
Copy link
Contributor

@jahstreet jahstreet commented Feb 10, 2025

When running Cassandra in a private network and accessing it from outside of that private network via some kind of proxy, we have an option to use FixedHostNameAddressTranslator. But when we want to set it up in a HA way and have more control over latencies in multi-datacenter deployments, that is not enough.

This PR proposes a SubnetAddressTranslator, which translates Cassandra node IP addresses based on the match to the configured subnet IP range (CIDR notation). The assumption is that each Cassandra datacenter nodes belong to different subnets not having intersecting IP ranges, which is the usual configuration for multi-DC Kubernetes and K8ssandra, for example.

Copy link
Contributor Author

@jahstreet jahstreet left a comment

Choose a reason for hiding this comment

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

Is there any additional documentation I should update with this change?

core/pom.xml Show resolved Hide resolved
logPrefix = context.getSessionName();
this.subnetAddresses =
context.getConfig().getDefaultProfile()
.getStringList(ADDRESS_TRANSLATOR_SUBNET_ADDRESSES_OPTION).stream()
Copy link
Contributor

Choose a reason for hiding this comment

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

From what I can tell this would work this way:

advanced.address-translator
{ 
  subnet-addresses = ["100.64.0.0/15:cassandra.datacenter1.com:9042","100.66.0.0/15:cassandra.datacenter1.com:9042"]
}

One concern I have is placing multiple property values in the same string, which implies some kind of parsing. I suppose that was already the case with address:port, but would be nice to make this structured. Using : as a delimiter would also cause some problems with IPv6.

could we consider using a string map instead, e.g.:

advanced.address-translator
{ 
  subnet-addresses {
    100.64.0.0/15 = "cassandra.datacenter1.com:9042"
    100.66.0.0/15 = "cassandra.datacenter1.com:9042"
  }
}

although i suspect this might break parsing some how with a / in a key name, but I think doing something like this could make the config more human/machine readable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right about the list vs string, I've got it wrong from Spark Cassandra Connector.
WRT to a map - looks cool, lemme try it.

core/pom.xml Show resolved Hide resolved
*/
public static final String ADDRESS_TRANSLATOR_SUBNET_ADDRESSES =
"advanced.address-translator.subnet-addresses";
/**
Copy link
Contributor

Choose a reason for hiding this comment

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

small nit: add newline between field and the next field doc.

}

private static void validateSubnetsAreNotOverlapping(List<SubnetAddress> subnetAddresses) {
for (int i = 0; i < subnetAddresses.size() - 1; i++) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is good to have 👍. I imagine without this, there could be some unpredictable behavior if subnets overlap (unclear which endpoint would ultimately be used).

# - FixedHostNameAddressTranslator: translates all addresses to a specific hostname.
# - SubnetAddressTranslator: translates addresses to hostname based on the subnet matches.
Copy link
Contributor

Choose a reason for hiding this comment

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

Like advertised-hostname below, we should also add a commented out example of configuring subnet-addresses for SubnetAddressTranslator

@@ -1020,8 +1020,9 @@ datastax-java-driver {
# the package com.datastax.oss.driver.internal.core.addresstranslation.
#
# The driver provides the following implementations out of the box:
# - PassThroughAddressTranslator: returns all addresses unchanged
# - PassThroughAddressTranslator: returns all addresses unchanged.
Copy link
Contributor

Choose a reason for hiding this comment

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

In regards to your question around additional documentation needed, it would be nice to add something documenting SubnetAddressTranslator to the Address resolution docs below the EC2 Multi region section. Could be good to explain the use case for why this may be considered. If you are feeling adventurous it'd be nice to add a blurb on FixedHostNameAddressTranslator as well (I could also make an attempt at this later)

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