mirror of
https://github.com/kemko/nomad.git
synced 2026-01-01 16:05:42 +03:00
Fixes #16517 Given a 3 Server cluster with at least 1 Client connected to Follower 1: If a NodeMeta.{Apply,Read} for the Client request is received by Follower 1 with `AllowStale = false` the Follower will forward the request to the Leader. The Leader, not being connected to the target Client, will forward the RPC to Follower 1. Follower 1, seeing AllowStale=false, will forward the request to the Leader. The Leader, not being connected to... well hoppefully you get the picture: an infinite loop occurs.
2.8 KiB
2.8 KiB
New/Updated RPC Endpoint Checklist
Prefer adding a new message to changing any existing RPC messages.
Code
-
Requeststruct and*RequestTypeconstant innomad/structs/structs.go. Append the constant, old constant values must remain unchanged -
In
nomad/fsm.go, add a dispatch case to the switch statement in(n *nomadFSM) Apply*nomadFSMmethod to decode the request and call the state method
-
State method for modifying objects in a
Txninnomad/state/state_store.gonomad/state/state_store_test.go
-
Handler for the request in
nomad/foo_endpoint.go- RPCs are resolved by matching the method name for bound structs net/rpc
- Check ACLs for security, list endpoints filter by ACL
- Register new RPC struct in
nomad/server.go - Check ACLs to enforce security
-
Wrapper for the HTTP request in
command/agent/foo_endpoint.go- Backwards compatibility requires a new endpoint, an upgraded client or server may be forwarding this request to an old server, without support for the new RPC
- RPCs triggered by an internal process may not need support
- Check ACLs as an optimization
-
Endpoint added/updated in the
nomad-openapirepository.- New endpoints will need to be configured in that repository's
generatorpackage. - Updated endpoints may require the
generatorconfiguration to change, especially if parameters or headers change. - If the accepted or returned
structschema changes, the Nomad version references ingenerator/go.modwill need to be updated. Once the version is updated, regenerate the spec and all all clients so that the new schema is reflected in the spec and thus the generated models. - If
QueryOptions,QueryMeta,WriteOptions, orWriteMetachange, thev1framework will need to updated to support the change.
- New endpoints will need to be configured in that repository's
-
nomad/core_sched.gosends many RPCsServersMeetMinimumVersionasserts that the server cluster is upgraded, so use this to guard sending the new RPC, else send the old RPC- Version must match the actual release version!
-
If implementing a Client RPC...
- Use
QueryOptionsinstead ofWriteRequestin the Request struct asWriteRequestis only for Raft writes. - Set
QueryOptions.AllowStale = truein the Server RPC forwarder to avoid an infinite loop between leaders and followers when a Client RPC is forwarded through a follower. See https://github.com/hashicorp/nomad/issues/16517
- Use