public async Task <BecomeCoordinatorResult> BecomeCoordinatorAsync(int currentEpoch) { try { ignoreWatches = false; await zooKeeperService.IncrementAndWatchEpochAsync(currentEpoch, this); await zooKeeperService.WatchNodesAsync(this); ResourcesZnode getResourcesRes = await zooKeeperService.GetResourcesAsync(this, null); resourcesVersion = getResourcesRes.Version; } catch (ZkStaleVersionException e) { logger.Error(clientId, "Could not become coordinator as a stale version number was used", e); return(BecomeCoordinatorResult.StaleEpoch); } catch (ZkInvalidOperationException e) { logger.Error(clientId, "Could not become coordinator as an invalid ZooKeeper operation occurred", e); return(BecomeCoordinatorResult.Error); } events.Add(CoordinatorEvent.RebalancingTriggered); return(BecomeCoordinatorResult.Ok); }
private async Task CheckForRebalancingAsync() { ResourcesZnode resources = await zooKeeperService.GetResourcesAsync(null, null); List <string> assignedResources = resources.ResourceAssignments.Assignments .Where(x => x.ClientId.Equals(clientId)) .Select(x => x.Resource) .ToList(); if (assignedResources.Any()) { events.Add(FollowerEvent.RebalancingTriggered); } }