Skip to content
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

Prefer replacing dead nodes with the same IP. #1098

Merged
merged 2 commits into from
Jun 7, 2024

Conversation

mattl-netflix
Copy link
Contributor

No description provided.

@@ -136,7 +136,13 @@ 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
Copy link

@clohfink clohfink Jun 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NP: Can ignore this but could do the isNew and same ip in same stream with a reduce like

    .reduce((current, next) -> {
        if (myInstanceInfo.getPrivateIP().equals(next.getHostIP())) {
            return next;
        } else if (!isNew(next) && !current.isPresent()) {
            return next;
        }
        return current;
    });```

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh the oft-neglected reduce! Though recall we are dealing with PriamInstances not Optionals so the !current.isPresent() check doesn't work as expected. Instead the logic should be:

filter(i -> !isNew(i))
.reduce(
    (current, next) ->
        myInstanceInfo.getPrivateIP().equals(next.getHostIP()) 
            ? next
            : current);

@mattl-netflix mattl-netflix merged commit 479ae9e into 4.x Jun 7, 2024
1 check passed
@mattl-netflix mattl-netflix deleted the feature/prefer_my_ip branch June 7, 2024 21:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants