Esempio n. 1
0
        public void HandleDataChange(ZooKeeperDataChangedEventArgs args)
        {
            int parsedLeader;
            var nodePath = args.Path;
            var nodeData = args.Data;

            Logger.Info("A partition leader or ISR list has been updated. Determining if rebalancing is necessary");
            if (!ZkUtils.TryParsePartitionLeader(nodeData, out parsedLeader))
            {
                Logger.Error("Skipping rebalancing. Failed to parse partition leader for path: " + nodePath +
                             " from ZK node");
            }
            else
            {
                if (!_partitionLeaderMap.ContainsKey(nodePath) || _partitionLeaderMap[nodePath] != parsedLeader)
                {
                    var currentLeader = _partitionLeaderMap.ContainsKey(nodePath)
                                            ? _partitionLeaderMap[nodePath].ToString()
                                            : "null";
                    Logger.Info("Performing rebalancing. Leader value for path: " + nodePath + " has changed from " +
                                currentLeader + " to " + parsedLeader);
                    _partitionLeaderMap[nodePath] = parsedLeader;
                    _rebalancer.AsyncRebalance();
                }
                else
                {
                    Logger.Info("Skipping rebalancing. Leader value for path: " + nodePath + " is " + parsedLeader +
                                " and has not changed");
                }
            }
        }
        /// <summary>
        /// Invokes subscribed handlers for ZooKeeeper data changes event
        /// </summary>
        /// <param name="e">
        /// The event data.
        /// </param>
        private void OnDataChanged(ZooKeeperDataChangedEventArgs e)
        {
            DataChangedEventItem handlers;

            this.dataChangedHandlers.TryGetValue(e.Path, out handlers);
            if (handlers == null || handlers.TotalCount == 0)
            {
                return;
            }

            try
            {
                this.Exists(e.Path, true);
                var data = this.ReadData <string>(e.Path, null, true);
                e.Data = data;
                handlers.OnDataChanged(e);
            }
            catch (KeeperException ex)
            {
                if (ex.ErrorCode == KeeperException.Code.NONODE)
                {
                    handlers.OnDataDeleted(e);
                }
                else
                {
                    throw;
                }
            }
        }
Esempio n. 3
0
 public void HandleDataDelete(ZooKeeperDataChangedEventArgs args)
 {
     Logger.Debug(args + " reach test event handler");
     this.events.Add(args);
 }
Esempio n. 4
0
 public void HandleDataDelete(ZooKeeperDataChangedEventArgs args)
 {
     _rebalancer.AsyncRebalance();
 }