public void SyncedRebalance() { lock (parent.rebalanceLock) { if (parent.isShuttingDown.Get()) { return; } else { for (var i = 1; i <= parent.Config.RebalanceMaxRetries; i++) { Logger.InfoFormat("begin rebalancing consumer {0} try #{1}", consumerIdString, i); var done = false; Cluster cluster = null; try { cluster = ZkUtils.GetCluster(parent.zkClient); done = this.Rebalance(cluster); } catch (Exception e) { /** occasionally, we may hit a ZK exception because the ZK state is changing while we are iterating. * For example, a ZK node can disappear between the time we get all children and the time we try to get * the value of a child. Just let this go since another rebalance will be triggered. **/ Logger.Info("Exception during rebalance", e); } Logger.InfoFormat("end rebalancing consumer {0} try #{1}", consumerIdString, i); if (done) { return; } else { /* Here the cache is at a risk of being stale. To take future rebalancing decisions correctly, we should * clear the cache */ Logger.Info("Rebalancing attempt failed. Clearing the cache before the next rebalancing operation is triggered"); } // stop all fetchers and clear all the queues to avoid Data duplication CloseFetchersForQueues(cluster, (IDictionary <string, IList <KafkaStream <TKey, TValue> > >)KafkaMessageAndMetadataStreams, parent.topicThreadIdAndQueues.Select(x => x.Value).ToList()); Thread.Sleep(parent.Config.RebalanceBackoffMs); } } } throw new ConsumerRebalanceFailedException( consumerIdString + " can't rebalance after " + parent.Config.RebalanceMaxRetries + " retries"); }