-
Notifications
You must be signed in to change notification settings - Fork 2k
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
batch node deregistration #5784
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the compatibility issue needs addressing first and will follow up with more feedback there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be another raft message type, otherwise great start 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few questions about backwards compatibility and regression testing
nomad/state/state_store.go
Outdated
// DeleteNode deregisters a batch of nodes | ||
func (s *StateStore) DeleteNode(index uint64, nodes []string) error { | ||
if len(nodes) == 0 { | ||
return nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this potentially return an error? - It probably signifies a programmer error, as an empty node-id should previously have returned a node lookup failed error.
880ac36
to
df405e0
Compare
cfd3fa6
to
eda57a7
Compare
943bcd9
to
3cc4c64
Compare
nomad/fsm.go
Outdated
@@ -191,6 +191,8 @@ func (n *nomadFSM) Apply(log *raft.Log) interface{} { | |||
return n.applyUpsertNode(buf[1:], log.Index) | |||
case structs.NodeDeregisterRequestType: | |||
return n.applyDeregisterNode(buf[1:], log.Index) | |||
case structs.NodeDeregisterBatchRequestType: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these sorted by their value? If so, probably belong to the bottom?
nomad/structs/structs.go
Outdated
@@ -54,6 +54,7 @@ type MessageType uint8 | |||
const ( | |||
NodeRegisterRequestType MessageType = iota | |||
NodeDeregisterRequestType | |||
NodeDeregisterBatchRequestType // QUESTION does iota make it important to append this list? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes - this needs to be appended at the end. golang compiler would assign 0 to iota and then increments for subsequent lines. See https://play.golang.org/p/7ZqlecuVJHW and https://golang.org/ref/spec#Iota about iota and constants.
In raft, we store the message type uint8 in messages, so these order here must remain unaltered; otherwise, we will not interpret old raft messages properly on upgrade. Probably belongs to raft notes too.
nomad/structs/structs.go
Outdated
type NodeDeregisterRequest struct { | ||
NodeID string | ||
WriteRequest | ||
} | ||
|
||
// NodeDeregisterBatchRequest is used for Node.DeregisterBatch endpoint | ||
// to deregister a batch of nodes from being schedulable entities. | ||
type NodeDeregisterBatchRequest struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find our naming conventions here odd, Batch seems to appear inconsistently throughout the file: BatchNodeUpdateDrainRequest
, JobBatchDeregisterRequest
, and NodeDeregisterBatchRequest
:(. The same goes for the fsm method handler name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agreed. I'll rename it to avoid introducing a third pattern at least
nomad/structs/structs.go
Outdated
@@ -316,12 +317,20 @@ type NodeRegisterRequest struct { | |||
} | |||
|
|||
// NodeDeregisterRequest is used for Node.Deregister endpoint | |||
// to deregister a node as being a schedulable entity. | |||
// to deregister a batch of nodes from being schedulable entities. | |||
// Deprecated in 0.9.3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that we still use it in http agent nodePurge, we might want to qualify its deprecation and scope it to internal scheduler work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry for the many back and forth - noticed one more compatibility issue :(.
nomad/structs/structs.go
Outdated
@@ -316,12 +317,19 @@ type NodeRegisterRequest struct { | |||
} | |||
|
|||
// NodeDeregisterRequest is used for Node.Deregister endpoint | |||
// to deregister a node as being a schedulable entity. | |||
// to deregister a batch of nodes from being schedulable entities. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the comment here doesn't need to be updated
nomad/node_endpoint.go
Outdated
func (n *Node) Deregister(args *structs.NodeDeregisterRequest, reply *structs.NodeUpdateResponse) error { | ||
if done, err := n.srv.forward("Node.Deregister", args, args, reply); done { | ||
return n.BatchDeregister(&structs.NodeBatchDeregisterRequest{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we can safely forward to Node.BatchDeregister
here when servers are running mixed fleet. Consider a 0.9.4 nomad server follower workin against 0.9.3 leader: the leader wouldn't be able to handle the call.
I think it's better to leave the old endpoints untouched and only add new ones.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, that makes a lot of sense
nomad/node_endpoint.go
Outdated
if done, err := n.srv.forward("Node.Deregister", args, args, reply); done { | ||
return err | ||
} | ||
|
||
// If we're handling the request locally on the leader, operate on a batch of size 1 | ||
return n.batchDeregister(&structs.NodeBatchDeregisterRequest{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:( I don't think this is right yet. Even if we are the leader, it's not safe to use the new raft message type until we confirm that all servers are at least 0.9.4. I would suggest keeping old handling untouched without it depending on batchDeregister (module some function extraction as preferred).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm with minor stylistic suggestion. Merge away. Thank you so much for following this through.
nomad/node_endpoint.go
Outdated
// deregister takes a raftMessage closure, to support both Deregister and BatchDeregister | ||
func (n *Node) deregister(raftMessage func() (interface{}, uint64, error), | ||
args *structs.NodeBatchDeregisterRequest, | ||
reply *structs.NodeUpdateResponse) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest ordering them in the following args, reply, raftApplyFn
. It's a bit more consistent with rest of functions, and it's a bit nicer visually for the lambda function to appear last. Also, calling raftApplyFn
or applyRaftMsgFn
probably captures meaning better.
78736ae
to
4ced779
Compare
Co-Authored-By: Mahmood Ali <[email protected]>
4ced779
to
17f4951
Compare
I'm going to lock this pull request because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active contributions. |
Change node deregistration to operate on a batch of node is, partitioned into
maxIdsPerReap
slices. The user-facing API submits a batch of 1.