-
Notifications
You must be signed in to change notification settings - Fork 885
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
base: 4.x
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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?
logPrefix = context.getSessionName(); | ||
this.subnetAddresses = | ||
context.getConfig().getDefaultProfile() | ||
.getStringList(ADDRESS_TRANSLATOR_SUBNET_ADDRESSES_OPTION).stream() |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
...n/java/com/datastax/oss/driver/internal/core/addresstranslation/SubnetAddressTranslator.java
Show resolved
Hide resolved
...n/java/com/datastax/oss/driver/internal/core/addresstranslation/SubnetAddressTranslator.java
Show resolved
Hide resolved
*/ | ||
public static final String ADDRESS_TRANSLATOR_SUBNET_ADDRESSES = | ||
"advanced.address-translator.subnet-addresses"; | ||
/** |
There was a problem hiding this comment.
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.
...n/java/com/datastax/oss/driver/internal/core/addresstranslation/SubnetAddressTranslator.java
Show resolved
Hide resolved
...n/java/com/datastax/oss/driver/internal/core/addresstranslation/SubnetAddressTranslator.java
Show resolved
Hide resolved
} | ||
|
||
private static void validateSubnetsAreNotOverlapping(List<SubnetAddress> subnetAddresses) { | ||
for (int i = 0; i < subnetAddresses.size() - 1; i++) { |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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)
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.