Ejemplo n.º 1
0
 /// <summary>
 /// Checks to see if deployment configuration has changed, by adding or removing silos.
 /// If so, it updates the list of all silo names and creates a new resource balancer.
 /// This should occure rarely.
 /// </summary>
 /// <param name="newSiloNames">new silo names</param>
 /// <returns>bool, true if list of all silo names has changed</returns>
 private bool UpdateAllSiloNames(IList <string> newSiloNames)
 {
     // Has configured silo names changed
     if (allSiloNames.Count != newSiloNames.Count ||
         !allSiloNames.ListEquals(newSiloNames))
     {
         // record new list of all instance names
         allSiloNames = newSiloNames;
         // rebuild balancer with new list of instance names
         List <QueueId> allQueues = streamQueueMapper.GetAllQueues().ToList();
         resourceBalancer = new BestFitBalancer <string, QueueId>(allSiloNames, allQueues);
         return(true);
     }
     return(false);
 }
Ejemplo n.º 2
0
        public DeploymentBasedQueueBalancer(
            ISiloStatusOracle siloStatusOracle,
            IDeploymentConfiguration deploymentConfig,
            IStreamQueueMapper queueMapper)
        {
            if (siloStatusOracle == null)
            {
                throw new ArgumentNullException("siloStatusOracle");
            }
            if (deploymentConfig == null)
            {
                throw new ArgumentNullException("deploymentConfig");
            }
            if (queueMapper == null)
            {
                throw new ArgumentNullException("queueMapper");
            }

            this.siloStatusOracle = siloStatusOracle;
            this.deploymentConfig = deploymentConfig;
            streamQueueMapper     = queueMapper;
            queueBalanceListeners = new List <IStreamQueueBalanceListener>();
            mySiloName            = this.siloStatusOracle.SiloName;
            activeSiloNames       = new List <string>();
            allSiloNames          = this.deploymentConfig.GetAllSiloInstanceNames();
            List <QueueId> allQueues = streamQueueMapper.GetAllQueues().ToList();

            resourceBalancer = new BestFitBalancer <string, QueueId>(allSiloNames, allQueues);

            // get silo names for all active silos
            foreach (SiloAddress siloAddress in this.siloStatusOracle.GetApproximateSiloStatuses(true).Keys)
            {
                string siloName;
                if (this.siloStatusOracle.TryGetSiloName(siloAddress, out siloName))
                {
                    activeSiloNames.Add(siloName);
                }
            }

            // register for notification of changes to silo status for any silo in the cluster
            this.siloStatusOracle.SubscribeToSiloStatusEvents(this);
        }
        public override IEnumerable <QueueId> GetMyQueues()
        {
            BestFitBalancer <string, QueueId> balancer = GetBalancer();
            bool useIdealDistribution = this.options.IsFixed || isStarting;
            Dictionary <string, List <QueueId> > distribution = useIdealDistribution
                ? balancer.IdealDistribution
                : balancer.GetDistribution(GetActiveSilos(siloStatusOracle, immatureSilos));

            List <QueueId> myQueues;

            if (distribution.TryGetValue(siloStatusOracle.SiloName, out myQueues))
            {
                if (!useIdealDistribution)
                {
                    HashSet <QueueId> queuesOfImmatureSilos = GetQueuesOfImmatureSilos(siloStatusOracle, immatureSilos, balancer.IdealDistribution);
                    // filter queues that belong to immature silos
                    myQueues.RemoveAll(queue => queuesOfImmatureSilos.Contains(queue));
                }
                return(myQueues);
            }
            return(Enumerable.Empty <QueueId>());
        }