예제 #1
0
        private async Task becomeReady(LeaderOffer neighborLeaderOffer)
        {
            await dispatchEvent(ElectionEventType.READY_START).ConfigureAwait(false);

            logger.debugFormat("{0} not elected leader. Watching node:{1}", leaderOffer.NodePath,
                               neighborLeaderOffer.NodePath);

            /*
             * Make sure to pass an explicit Watcher because we could be sharing this
             * zooKeeper instance with someone else.
             */
            var stat = await ZooKeeper.existsAsync(neighborLeaderOffer.NodePath, electionWatcher).ConfigureAwait(false);

            if (stat != null)
            {
                logger.debugFormat("We're behind {0} in line and they're alive. Keeping an eye on them.",
                                   neighborLeaderOffer.NodePath);
                state = State.READY;
                await dispatchEvent(ElectionEventType.READY_COMPLETE).ConfigureAwait(false);
            }
            else
            {
                /*
                 * If the stat fails, the node has gone missing between the call to
                 * getChildren() and exists(). We need to try and become the leader.
                 */
                logger.debugFormat("We were behind {0} but it looks like they died. Back to determination.",
                                   neighborLeaderOffer.NodePath);
                await determineElectionStatus().ConfigureAwait(false);
            }
        }
예제 #2
0
        private async Task makeOffer()
        {
            state = State.OFFER;
            await dispatchEvent(ElectionEventType.OFFER_START).ConfigureAwait(false);

            leaderOffer = new LeaderOffer();

            leaderOffer.HostName = HostName;
            leaderOffer.NodePath = await ZooKeeper.createAsync(RootNodeName + "/" + "n_", HostName.UTF8getBytes(),
                                                               ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL_SEQUENTIAL).ConfigureAwait(false);

            logger.debugFormat("Created leader offer {0}", leaderOffer);

            await dispatchEvent(ElectionEventType.OFFER_COMPLETE).ConfigureAwait(false);
        }