Skip to content

Commit

Permalink
rolling back the changes to use gossip info while grabbing pre-assign…
Browse files Browse the repository at this point in the history
…ed and dead tokens.
  • Loading branch information
cthumuluru committed Jun 7, 2019
1 parent 6e0c0b4 commit 4794c01
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import com.netflix.priam.identity.IPriamInstanceFactory;
import com.netflix.priam.identity.PriamInstance;
import com.netflix.priam.identity.config.InstanceInfo;
import com.netflix.priam.identity.token.TokenRetrieverUtils.GossipParseException;
import com.netflix.priam.utils.Sleeper;
import java.util.List;
import java.util.Random;
Expand Down Expand Up @@ -112,29 +111,9 @@ public PriamInstance get() throws Exception {
// remove it as we marked it down...
factory.delete(priamInstance);

// find the replaced IP
try {
replacedIp =
TokenRetrieverUtils.inferTokenOwnerFromGossip(
allInstancesWithinCluster,
priamInstance.getToken(),
priamInstance.getDC());

// Lets not replace the instance if gossip info is not merging!!
if (replacedIp == null) return null;
logger.info(
"Will try to replace token: {} with replacedIp (from gossip info): {} instead of ip from Token database: {}",
priamInstance.getToken(),
replacedIp,
priamInstance.getHostIP());
} catch (GossipParseException e) {
// In case of gossip exception, fallback to IP in token database.
this.replacedIp = priamInstance.getHostIP();
logger.info(
"Will try to replace token: {} with replacedIp from Token database: {}",
priamInstance.getToken(),
priamInstance.getHostIP());
}
// use entry in the token database always.
// this can cause "can't replace live token errors.
this.replacedIp = priamInstance.getHostIP();

PriamInstance result;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ public class TokenRetrieverUtils {
public static String inferTokenOwnerFromGossip(
List<? extends PriamInstance> allIds, String token, String dc)
throws GossipParseException {
// TODO: Gossip info in some cases doesn't reflect the real C* state.
// Not using gossip info for now.
if (!useGossipInfo()) {
return null;
}

// Avoid using dead instance who we are trying to replace (duh!!)
// Avoid other regions instances to avoid communication over public ip address.
List<? extends PriamInstance> eligibleInstances =
Expand Down Expand Up @@ -100,6 +106,12 @@ public static String inferTokenOwnerFromGossip(
return null;
}

// TODO: Gossip info in some cases doesn't reflect the real C* state.
// Not using gossip info for now.
private static boolean useGossipInfo() {
return false;
}

// helper method to get the token owner IP from a Cassandra node.
private static String getIp(String host, String token) throws GossipParseException {
String response = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public void testNoReplacementNoSpotAvailable() throws Exception {
};
}

@Test
// @Test
// There is a potential slot for dead token but we are unable to replace.
public void testNoReplacementNoGossipMatch(@Mocked SystemUtils systemUtils) throws Exception {
List<PriamInstance> allInstances = getInstances(2);
Expand Down Expand Up @@ -150,7 +150,7 @@ public void testNoReplacementNoGossipMatch(@Mocked SystemUtils systemUtils) thro
};
}

@Test
// @Test
public void testReplacementGossipMatch(@Mocked SystemUtils systemUtils) throws Exception {
List<PriamInstance> allInstances = getInstances(6);
List<String> racMembership = getRacMembership(2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import junit.framework.Assert;
import mockit.Expectations;
import mockit.Mocked;
import org.junit.Test;

public class TokenRetrieverUtilsTest {
private static final String APP = "testapp";
Expand Down Expand Up @@ -47,7 +46,7 @@ public class TokenRetrieverUtilsTest {
.collect(Collectors.toList())
.toArray(new String[0]);

@Test
// @Test
public void testRetrieveTokenOwnerWhenGossipAgrees(@Mocked SystemUtils systemUtils)
throws Exception {
// updates instances with new instance owning token 4 as per token database.
Expand Down Expand Up @@ -80,7 +79,7 @@ public void testRetrieveTokenOwnerWhenGossipAgrees(@Mocked SystemUtils systemUti
}

@SuppressWarnings("unchecked")
@Test
// @Test
public void testRetrieveTokenOwnerWhenGossipDisagrees(@Mocked SystemUtils systemUtils)
throws Exception {
// updates instances with new instance owning token 4 as per token database.
Expand Down Expand Up @@ -118,7 +117,7 @@ public void testRetrieveTokenOwnerWhenGossipDisagrees(@Mocked SystemUtils system
Assert.assertEquals(null, replaceIp);
}

@Test
// @Test
public void testRetrieveTokenOwnerWhenAllHostsInGossipReturnsNull(
@Mocked SystemUtils systemUtils) throws Exception {
// updates instances with new instance owning token 4 as per token database.
Expand Down Expand Up @@ -150,7 +149,7 @@ public void testRetrieveTokenOwnerWhenAllHostsInGossipReturnsNull(
Assert.assertNull(replaceIp);
}

@Test(expected = TokenRetrieverUtils.GossipParseException.class)
// @Test(expected = TokenRetrieverUtils.GossipParseException.class)
public void testRetrieveTokenOwnerWhenAllInstancesThrowGossipParseException(
@Mocked SystemUtils systemUtils) throws TokenRetrieverUtils.GossipParseException {
// updates instances with new instance owning token 4 as per token database.
Expand Down

0 comments on commit 4794c01

Please sign in to comment.