Skip to content

[FIXED] Server peer re-add after peer-remove #6815

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

Merged
merged 1 commit into from
Apr 24, 2025

Conversation

MauriceVanVeen
Copy link
Member

A server can be shutdown and then peer-removed from the cluster to have streams/consumers moved to a different server (if replicated), since it indicates a server will not be coming back.

However, imagine the following failover scenario/setup:

  • server X fails due to cloud/server issue
  • spin up new server Y
  • shutdown server X, and peer-remove it, stream/consumer replica moves to server Y
  • once the server X issue is resolved, restart server X
  • shutdown server Y, and peer-remove it, stream/consumer replica moves back to server X

Although it sounds straightforward enough, you'd currently need to restart ALL servers in the (super) cluster to allow server X to come back like that. This would be a hidden requirement if the server X would only come back after some months, and servers would have been upgraded/restarted already by then.

To make it more obvious/simple what happens:

  • to indicate a shutdown server is not coming back: peer-remove it
  • when the server does come back: it gets re-added automatically (no need to restart other servers at all)

Signed-off-by: Maurice van Veen [email protected]

@MauriceVanVeen MauriceVanVeen requested a review from a team as a code owner April 22, 2025 16:04
Copy link
Member

@derekcollison derekcollison left a comment

Choose a reason for hiding this comment

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

In general think this is ok. Trying to think through if a peer keeps trying to come back and we do not want it to, the time threshold may be too low?

server/raft.go Outdated
}
n.removed[peer] = struct{}{}
n.removed[peer] = time.Now().UnixNano()
Copy link
Member

Choose a reason for hiding this comment

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

Could use new access time here.

Copy link
Member Author

Choose a reason for hiding this comment

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

That feels like a pre-optimization, and don't really think it's needed. This only gets run once when a peer is removed, which shouldn't be happening often enough to need to use the new getAccessTime() in my opinion?

Copy link
Member

Choose a reason for hiding this comment

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

Not pre since we know this can affect the system (UnixNano).. You could make the map take a time vs int64, those are cheap..

Also we can not control how may times peer remove can be called per second atm.

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated to store time.Time instead

server/raft.go Outdated
}
n.removed[peer] = struct{}{}
n.removed[peer] = time.Now().UnixNano()
Copy link
Member

Choose a reason for hiding this comment

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

Same here.

@MauriceVanVeen
Copy link
Member Author

Trying to think through if a peer keeps trying to come back and we do not want it to, the time threshold may be too low?

A peer should only be removed if the server is shutdown and we want to indicate it isn't coming back. So the peer shouldn't be trying to come back in that situation?
Could up the threshold from 10s, to maybe 30s?

@MauriceVanVeen MauriceVanVeen force-pushed the maurice/peer-re-add-after-remove branch from 2a3f2f7 to 80e6d36 Compare April 23, 2025 17:32
@MauriceVanVeen
Copy link
Member Author

MauriceVanVeen commented Apr 23, 2025

Updated to use time.Time and 30s instead of 10s.

EDIT: updated to 5 minutes.

@derekcollison
Copy link
Member

Updated to use time.Time and 30s instead of 10s.

Why not like 5 minutes? Meaning what are we basing this on? Should it be configurable?

@MauriceVanVeen
Copy link
Member Author

Why not like 5 minutes? Meaning what are we basing this on? Should it be configurable?

It can be any value, but it should be short enough to be usable.
Currently you need to restart ALL servers in the (super) cluster to be able to do this. It should be easy to bring back a server within a reasonable amount of time, without needing to do a bunch of restarts.

It can be short if you shutdown a server first, and then peer-remove it.
If a server is online while you peer-remove it, it first needs to shutdown JetStream. That can take longer.

Could set it to 5 minutes. But don't think it should be much higher.

Don't think it should be made configurable, that will give a false sense of security since you'd expect a peer-removed server can't come back before that time. But.. you can restart all servers to be able to re-admit it (since n.removed is purely in-memory state), or even restart only one server and make that one the meta leader.

TLDR; does 5 minutes non-configurable sound okay?

@MauriceVanVeen MauriceVanVeen force-pushed the maurice/peer-re-add-after-remove branch from 80e6d36 to 8875c26 Compare April 23, 2025 18:02
@derekcollison
Copy link
Member

Why not like 5 minutes? Meaning what are we basing this on? Should it be configurable?

It can be any value, but it should be short enough to be usable. Currently you need to restart ALL servers in the (super) cluster to be able to do this. It should be easy to bring back a server within a reasonable amount of time, without needing to do a bunch of restarts.

It can be short if you shutdown a server first, and then peer-remove it. If a server is online while you peer-remove it, it first needs to shutdown JetStream. That can take longer.

Could set it to 5 minutes. But don't think it should be much higher.

Don't think it should be made configurable, that will give a false sense of security since you'd expect a peer-removed server can't come back before that time. But.. you can restart all servers to be able to re-admit it (since n.removed is purely in-memory state), or even restart only one server and make that one the meta leader.

TLDR; does 5 minutes non-configurable sound okay?

Could be 2 or 5. We could also add in a method to clear the removed state from the system before we bring up the server again?

@MauriceVanVeen
Copy link
Member Author

Could be 2 or 5. We could also add in a method to clear the removed state from the system before we bring up the server again?

Have changed it to 5 minutes.
Could add a method to clear the state pro-actively based on a timer. But I'd rather wait with that and spend more time while working on peer management as a whole for 2.12

@derekcollison derekcollison self-requested a review April 23, 2025 18:59
Copy link
Member

@derekcollison derekcollison left a comment

Choose a reason for hiding this comment

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

LGTM

@neilalexander neilalexander merged commit b714a2a into main Apr 24, 2025
62 of 66 checks passed
neilalexander added a commit that referenced this pull request Apr 24, 2025
Includes the following:

* #6815
* #6825
* #6827

Signed-off-by: Neil Twigg <[email protected]>
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