open-nomad/client/allocrunner
Tim Gross 9ed75e1f72
client: de-duplicate alloc updates and gate during restore (#17074)
When client nodes are restarted, all allocations that have been scheduled on the
node have their modify index updated, including terminal allocations. There are
several contributing factors:

* The `allocSync` method that updates the servers isn't gated on first contact
  with the servers. This means that if a server updates the desired state while
  the client is down, the `allocSync` races with the `Node.ClientGetAlloc`
  RPC. This will typically result in the client updating the server with "running"
  and then immediately thereafter "complete".

* The `allocSync` method unconditionally sends the `Node.UpdateAlloc` RPC even
  if it's possible to assert that the server has definitely seen the client
  state. The allocrunner may queue-up updates even if we gate sending them. So
  then we end up with a race between the allocrunner updating its internal state
  to overwrite the previous update and `allocSync` sending the bogus or duplicate
  update.

This changeset adds tracking of server-acknowledged state to the
allocrunner. This state gets checked in the `allocSync` before adding the update
to the batch, and updated when `Node.UpdateAlloc` returns successfully. To
implement this we need to be able to equality-check the updates against the last
acknowledged state. We also need to add the last acknowledged state to the
client state DB, otherwise we'd drop unacknowledged updates across restarts.

The client restart test has been expanded to cover a variety of allocation
states, including allocs stopped before shutdown, allocs stopped by the server
while the client is down, and allocs that have been completely GC'd on the
server while the client is down. I've also bench tested scenarios where the task
workload is killed while the client is down, resulting in a failed restore.

Fixes #16381
2023-05-11 09:05:24 -04:00
..
interfaces [COMPLIANCE] Add Copyright and License Headers 2023-04-10 15:36:59 +00:00
state [COMPLIANCE] Add Copyright and License Headers 2023-04-10 15:36:59 +00:00
tasklifecycle [COMPLIANCE] Add Copyright and License Headers 2023-04-10 15:36:59 +00:00
taskrunner client: unveil /etc/ssh/ssh_known_hosts for artifact downloads (#17122) 2023-05-09 09:43:52 -05:00
alloc_runner.go client: de-duplicate alloc updates and gate during restore (#17074) 2023-05-11 09:05:24 -04:00
alloc_runner_hooks.go full task cleanup when alloc prerun hook fails (#17104) 2023-05-08 13:17:10 -05:00
alloc_runner_test.go client: de-duplicate alloc updates and gate during restore (#17074) 2023-05-11 09:05:24 -04:00
alloc_runner_unix_test.go [COMPLIANCE] Add Copyright and License Headers 2023-04-10 15:36:59 +00:00
allocdir_hook.go [COMPLIANCE] Add Copyright and License Headers 2023-04-10 15:36:59 +00:00
cgroup_hook.go [COMPLIANCE] Add Copyright and License Headers 2023-04-10 15:36:59 +00:00
checks_hook.go [COMPLIANCE] Add Copyright and License Headers 2023-04-10 15:36:59 +00:00
checks_hook_test.go [COMPLIANCE] Add Copyright and License Headers 2023-04-10 15:36:59 +00:00
config.go [COMPLIANCE] Add Copyright and License Headers 2023-04-10 15:36:59 +00:00
consul_grpc_sock_hook.go [COMPLIANCE] Add Copyright and License Headers 2023-04-10 15:36:59 +00:00
consul_grpc_sock_hook_test.go [COMPLIANCE] Add Copyright and License Headers 2023-04-10 15:36:59 +00:00
consul_http_sock_hook.go [COMPLIANCE] Add Copyright and License Headers 2023-04-10 15:36:59 +00:00
consul_http_sock_hook_test.go [COMPLIANCE] Add Copyright and License Headers 2023-04-10 15:36:59 +00:00
csi_hook.go Merge pull request #16836 from hashicorp/compliance/add-headers 2023-04-10 16:32:03 -07:00
csi_hook_test.go Merge pull request #16836 from hashicorp/compliance/add-headers 2023-04-10 16:32:03 -07:00
fail_hook.go full task cleanup when alloc prerun hook fails (#17104) 2023-05-08 13:17:10 -05:00
group_service_hook.go services: un-mark group services as deregistered if restart hook runs (#16905) 2023-04-24 14:24:51 -05:00
group_service_hook_test.go [COMPLIANCE] Add Copyright and License Headers 2023-04-10 15:36:59 +00:00
health_hook.go [COMPLIANCE] Add Copyright and License Headers 2023-04-10 15:36:59 +00:00
health_hook_test.go [COMPLIANCE] Add Copyright and License Headers 2023-04-10 15:36:59 +00:00
migrate_hook.go [COMPLIANCE] Add Copyright and License Headers 2023-04-10 15:36:59 +00:00
network_hook.go [COMPLIANCE] Add Copyright and License Headers 2023-04-10 15:36:59 +00:00
network_hook_test.go [COMPLIANCE] Add Copyright and License Headers 2023-04-10 15:36:59 +00:00
network_manager_linux.go allocrunner: prevent panic on network manager (#16921) 2023-04-18 13:39:13 -07:00
network_manager_linux_test.go allocrunner: prevent panic on network manager (#16921) 2023-04-18 13:39:13 -07:00
network_manager_nonlinux.go [COMPLIANCE] Add Copyright and License Headers 2023-04-10 15:36:59 +00:00
networking.go [COMPLIANCE] Add Copyright and License Headers 2023-04-10 15:36:59 +00:00
networking_bridge_linux.go [COMPLIANCE] Add Copyright and License Headers 2023-04-10 15:36:59 +00:00
networking_bridge_linux_test.go [COMPLIANCE] Add Copyright and License Headers 2023-04-10 15:36:59 +00:00
networking_cni.go [COMPLIANCE] Add Copyright and License Headers 2023-04-10 15:36:59 +00:00
networking_cni_test.go [COMPLIANCE] Add Copyright and License Headers 2023-04-10 15:36:59 +00:00
testing.go [COMPLIANCE] Add Copyright and License Headers 2023-04-10 15:36:59 +00:00
upstream_allocs_hook.go [COMPLIANCE] Add Copyright and License Headers 2023-04-10 15:36:59 +00:00