Ejemplo n.º 1
0
        public PartitionLoadBalancer(
            IPartitionController partitionController,
            ILeaseContainer leaseContainer,
            IParitionLoadBalancingStrategy partitionLoadBalancingStrategy,
            TimeSpan leaseAcquireInterval)
        {
            if (partitionController == null)
            {
                throw new ArgumentNullException(nameof(partitionController));
            }
            if (leaseContainer == null)
            {
                throw new ArgumentNullException(nameof(leaseContainer));
            }
            if (partitionLoadBalancingStrategy == null)
            {
                throw new ArgumentNullException(nameof(partitionLoadBalancingStrategy));
            }

            this.partitionController            = partitionController;
            this.leaseContainer                 = leaseContainer;
            this.partitionLoadBalancingStrategy = partitionLoadBalancingStrategy;
            this.leaseAcquireInterval           = leaseAcquireInterval;
            this.cancellationTokenSource        = new CancellationTokenSource();
        }
Ejemplo n.º 2
0
        private async Task <IPartitionManager> BuildPartitionManagerAsync(ILeaseManager leaseManager)
        {
            this.leaseDocumentClient = this.leaseDocumentClient ?? this.leaseCollectionLocation.CreateDocumentClient();

            DocumentCollection leaseCollection = await this.leaseDocumentClient.GetDocumentCollectionAsync(this.leaseCollectionLocation).ConfigureAwait(false);

            string leaseStoreCollectionLink = leaseCollection.SelfLink;

            string collectionSelfLink       = this.feedCollectionLocation.GetCollectionSelfLink();
            var    factory                  = new CheckpointerObserverFactory(this.observerFactory, this.changeFeedProcessorOptions.CheckpointFrequency);
            var    synchronizer             = new PartitionSynchronizer(this.feedDocumentClient, collectionSelfLink, leaseManager, this.changeFeedProcessorOptions.DegreeOfParallelism, this.changeFeedProcessorOptions.QueryPartitionsMaxBatchSize);
            var    leaseStore               = new LeaseStore(this.leaseDocumentClient, this.leaseCollectionLocation, this.GetLeasePrefix(), leaseStoreCollectionLink);
            var    bootstrapper             = new Bootstrapper(synchronizer, leaseStore, this.lockTime, this.sleepTime);
            var    partitionObserverFactory = new PartitionSupervisorFactory(
                factory,
                leaseManager,
                this.partitionProcessorFactory ?? new PartitionProcessorFactory(this.feedDocumentClient, this.changeFeedProcessorOptions, leaseManager, collectionSelfLink),
                this.changeFeedProcessorOptions);

            var partitionController = new PartitionController(leaseManager, partitionObserverFactory, synchronizer);

            if (this.loadBalancingStrategy == null)
            {
                this.loadBalancingStrategy = new EqualPartitionsBalancingStrategy(this.hostName, this.changeFeedProcessorOptions.MinPartitionCount, this.changeFeedProcessorOptions.MaxPartitionCount, this.changeFeedProcessorOptions.LeaseExpirationInterval);
            }

            var partitionLoadBalancer = new PartitionLoadBalancer(partitionController, leaseManager, this.loadBalancingStrategy, this.changeFeedProcessorOptions.LeaseAcquireInterval);

            return(new PartitionManager(bootstrapper, partitionController, partitionLoadBalancer));
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Sets the <see cref="IParitionLoadBalancingStrategy"/> to be used for partition load balancing
 /// </summary>
 /// <param name="strategy">The instance of <see cref="IParitionLoadBalancingStrategy"/> to use.</param>
 /// <returns>The instance of <see cref="ChangeFeedProcessorBuilder"/> to use.</returns>
 public ChangeFeedProcessorBuilder WithPartitionLoadBalancingStrategy(IParitionLoadBalancingStrategy strategy)
 {
     if (strategy == null)
     {
         throw new ArgumentNullException(nameof(strategy));
     }
     this.loadBalancingStrategy = strategy;
     return(this);
 }
        private IPartitionManager BuildPartitionManager(ILeaseStoreManager leaseStoreManager)
        {
            string feedCollectionSelfLink = this.feedCollectionLocation.GetCollectionSelfLink();
            var    factory      = new CheckpointerObserverFactory(this.observerFactory, this.changeFeedProcessorOptions.CheckpointFrequency);
            var    synchronizer = new PartitionSynchronizer(
                this.feedDocumentClient,
                feedCollectionSelfLink,
                leaseStoreManager,
                leaseStoreManager,
                this.changeFeedProcessorOptions.DegreeOfParallelism,
                this.changeFeedProcessorOptions.QueryPartitionsMaxBatchSize);
            var bootstrapper = new Bootstrapper(synchronizer, leaseStoreManager, this.lockTime, this.sleepTime);
            var partitionSuperviserFactory = new PartitionSupervisorFactory(
                factory,
                leaseStoreManager,
                this.partitionProcessorFactory ?? new PartitionProcessorFactory(this.feedDocumentClient, this.changeFeedProcessorOptions, leaseStoreManager, feedCollectionSelfLink),
                this.changeFeedProcessorOptions);

            if (this.loadBalancingStrategy == null)
            {
                this.loadBalancingStrategy = new EqualPartitionsBalancingStrategy(
                    this.HostName,
                    this.changeFeedProcessorOptions.MinPartitionCount,
                    this.changeFeedProcessorOptions.MaxPartitionCount,
                    this.changeFeedProcessorOptions.LeaseExpirationInterval);
            }

            IPartitionController partitionController = new PartitionController(leaseStoreManager, leaseStoreManager, partitionSuperviserFactory, synchronizer);

            if (this.healthMonitor == null)
            {
                this.healthMonitor = new TraceHealthMonitor();
            }

            partitionController = new HealthMonitoringPartitionControllerDecorator(partitionController, this.healthMonitor);
            var partitionLoadBalancer = new PartitionLoadBalancer(
                partitionController,
                leaseStoreManager,
                this.loadBalancingStrategy,
                this.changeFeedProcessorOptions.LeaseAcquireInterval);

            return(new PartitionManager(bootstrapper, partitionController, partitionLoadBalancer));
        }