Skip to content

Commit

Permalink
Always use private IPs. (#1095)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattl-netflix authored May 20, 2024
1 parent 187143d commit 6f094b8
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1040,13 +1040,6 @@ default ImmutableSet<String> getTunablePropertyFiles() {
return ImmutableSet.of();
}

/**
* @return true to use private IPs for seeds and insertion into the Token DB false otherwise.
*/
default boolean usePrivateIP() {
return getSnitch().equals("org.apache.cassandra.locator.GossipingPropertyFileSnitch");
}

/**
* @return BackupsToCompress UNCOMPRESSED means compress backups only when the files are not
* already compressed by Cassandra
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void doubleSlots() {
new_slot + hash,
InstanceIdentity.DUMMY_INSTANCE_ID,
instanceInfo.getHostname(),
config.usePrivateIP() ? instanceInfo.getPrivateIP() : instanceInfo.getHostIP(),
instanceInfo.getPrivateIP(),
data.getRac(),
null,
token);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,11 +286,9 @@ private String getReplacedIpForExistingToken(
}

private PriamInstance claimToken(PriamInstance originalInstance) {
String hostIP =
config.usePrivateIP() ? myInstanceInfo.getPrivateIP() : myInstanceInfo.getHostIP();
if (originalInstance.getInstanceId().equals(myInstanceInfo.getInstanceId())
&& originalInstance.getHostName().equals(myInstanceInfo.getHostname())
&& originalInstance.getHostIP().equals(hostIP)
&& originalInstance.getHostIP().equals(myInstanceInfo.getPrivateIP())
&& originalInstance.getRac().equals(myInstanceInfo.getRac())) {
return originalInstance;
}
Expand All @@ -299,7 +297,7 @@ private PriamInstance claimToken(PriamInstance originalInstance) {
newInstance.setId(originalInstance.getId());
newInstance.setInstanceId(myInstanceInfo.getInstanceId());
newInstance.setHost(myInstanceInfo.getHostname());
newInstance.setHostIP(hostIP);
newInstance.setHostIP(myInstanceInfo.getPrivateIP());
newInstance.setRac(myInstanceInfo.getRac());
newInstance.setVolumes(originalInstance.getVolumes());
newInstance.setToken(originalInstance.getToken());
Expand All @@ -318,16 +316,12 @@ private PriamInstance claimToken(PriamInstance originalInstance) {

private PriamInstance createToken(int id, String token) {
try {
String hostIp =
config.usePrivateIP()
? myInstanceInfo.getPrivateIP()
: myInstanceInfo.getHostIP();
return factory.create(
config.getAppName(),
id,
myInstanceInfo.getInstanceId(),
myInstanceInfo.getHostname(),
hostIp,
myInstanceInfo.getPrivateIP(),
myInstanceInfo.getRac(),
null /* volumes */,
token);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public class FakeConfiguration implements IConfiguration {
private String roleManager = "";
private boolean mayCreateNewToken;
private ImmutableList<String> racs;
private boolean usePrivateIp;
private String diskAccessMode;
private boolean skipDeletingOthersIngressRules;
private boolean skipUpdatingOthersIngressRules;
Expand Down Expand Up @@ -235,15 +234,6 @@ public void setCreateNewToken(boolean mayCreateNewToken) {
this.mayCreateNewToken = mayCreateNewToken;
}

@Override
public boolean usePrivateIP() {
return usePrivateIp;
}

public void usePrivateIP(boolean usePrivateIp) {
this.usePrivateIp = usePrivateIp;
}

public BackupsToCompress getBackupsToCompress() {
return (BackupsToCompress)
fakeConfig.getOrDefault("Priam.backupsToCompress", BackupsToCompress.ALL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ public void testGetPreassignedTokenReplacesIfOwnerIPIsNotLive(@Mocked SystemUtil
public void testIPIsUpdatedWhenGrabbingPreassignedToken(@Mocked SystemUtils systemUtils)
throws Exception {
create(0, instanceInfo.getInstanceId(), "host_0", "1.2.3.4", "az1", 0 + "");
Truth.assertThat(getTokenRetriever().get().getHostIP()).isEqualTo("127.0.0.0");
Truth.assertThat(getTokenRetriever().get().getHostIP()).isEqualTo("127.1.1.0");
}

@Test
Expand Down

0 comments on commit 6f094b8

Please sign in to comment.