From 80c1b9c13afe3b64374938a27415f29e5a0158a9 Mon Sep 17 00:00:00 2001 From: Anthony Romano Date: Thu, 30 Mar 2017 11:41:36 -0700 Subject: [PATCH] concurrency: support resuming elections if leadership already held If a client already knows it holds leadership, let it create an election object with its leadership information. --- clientv3/concurrency/election.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/clientv3/concurrency/election.go b/clientv3/concurrency/election.go index 2b5ded9cf..47f68f1b4 100644 --- a/clientv3/concurrency/election.go +++ b/clientv3/concurrency/election.go @@ -45,6 +45,16 @@ func NewElection(s *Session, pfx string) *Election { return &Election{session: s, keyPrefix: pfx + "/"} } +// ResumeElection initializes an election with a known leader. +func ResumeElection(s *Session, pfx string, leaderKey string, leaderRev int64) *Election { + return &Election{ + session: s, + leaderKey: leaderKey, + leaderRev: leaderRev, + leaderSession: s, + } +} + // Campaign puts a value as eligible for the election. It blocks until // it is elected, an error occurs, or the context is cancelled. func (e *Election) Campaign(ctx context.Context, val string) error {