Skip to content

Commit

Permalink
Prefer replacing dead nodes with the same IP. (#1098)
Browse files Browse the repository at this point in the history
* Prefer replacing dead nodes with the same IP.

* Use reduce to clarify token acquisition logic in the existing token case.
  • Loading branch information
mattl-netflix authored Jun 7, 2024
1 parent e93d85e commit 479ae9e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,16 @@ public PriamInstance retriableCall() throws Exception {
.filter(i -> !racInstanceIds.contains(i.getInstanceId()))
.collect(Collectors.toList());
Optional<PriamInstance> candidate =
instances.stream().filter(i -> !isNew(i)).findFirst();
instances
.stream()
.filter(i -> !isNew(i))
.reduce(
(current, next) ->
myInstanceInfo
.getPrivateIP()
.equals(next.getHostIP())
? next
: current);
candidate.ifPresent(i -> replacedIp = getReplacedIpForExistingToken(allIds, i));
if (replacedIp == null) {
candidate = instances.stream().filter(i -> isNew(i)).findFirst();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,25 @@ public void testReplacementGossipMatch(@Mocked SystemUtils systemUtils) throws E
Truth.assertThat(tokenRetriever.getReplacedIp().get()).isEqualTo("127.0.0.3");
}

@Test
public void testPrioritizeDeadTokensWithSameIP(@Mocked SystemUtils systemUtils)
throws Exception {
create(0, "iid_1", "host_0", "127.0.0.1", instanceInfo.getRac(), 0 + "");
create(1, "iid_2", "host_1", "127.1.1.0", instanceInfo.getRac(), 1 + "");
new Expectations() {
{
membership.getRacMembership();
result = ImmutableSet.of();
SystemUtils.getDataFromUrl(anyString);
returns(null, null);
}
};
TokenRetriever tokenRetriever = getTokenRetriever();
Truth.assertThat(tokenRetriever.grabExistingToken().getHostIP()).isEqualTo("127.1.1.0");
Truth.assertThat(tokenRetriever.getReplacedIp().isPresent()).isTrue();
Truth.assertThat(tokenRetriever.getReplacedIp().get()).isEqualTo("127.1.1.0");
}

@Test
public void testPrioritizeDeadTokens(@Mocked SystemUtils systemUtils) throws Exception {
create(0, "iid_0", "host_0", "127.0.0.0", instanceInfo.getRac(), 0 + "");
Expand Down

0 comments on commit 479ae9e

Please sign in to comment.