Class LeaderCandidateIdentity
- Namespace
- Excalibur.Dispatch.LeaderElection
- Assembly
- Excalibur.Dispatch.LeaderElection.Abstractions.dll
Resolves the candidate identity an election competes under, from the configured instance identifier or, when none was configured, from the environment.
public static class LeaderCandidateIdentity
- Inheritance
-
LeaderCandidateIdentity
- Inherited Members
Remarks
This is the single place the identity is established. It is deliberately not per-provider: the candidate identity is the value a lease holder is written from and compared against, so the whole fencing argument is stated over it, and an identity that varies by provider makes that argument provider-specific for no reason.
Why the environment is consulted here rather than in one provider. Running in a container is not a property of any particular coordination backend — any provider can run in a pod — so the container's own name for the process belongs in the shared resolver. Reading it here also makes the identity STABLE ACROSS A RESTART wherever the environment supplies one, which the generated fallback cannot be: two processes on one machine with no environment name each receive a fresh random identity, so neither can recognise its own prior tenure.
The generated fallback is a last resort and is not stable. It exists so that an election always has an identity to compete under, never as a recommended configuration. A deployment that relies on it cannot distinguish a restarted instance from a new one. The fallback is a complete 32-character GUID without separators; machine-name length cannot truncate its random component.
Methods
Resolve(string?)
Resolves the identity this candidate competes under.
public static string Resolve(string? configuredInstanceId)
Parameters
configuredInstanceIdstringThe identifier the consumer configured, or null when they configured none. Whitespace is treated as unset, because a blank value in configuration is an omission rather than a choice.
Returns
- string
The configured identifier when one was supplied; otherwise the container's own name for this process; otherwise a generated identifier that is unique but NOT stable across a restart.