open-nomad/nomad/state
Luiz Aoqui 3479e2231f
core: enforce strict steps for clients reconnect (#15808)
When a Nomad client that is running an allocation with
`max_client_disconnect` set misses a heartbeat the Nomad server will
update its status to `disconnected`.

Upon reconnecting, the client will make three main RPC calls:

- `Node.UpdateStatus` is used to set the client status to `ready`.
- `Node.UpdateAlloc` is used to update the client-side information about
  allocations, such as their `ClientStatus`, task states etc.
- `Node.Register` is used to upsert the entire node information,
  including its status.

These calls are made concurrently and are also running in parallel with
the scheduler. Depending on the order they run the scheduler may end up
with incomplete data when reconciling allocations.

For example, a client disconnects and its replacement allocation cannot
be placed anywhere else, so there's a pending eval waiting for
resources.

When this client comes back the order of events may be:

1. Client calls `Node.UpdateStatus` and is now `ready`.
2. Scheduler reconciles allocations and places the replacement alloc to
   the client. The client is now assigned two allocations: the original
   alloc that is still `unknown` and the replacement that is `pending`.
3. Client calls `Node.UpdateAlloc` and updates the original alloc to
   `running`.
4. Scheduler notices too many allocs and stops the replacement.

This creates unnecessary placements or, in a different order of events,
may leave the job without any allocations running until the whole state
is updated and reconciled.

To avoid problems like this clients must update _all_ of its relevant
information before they can be considered `ready` and available for
scheduling.

To achieve this goal the RPC endpoints mentioned above have been
modified to enforce strict steps for nodes reconnecting:

- `Node.Register` does not set the client status anymore.
- `Node.UpdateStatus` sets the reconnecting client to the `initializing`
  status until it successfully calls `Node.UpdateAlloc`.

These changes are done server-side to avoid the need of additional
coordination between clients and servers. Clients are kept oblivious of
these changes and will keep making these calls as they normally would.

The verification of whether allocations have been updates is done by
storing and comparing the Raft index of the last time the client missed
a heartbeat and the last time it updated its allocations.
2023-01-25 15:53:59 -05:00
..
indexer core: add ACL token expiry state, struct, and RPC handling. (#13718) 2022-07-13 15:40:34 +02:00
paginator build: run gofmt on all go source files 2022-08-16 11:14:11 -05:00
autopilot.go autopilot: correctly return errors within state functions. (#12714) 2022-04-21 08:54:50 +02:00
autopilot_test.go ci: swap ci parallelization for unconstrained gomaxprocs 2022-03-15 12:58:52 -05:00
deployment_events_test.go ci: swap ci parallelization for unconstrained gomaxprocs 2022-03-15 12:58:52 -05:00
events.go events: add ACL binding rules to core events stream topics. (#15544) 2022-12-14 14:49:49 +01:00
events_test.go events: add ACL binding rules to core events stream topics. (#15544) 2022-12-14 14:49:49 +01:00
iterator.go
schema.go acl: add binding rule object state schema and functionality. (#15511) 2022-12-14 08:48:18 +01:00
schema_test.go ci: swap ci parallelization for unconstrained gomaxprocs 2022-03-15 12:58:52 -05:00
state_changes.go
state_store.go core: enforce strict steps for clients reconnect (#15808) 2023-01-25 15:53:59 -05:00
state_store_acl.go acl: add ACL roles to event stream topic and resolve policies. (#14923) 2022-10-20 09:43:35 +02:00
state_store_acl_binding_rule.go acl: add binding rule object state schema and functionality. (#15511) 2022-12-14 08:48:18 +01:00
state_store_acl_binding_rule_test.go bugfix: unit test for GetACLBindingRules (#15583) 2022-12-20 15:06:09 +01:00
state_store_acl_sso.go bugfix: acl sso auth methods test failures (#15512) 2022-12-09 18:47:32 +01:00
state_store_acl_sso_test.go acl: make sure there is only one default Auth Method per type (#15504) 2022-12-09 14:46:54 +01:00
state_store_acl_test.go cleanup: rename Equals to Equal for consistency (#14759) 2022-10-10 09:28:46 -05:00
state_store_oss.go gofmt all the files 2021-10-01 10:14:28 -04:00
state_store_restore.go acl: add binding rule object state schema and functionality. (#15511) 2022-12-14 08:48:18 +01:00
state_store_restore_test.go acl: add binding rule object state schema and functionality. (#15511) 2022-12-14 08:48:18 +01:00
state_store_service_regisration_test.go cleanup: rename Equals to Equal for consistency (#14759) 2022-10-10 09:28:46 -05:00
state_store_service_registration.go cleanup: rename Equals to Equal for consistency (#14759) 2022-10-10 09:28:46 -05:00
state_store_test.go core: enforce strict steps for clients reconnect (#15808) 2023-01-25 15:53:59 -05:00
state_store_variables.go cleanup: rename Equals to Equal for consistency (#14759) 2022-10-10 09:28:46 -05:00
state_store_variables_oss.go rename SecureVariables to Variables throughout 2022-08-26 16:06:24 -04:00
state_store_variables_test.go cleanup: rename Equals to Equal for consistency (#14759) 2022-10-10 09:28:46 -05:00
testing.go CSI: allow updates to volumes on re-registration (#12167) 2022-03-07 11:06:59 -05:00