Comment 0 for bug 1469731

Revision history for this message
Robert Ayres (robert-ayres) wrote : Leader should probably change when removing unit

Juju version 1.23.3-trusty-amd64

I've run into an interesting situation regarding leadership election feature and relations.

As an example, imagine we're relating multiple units of an active/active database to at least one unit of another service.
The database service uses leader election features ('is-leader', 'leader-set', etc.) so the current leader will be responsible for creating credentials for non-database units the service is related to. It also shares those credentials around other database units using leader-set.
This will all work fine until you try and remove one of the units of the database service. Whether a service has a relation removed or a unit is removed, the *-relation-departed/broken hooks will fire, but crucially contain no context as to why they're firing. In the database example, if you were to remove the current unit selected as leader, that unit cannot tell within the context of the hook whether it should remove credentials for the related service (remove-relation has happened) or whether to simply ignore the hook (the leader unit is being removed but others remain).

Perhaps the simplest solution would be for the case of a unit being removed, a different unit is selected as leader before invoking its departed/broken hooks. When there is only one unit, then lack of context in this situation doesn't really matter, the same hook action will probably be taken.
Alternatively, providing some context for why a hook action is being invoked, maybe an environment variable, would work.