Skip to content

Commit

Permalink
Set replaceip even when replacing a node with the same IP. This only …
Browse files Browse the repository at this point in the history
…works safely in versions where replace_address_first_boot is set instead of replace_address.
  • Loading branch information
mattl-netflix committed Jun 7, 2024
1 parent cbc0fac commit 0dcedbc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -224,18 +224,12 @@ private String getReplacedIpForAssignedToken(
if (inferredTokenOwnership.getTokenInformationStatus()
== TokenRetrieverUtils.InferredTokenOwnership.TokenInformationStatus.GOOD) {
Preconditions.checkNotNull(inferredTokenOwnership.getTokenInformation());
String inferredIp = inferredTokenOwnership.getTokenInformation().getIpAddress();
if (!inferredIp.equals(myInstanceInfo.getHostIP())
&& !inferredIp.equals(myInstanceInfo.getPrivateIP())) {
if (inferredTokenOwnership.getTokenInformation().isLive()) {
throw new TokenRetrieverUtils.GossipParseException(
"We have been assigned a token that C* thinks is alive. Throwing to buy time in the hopes that Gossip just needs to settle.");
}
ipToReplace = inferredIp;
logger.info(
"Priam found that the token is not alive according to Cassandra and we should start Cassandra in replace mode with replace ip: "
+ inferredIp);
if (inferredTokenOwnership.getTokenInformation().isLive()) {
throw new TokenRetrieverUtils.GossipParseException(
"We have been assigned a token that C* thinks is alive. Throwing to buy time in the hopes that Gossip just needs to settle.");
}
ipToReplace = inferredTokenOwnership.getTokenInformation().getIpAddress();
logger.info("The token is not alive per gossip. Setting replace ip to: " + ipToReplace);
} else if (inferredTokenOwnership.getTokenInformationStatus()
== TokenRetrieverUtils.InferredTokenOwnership.TokenInformationStatus
.MISMATCH
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class AssignedTokenRetrieverTest {
public static final String DEAD_APP = "testapp-dead";

@Test
public void grabAssignedTokenStartDbInBootstrapModeWhenGossipAgreesCurrentInstanceIsTokenOwner(
public void grabAssignedTokenStartDbInReplaceModeWhenGossipAgreesCurrentInstanceIsTokenOwner(
@Mocked IPriamInstanceFactory factory,
@Mocked IConfiguration config,
@Mocked IMembership membership,
Expand Down Expand Up @@ -75,7 +75,7 @@ public void grabAssignedTokenStartDbInBootstrapModeWhenGossipAgreesCurrentInstan
factory, membership, config, instanceInfo, sleeper, tokenManager);
InstanceIdentity instanceIdentity =
new InstanceIdentity(factory, membership, config, instanceInfo, tokenRetriever);
Truth.assertThat(instanceIdentity.isReplace()).isFalse();
Truth.assertThat(instanceIdentity.isReplace()).isTrue();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ public void testNewTokenGenerationMultipleInstancesWithLargetEnoughIds() throws
}

@Test
public void testPreassignedTokenNotReplacedIfPublicIPMatch(@Mocked SystemUtils systemUtils)
public void testPreassignedTokenReplacedEvenIfPublicIPMatch(@Mocked SystemUtils systemUtils)
throws Exception {
// IP in DB doesn't matter so we make it different to confirm that
create(0, instanceInfo.getInstanceId(), "host_0", "1.2.3.4", "az1", 0 + "");
Expand All @@ -330,11 +330,11 @@ public void testPreassignedTokenNotReplacedIfPublicIPMatch(@Mocked SystemUtils s
};
TokenRetriever tokenRetriever = getTokenRetriever();
tokenRetriever.get();
Truth.assertThat(tokenRetriever.getReplacedIp().isPresent()).isFalse();
Truth.assertThat(tokenRetriever.getReplacedIp().isPresent()).isTrue();
}

@Test
public void testPreassignedTokenNotReplacedIfPrivateIPMatch(@Mocked SystemUtils systemUtils)
public void testPreassignedTokenReplacedEvenIfPrivateIPMatch(@Mocked SystemUtils systemUtils)
throws Exception {
// IP in DB doesn't matter so we make it different to confirm that
create(0, instanceInfo.getInstanceId(), "host_0", "1.2.3.4", "az1", 0 + "");
Expand All @@ -356,7 +356,7 @@ public void testPreassignedTokenNotReplacedIfPrivateIPMatch(@Mocked SystemUtils
};
TokenRetriever tokenRetriever = getTokenRetriever();
tokenRetriever.get();
Truth.assertThat(tokenRetriever.getReplacedIp().isPresent()).isFalse();
Truth.assertThat(tokenRetriever.getReplacedIp().isPresent()).isTrue();
}

@Test
Expand Down

0 comments on commit 0dcedbc

Please sign in to comment.