trackedServices, delegateChecks, trackedChecks, and checkRunners
should all be covered. This lock needs to be reasonably narrow and
can't use defer due to possible recursive locking concerns further
downstream from the call sites.
The source of truth is the local Nomad Agent. Any checks are not local that
have a matching prefix are removed. Changed checks are re-registered
and missing checks are re-added.
The source of truth is the local Nomad Agent. Any services not local that
have a matching prefix are removed. Changed services are re-registered
and missing services are re-added.
It's possible that a Nomad Client is heartbeating with a Nomad server that
has become issolated from the quorum of Nomad Servers. When 3x the
heartbeatTTL has been exceeded, append the Consul server list to the primary
primary server list. When the next RPCProxy rebalance occurs, there is a
chance one of the servers discovered from Consul will be in the majority.
When client reattaches to a Nomad Server in the majority, it will include
a heartbeat and will reset the TTLs *AND* will clear the primary server list
to include only values from the heartbeat.
Now the right way to register services with the Syncer is to call
`SetServices(groupName, []*services)`. This was required to allow
the Syncer to sync either the Client, Server, or Both using a
single Syncer.
This call is obsolete by a future commit that changes the canonical
source of truth to be consul.AgentServiceRegistration structs, which
means it is not necessary to construct AgentServiceRegistration
objects every time a registration is made, we just reuse the existing
object.
This has been done to allow the Server and Client to reuse the same
Syncer because the Agent may be running Client, Server, or both
simultaneously and we only want one Syncer object alive in the agent.
This attribute isn't actually an identifier because it can represent
a collection of services. Rename `serviceIdentifier` to
`serviceRegPrefix which more accurately conveys the intention of this
Syncer attribute.
While here, also rename `SetServiceIdentifier()` to `SetServiceRegPrefix()`
and `GenerateServiceIdentifier()` to `GenerateServicePrefix()`.
SyncServices() immediately attempts to sync whatever information
the process has with Consul. Previously this method would take an
argument of the exclusive list of services that should exist,
however this is not condusive to having a Nomad Client and Nomad
Server share the same consul.Syncer.
I *KNEW* I should have done this when I wrote it, but didn't want to
go back and audit the handlers to include the appropriate return
handling, but now that the code is taking shape, make this change.
Previously this would immediately default to '127.0.0.1' if the
config was set to `:some-port-number`. Now it uses the BindAddr
if available. Also, if the `port` option is set to just a port`
number (e.g. '1234'), attempt to parse the port number by itself
to allow statically configured ports to work, even when no host is
specified.
In addition to the API changing, consul.Syncer can now be signaled
to shutdown via the Shutdown() method, which will call the Run()'ing
sync task to exit gracefully.