Exemplo n.º 1
0
 /// <summary>
 /// Create stream queue balancer by type requested
 /// </summary>
 /// <param name="balancerType">queue balancer type to create</param>
 /// <param name="strProviderName">name of requesting stream provider</param>
 /// <param name="siloStatusOracle">membership services interface.</param>
 /// <param name="clusterConfiguration">cluster configuration</param>
 /// <param name="runtime">stream provider runtime environment to run in</param>
 /// <param name="queueMapper">queue mapper of requesting stream provider</param>
 /// <param name="siloMaturityPeriod">Maturity Period of a silo for queue rebalancing purposes</param>
 /// <returns>Constructed stream queue balancer</returns>
 public static IStreamQueueBalancer Create(
     StreamQueueBalancerType balancerType,
     string strProviderName,
     ISiloStatusOracle siloStatusOracle,
     ClusterConfiguration clusterConfiguration,
     IStreamProviderRuntime runtime,
     IStreamQueueMapper queueMapper,
     TimeSpan siloMaturityPeriod)
 {
     if (string.IsNullOrWhiteSpace(strProviderName))
     {
         throw new ArgumentNullException("strProviderName");
     }
     if (siloStatusOracle == null)
     {
         throw new ArgumentNullException("siloStatusOracle");
     }
     if (clusterConfiguration == null)
     {
         throw new ArgumentNullException("clusterConfiguration");
     }
     if (runtime == null)
     {
         throw new ArgumentNullException("runtime");
     }
     if (queueMapper == null)
     {
         throw new ArgumentNullException("queueMapper");
     }
     bool isFixed;
     switch (balancerType)
     {
         case StreamQueueBalancerType.ConsistentRingBalancer:
         {
             // Consider: for now re-use the same ConsistentRingProvider with 1 equally devided range. Remove later.
             IConsistentRingProviderForGrains ringProvider = runtime.GetConsistentRingProvider(0, 1);
             return new ConsistentRingQueueBalancer(ringProvider, queueMapper);
         }
         case StreamQueueBalancerType.DynamicAzureDeploymentBalancer:
         case StreamQueueBalancerType.StaticAzureDeploymentBalancer:
         {
             Logger logger = LogManager.GetLogger(typeof(StreamQueueBalancerFactory).Name, LoggerType.Runtime);
             var wrapper = AssemblyLoader.LoadAndCreateInstance<IDeploymentConfiguration>(Constants.ORLEANS_AZURE_UTILS_DLL, logger);
             isFixed = balancerType == StreamQueueBalancerType.StaticAzureDeploymentBalancer;
             return new DeploymentBasedQueueBalancer(siloStatusOracle, wrapper, queueMapper, siloMaturityPeriod, isFixed);
         }
         case StreamQueueBalancerType.DynamicClusterConfigDeploymentBalancer:
         case StreamQueueBalancerType.StaticClusterConfigDeploymentBalancer:
         {
             IDeploymentConfiguration deploymentConfiguration = new StaticClusterDeploymentConfiguration(clusterConfiguration);
             isFixed = balancerType == StreamQueueBalancerType.StaticClusterConfigDeploymentBalancer;
             return new DeploymentBasedQueueBalancer(siloStatusOracle, deploymentConfiguration, queueMapper, siloMaturityPeriod, isFixed);
         }
         default:
         {
             string error = string.Format("Unsupported balancerType for stream provider. BalancerType: {0}, StreamProvider: {1}", balancerType, strProviderName);
             throw new ArgumentOutOfRangeException("balancerType", error);
         }
     }
 }
Exemplo n.º 2
0
        public SiloProviderRuntime(
            SiloInitializationParameters siloDetails,
            GlobalConfiguration config,
            IConsistentRingProvider consistentRingProvider,
            ISiloRuntimeClient runtimeClient,
            ImplicitStreamSubscriberTable implicitStreamSubscriberTable,
            ISiloStatusOracle siloStatusOracle,
            OrleansTaskScheduler scheduler,
            ActivationDirectory activationDirectory)
        {
            this.siloDetails            = siloDetails;
            this.siloStatusOracle       = siloStatusOracle;
            this.scheduler              = scheduler;
            this.activationDirectory    = activationDirectory;
            this.consistentRingProvider = consistentRingProvider;
            this.runtimeClient          = runtimeClient;
            this.ServiceId              = config.ServiceId;
            this.SiloIdentity           = siloDetails.SiloAddress.ToLongString();

            this.grainBasedPubSub = new GrainBasedPubSubRuntime(this.GrainFactory);
            var tmp = new ImplicitStreamPubSub(this.runtimeClient.InternalGrainFactory, implicitStreamSubscriberTable);

            this.implictPubSub = tmp;
            this.combinedGrainBasedAndImplicitPubSub = new StreamPubSubImpl(this.grainBasedPubSub, tmp);
        }
Exemplo n.º 3
0
        internal TypeManager(
            SiloAddress myAddr,
            GrainTypeManager grainTypeManager,
            ISiloStatusOracle oracle,
            OrleansTaskScheduler scheduler,
            TimeSpan refreshClusterMapTimeout,
            ImplicitStreamSubscriberTable implicitStreamSubscriberTable)
            : base(Constants.TypeManagerId, myAddr)
        {
            if (grainTypeManager == null)
                throw new ArgumentNullException(nameof(grainTypeManager));
            if (oracle == null)
                throw new ArgumentNullException(nameof(oracle));
            if (scheduler == null)
                throw new ArgumentNullException(nameof(scheduler));
            if (implicitStreamSubscriberTable == null)
                throw new ArgumentNullException(nameof(implicitStreamSubscriberTable));

            this.grainTypeManager = grainTypeManager;
            this.statusOracle = oracle;
            this.implicitStreamSubscriberTable = implicitStreamSubscriberTable;
            this.scheduler = scheduler;
            this.hasToRefreshClusterGrainInterfaceMap = true;
            this.refreshClusterGrainInterfaceMapTimer = new AsyncTaskSafeTimer(
                    OnRefreshClusterMapTimer,
                    null,
                    TimeSpan.Zero,  // Force to do it once right now
                    refreshClusterMapTimeout); 
        }
Exemplo n.º 4
0
 internal GrainDirectoryPartition()
 {
     partitionData = new Dictionary <GrainId, IGrainInfo>();
     lockable      = new object();
     log           = TraceLogger.GetLogger("DirectoryPartition");
     membership    = Silo.CurrentSilo.LocalSiloStatusOracle;
 }
        public DeploymentBasedQueueBalancer(
            ISiloStatusOracle siloStatusOracle,
            IDeploymentConfiguration deploymentConfig,
            IStreamQueueMapper queueMapper,
            bool isFixed)
        {
            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;
            allQueues = queueMapper.GetAllQueues().ToList();
            queueBalanceListeners = new List<IStreamQueueBalanceListener>();
            mySiloName = this.siloStatusOracle.SiloName;
            this.isFixed = isFixed;

            // register for notification of changes to silo status for any silo in the cluster
            this.siloStatusOracle.SubscribeToSiloStatusEvents(this);
        }
Exemplo n.º 6
0
        public DeploymentBasedQueueBalancer(
            ISiloStatusOracle siloStatusOracle,
            IDeploymentConfiguration deploymentConfig,
            bool isFixed)
        {
            if (siloStatusOracle == null)
            {
                throw new ArgumentNullException("siloStatusOracle");
            }
            if (deploymentConfig == null)
            {
                throw new ArgumentNullException("deploymentConfig");
            }

            this.siloStatusOracle = siloStatusOracle;
            this.deploymentConfig = deploymentConfig;
            queueBalanceListeners = new List <IStreamQueueBalanceListener>();
            immatureSilos         = new ConcurrentDictionary <SiloAddress, bool>();
            this.isFixed          = isFixed;
            isStarting            = true;

            // register for notification of changes to silo status for any silo in the cluster
            this.siloStatusOracle.SubscribeToSiloStatusEvents(this);

            // record all already active silos as already mature.
            // Even if they are not yet, they will be mature by the time I mature myself (after I become !isStarting).
            foreach (var silo in siloStatusOracle.GetApproximateSiloStatuses(true).Keys.Where(s => !s.Equals(siloStatusOracle.SiloAddress)))
            {
                immatureSilos[silo] = false;     // record as mature
            }
        }
Exemplo n.º 7
0
 /// <summary>
 /// Create a <see cref="PlacementService"/> instance.
 /// </summary>
 public PlacementService(
     IOptionsMonitor <SiloMessagingOptions> siloMessagingOptions,
     ILocalSiloDetails localSiloDetails,
     ISiloStatusOracle siloStatusOracle,
     ILogger <PlacementService> logger,
     GrainLocator grainLocator,
     GrainVersionManifest grainInterfaceVersions,
     CachedVersionSelectorManager versionSelectorManager,
     PlacementDirectorResolver directorResolver,
     PlacementStrategyResolver strategyResolver)
 {
     LocalSilo                         = localSiloDetails.SiloAddress;
     _strategyResolver                 = strategyResolver;
     _directorResolver                 = directorResolver;
     _logger                           = logger;
     _grainLocator                     = grainLocator;
     _grainInterfaceVersions           = grainInterfaceVersions;
     _versionSelectorManager           = versionSelectorManager;
     _siloStatusOracle                 = siloStatusOracle;
     _assumeHomogeneousSilosForTesting = siloMessagingOptions.CurrentValue.AssumeHomogenousSilosForTesting;
     _workers                          = new PlacementWorker[PlacementWorkerCount];
     for (var i = 0; i < PlacementWorkerCount; i++)
     {
         _workers[i] = new(this);
     }
 }
Exemplo n.º 8
0
        public SiloProviderRuntime(
            ILocalSiloDetails siloDetails,
            IOptions <SiloOptions> siloOptions,
            IConsistentRingProvider consistentRingProvider,
            ISiloRuntimeClient runtimeClient,
            ImplicitStreamSubscriberTable implicitStreamSubscriberTable,
            ISiloStatusOracle siloStatusOracle,
            OrleansTaskScheduler scheduler,
            ActivationDirectory activationDirectory,
            ILoggerFactory loggerFactory)
        {
            this.loggerFactory          = loggerFactory;
            this.siloStatusOracle       = siloStatusOracle;
            this.scheduler              = scheduler;
            this.activationDirectory    = activationDirectory;
            this.consistentRingProvider = consistentRingProvider;
            this.runtimeClient          = runtimeClient;
            this.ServiceId              = siloOptions.Value.ServiceId;
            this.SiloIdentity           = siloDetails.SiloAddress.ToLongString();

            this.grainBasedPubSub = new GrainBasedPubSubRuntime(this.GrainFactory);
            var tmp = new ImplicitStreamPubSub(this.runtimeClient.InternalGrainFactory, implicitStreamSubscriberTable);

            this.implictPubSub = tmp;
            this.combinedGrainBasedAndImplicitPubSub = new StreamPubSubImpl(this.grainBasedPubSub, tmp);
        }
Exemplo n.º 9
0
 public override Task OnActivateAsync()
 {
     this.siloStatusOracle         = base.ServiceProvider.GetRequiredService <ISiloStatusOracle>();
     this.clusterConfiguration     = base.ServiceProvider.GetRequiredService <ClusterConfiguration>();
     this.queueLeaseToRenewTimeMap = new Dictionary <QueueId, DateTime>();
     this.responsibilityMap        = new Dictionary <string, int>();
     return(Task.CompletedTask);
 }
Exemplo n.º 10
0
 private bool IsValidSilo(SiloAddress silo)
 {
     if (membership == null)
     {
         membership = Silo.CurrentSilo.LocalSiloStatusOracle;
     }
     return(membership.IsValidSilo(silo));
 }
Exemplo n.º 11
0
 public PerSiloGrainClient(IServiceProvider serviceProvider, IGrainReferenceConverter grainReferenceConverter,
                           ISiloStatusOracle siloStatusOracle, ILog log)
     : base(serviceProvider)
 {
     GrainReferenceConverter = grainReferenceConverter;
     SiloStatusOracle        = siloStatusOracle;
     Log = log;
 }
Exemplo n.º 12
0
 public GrainDirectoryPartition(ISiloStatusOracle siloStatusOracle, GlobalConfiguration globalConfig, IInternalGrainFactory grainFactory)
 {
     partitionData         = new Dictionary <GrainId, IGrainInfo>();
     lockable              = new object();
     log                   = LogManager.GetLogger("DirectoryPartition");
     this.siloStatusOracle = siloStatusOracle;
     this.globalConfig     = globalConfig;
     this.grainFactory     = grainFactory;
 }
Exemplo n.º 13
0
 internal GrainDirectoryHandoffManager(LocalGrainDirectory localDirectory, ISiloStatusOracle siloStatusOracle)
 {
     logger = LogManager.GetLogger(this.GetType().FullName);
     this.localDirectory     = localDirectory;
     this.siloStatusOracle   = siloStatusOracle;
     directoryPartitionsMap  = new Dictionary <SiloAddress, GrainDirectoryPartition>();
     silosHoldingMyPartition = new List <SiloAddress>();
     lastPromise             = new Dictionary <SiloAddress, Task>();
 }
Exemplo n.º 14
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="serviceProvider"></param>
 /// <param name="siloStatusOracle"></param>
 /// <param name="deploymentConfig"></param>
 /// <param name="loggerFac"></param>
 public LeaseBasedQueueBalancer(IServiceProvider serviceProvider, ISiloStatusOracle siloStatusOracle, IDeploymentConfiguration deploymentConfig, Factory <string, Logger> loggerFac)
 {
     this.serviceProvider  = serviceProvider;
     this.deploymentConfig = deploymentConfig;
     this.siloStatusOracle = siloStatusOracle;
     this.myQueues         = new List <AcquiredQueue>();
     this.isStarting       = true;
     this.logger           = loggerFac(this.GetType().Name);
 }
Exemplo n.º 15
0
        private bool IsValidSilo(SiloAddress silo)
        {
            if (Membership == null)
            {
                Membership = Silo.CurrentSilo.LocalSiloStatusOracle;
            }

            return(Membership.IsFunctionalDirectory(silo));
        }
Exemplo n.º 16
0
 public SiloConnectionMaintainer(
     ConnectionManager connectionManager,
     ISiloStatusOracle siloStatusOracle,
     ILogger <SiloConnectionMaintainer> log)
 {
     this.connectionManager = connectionManager;
     this.siloStatusOracle  = siloStatusOracle;
     this.log = log;
 }
Exemplo n.º 17
0
        /// <summary>
        /// Create stream queue balancer by type requested
        /// </summary>
        /// <param name="balancerType">queue balancer type to create</param>
        /// <param name="strProviderName">name of requesting stream provider</param>
        /// <param name="siloStatusOracle">membership services interface.</param>
        /// <param name="clusterConfiguration">cluster configuration</param>
        /// <param name="runtime">stream provider runtime environment to run in</param>
        /// <param name="queueMapper">queue mapper of requesting stream provider</param>
        /// <returns>Constructed stream queue balancer</returns>
        public static IStreamQueueBalancer Create(
            StreamQueueBalancerType balancerType,
            string strProviderName,
            ISiloStatusOracle siloStatusOracle,
            ClusterConfiguration clusterConfiguration,
            IStreamProviderRuntime runtime,
            IStreamQueueMapper queueMapper)
        {
            if (string.IsNullOrWhiteSpace(strProviderName))
            {
                throw new ArgumentNullException("strProviderName");
            }
            if (siloStatusOracle == null)
            {
                throw new ArgumentNullException("siloStatusOracle");
            }
            if (clusterConfiguration == null)
            {
                throw new ArgumentNullException("clusterConfiguration");
            }
            if (runtime == null)
            {
                throw new ArgumentNullException("runtime");
            }
            if (queueMapper == null)
            {
                throw new ArgumentNullException("queueMapper");
            }
            switch (balancerType)
            {
            case StreamQueueBalancerType.ConsistentRingBalancer:
            {
                // Consider: for now re-use the same ConsistentRingProvider with 1 equally devided range. Remove later.
                IConsistentRingProviderForGrains ringProvider = runtime.GetConsistentRingProvider(0, 1);
                return(new ConsistentRingQueueBalancer(ringProvider, queueMapper));
            }

            case StreamQueueBalancerType.AzureDeploymentBalancer:
            {
                TraceLogger logger  = TraceLogger.GetLogger(typeof(StreamQueueBalancerFactory).Name, TraceLogger.LoggerType.Runtime);
                var         wrapper = AssemblyLoader.LoadAndCreateInstance <IDeploymentConfiguration>(Constants.ORLEANS_AZURE_UTILS_DLL, logger);
                return(new DeploymentBasedQueueBalancer(siloStatusOracle, wrapper, queueMapper));
            }

            case StreamQueueBalancerType.StaticClusterDeploymentBalancer:
            {
                IDeploymentConfiguration deploymentConfiguration = new StaticClusterDeploymentConfiguration(clusterConfiguration);
                return(new DeploymentBasedQueueBalancer(siloStatusOracle, deploymentConfiguration, queueMapper));
            }

            default:
            {
                string error = string.Format("Unsupported balancerType for stream provider. BalancerType: {0}, StreamProvider: {1}", balancerType, strProviderName);
                throw new ArgumentOutOfRangeException("balancerType", error);
            }
            }
        }
Exemplo n.º 18
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="serviceProvider"></param>
 /// <param name="siloStatusOracle"></param>
 /// <param name="deploymentConfig"></param>
 /// <param name="loggerFactory"></param>
 public LeaseBasedQueueBalancer(IServiceProvider serviceProvider, ISiloStatusOracle siloStatusOracle, IDeploymentConfiguration deploymentConfig, ILoggerFactory loggerFactory)
 {
     this.serviceProvider  = serviceProvider;
     this.deploymentConfig = deploymentConfig;
     this.siloStatusOracle = siloStatusOracle;
     this.myQueues         = new List <AcquiredQueue>();
     this.isStarting       = true;
     this.loggerFactory    = loggerFactory;
     this.logger           = loggerFactory.CreateLogger <LeaseBasedQueueBalancer>();
 }
Exemplo n.º 19
0
 public GrainDirectoryPartition(ISiloStatusOracle siloStatusOracle, GlobalConfiguration globalConfig, IInternalGrainFactory grainFactory, ILoggerFactory loggerFactory)
 {
     partitionData         = new Dictionary <GrainId, IGrainInfo>();
     lockable              = new object();
     log                   = loggerFactory.CreateLogger <GrainDirectoryPartition>();
     this.siloStatusOracle = siloStatusOracle;
     this.globalConfig     = globalConfig;
     this.grainFactory     = grainFactory;
     this.loggerFactory    = loggerFactory;
 }
Exemplo n.º 20
0
 public GrainDirectoryPartition(ISiloStatusOracle siloStatusOracle, IOptions <GrainDirectoryOptions> grainDirectoryOptions, IInternalGrainFactory grainFactory, ILoggerFactory loggerFactory)
 {
     partitionData              = new Dictionary <GrainId, IGrainInfo>();
     lockable                   = new object();
     log                        = loggerFactory.CreateLogger <GrainDirectoryPartition>();
     this.siloStatusOracle      = siloStatusOracle;
     this.grainDirectoryOptions = grainDirectoryOptions;
     this.grainFactory          = grainFactory;
     this.loggerFactory         = loggerFactory;
 }
 /// <summary>
 /// Constructor
 /// </summary>
 public LeaseBasedQueueBalancer(string name, LeaseBasedQueueBalancerOptions options, IServiceProvider serviceProvider, ISiloStatusOracle siloStatusOracle, IDeploymentConfiguration deploymentConfig, ILoggerFactory loggerFactory)
 {
     this.serviceProvider  = serviceProvider;
     this.deploymentConfig = deploymentConfig;
     this.siloStatusOracle = siloStatusOracle;
     this.myQueues         = new List <AcquiredQueue>();
     this.isStarting       = true;
     this.loggerFactory    = loggerFactory;
     this.options          = options;
     this.logger           = loggerFactory.CreateLogger($"{typeof(LeaseBasedQueueBalancer).FullName}-{name}");
 }
Exemplo n.º 22
0
 public DeploymentLoadPublisher(
     Silo silo,
     ISiloStatusOracle siloStatusOracle,
     GlobalConfiguration config)
     : base(Constants.DeploymentLoadPublisherSystemTargetId, silo.SiloAddress)
 {
     this.silo                     = silo;
     this.siloStatusOracle         = siloStatusOracle;
     statisticsRefreshTime         = config.DeploymentLoadPublisherRefreshTime;
     periodicStats                 = new ConcurrentDictionary <SiloAddress, SiloRuntimeStatistics>();
     siloStatisticsChangeListeners = new List <ISiloStatisticsChangeListener>();
 }
Exemplo n.º 23
0
 internal OutboundMessageQueue(
     MessageCenter mc,
     ILogger <OutboundMessageQueue> logger,
     ConnectionManager senderManager,
     ISiloStatusOracle siloStatusOracle)
 {
     messageCenter          = mc;
     this.connectionManager = senderManager;
     this.siloStatusOracle  = siloStatusOracle;
     this.logger            = logger;
     stopped = false;
 }
Exemplo n.º 24
0
 public ManagementGrain(
     GlobalConfiguration globalConfig,
     IMultiClusterOracle multiClusterOracle,
     IInternalGrainFactory internalGrainFactory,
     ISiloStatusOracle siloStatusOracle,
     MembershipTableFactory membershipTableFactory)
 {
     this.globalConfig           = globalConfig;
     this.multiClusterOracle     = multiClusterOracle;
     this.internalGrainFactory   = internalGrainFactory;
     this.siloStatusOracle       = siloStatusOracle;
     this.membershipTableFactory = membershipTableFactory;
 }
Exemplo n.º 25
0
 public ManagementGrain(
     IInternalGrainFactory internalGrainFactory,
     ISiloStatusOracle siloStatusOracle,
     GrainTypeManager grainTypeManager,
     IVersionStore versionStore,
     ILogger <ManagementGrain> logger,
     MembershipTableManager membershipTableManager)
 {
     this.membershipTableManager = membershipTableManager;
     this.internalGrainFactory   = internalGrainFactory;
     this.siloStatusOracle       = siloStatusOracle;
     this.grainTypeManager       = grainTypeManager;
     this.versionStore           = versionStore;
     this.logger = logger;
 }
Exemplo n.º 26
0
 public TestHooksSystemTarget(
     ISiloHost host,
     ILocalSiloDetails siloDetails,
     ILoggerFactory loggerFactory,
     ISiloStatusOracle siloStatusOracle,
     TestHooksHostEnvironmentStatistics hostEnvironmentStatistics,
     IOptions <LoadSheddingOptions> loadSheddingOptions)
     : base(Constants.TestHooksSystemTargetType, siloDetails.SiloAddress, loggerFactory)
 {
     this.host                      = host;
     this.siloStatusOracle          = siloStatusOracle;
     this.hostEnvironmentStatistics = hostEnvironmentStatistics;
     this.loadSheddingOptions       = loadSheddingOptions.Value;
     this.consistentRingProvider    = this.host.Services.GetRequiredService <IConsistentRingProvider>();
 }
Exemplo n.º 27
0
 public ManagementGrain(
     IInternalGrainFactory internalGrainFactory,
     ISiloStatusOracle siloStatusOracle,
     IVersionStore versionStore,
     ILogger <ManagementGrain> logger,
     MembershipTableManager membershipTableManager,
     IClusterManifestProvider clusterManifestProvider)
 {
     this.membershipTableManager = membershipTableManager;
     this.siloManifest           = clusterManifestProvider.LocalGrainManifest;
     this.internalGrainFactory   = internalGrainFactory;
     this.siloStatusOracle       = siloStatusOracle;
     this.versionStore           = versionStore;
     this.logger = logger;
 }
Exemplo n.º 28
0
 private void EnsureInitialized()
 {
     if (!isInitialized)
     {
         lock (this.initializationLock)
         {
             if (!isInitialized)
             {
                 this.messageCenter     = this.serviceProvider.GetRequiredService <MessageCenter>();
                 this.connectionManager = this.serviceProvider.GetRequiredService <ConnectionManager>();
                 this.siloStatusOracle  = this.serviceProvider.GetRequiredService <ISiloStatusOracle>();
                 this.isInitialized     = true;
             }
         }
     }
 }
Exemplo n.º 29
0
 internal GrainDirectoryHandoffManager(
     LocalGrainDirectory localDirectory,
     ISiloStatusOracle siloStatusOracle,
     IInternalGrainFactory grainFactory,
     Factory <GrainDirectoryPartition> createPartion,
     ILoggerFactory loggerFactory)
 {
     logger = loggerFactory.CreateLogger <GrainDirectoryHandoffManager>();
     this.localDirectory     = localDirectory;
     this.siloStatusOracle   = siloStatusOracle;
     this.grainFactory       = grainFactory;
     this.createPartion      = createPartion;
     directoryPartitionsMap  = new Dictionary <SiloAddress, GrainDirectoryPartition>();
     silosHoldingMyPartition = new List <SiloAddress>();
     lastPromise             = new Dictionary <SiloAddress, Task>();
 }
Exemplo n.º 30
0
 public SiloConnectionFactory(
     IServiceProvider serviceProvider,
     IOptions <ConnectionOptions> connectionOptions,
     IConnectionFactory connectionFactory,
     MessageFactory messageFactory,
     INetworkingTrace trace,
     ILocalSiloDetails localSiloDetails,
     ISiloStatusOracle siloStatusOracle)
     : base(connectionFactory, serviceProvider, connectionOptions)
 {
     this.serviceProvider  = serviceProvider;
     this.messageFactory   = messageFactory;
     this.trace            = trace;
     this.localSiloDetails = localSiloDetails;
     this.siloStatusOracle = siloStatusOracle;
 }
Exemplo n.º 31
0
 public ManagementGrain(
     IOptions <MultiClusterOptions> multiClusterOptions,
     IMultiClusterOracle multiClusterOracle,
     IInternalGrainFactory internalGrainFactory,
     ISiloStatusOracle siloStatusOracle,
     MembershipTableFactory membershipTableFactory,
     GrainTypeManager grainTypeManager,
     IVersionStore versionStore)
 {
     this.multiClusterOptions    = multiClusterOptions.Value;
     this.multiClusterOracle     = multiClusterOracle;
     this.internalGrainFactory   = internalGrainFactory;
     this.siloStatusOracle       = siloStatusOracle;
     this.membershipTableFactory = membershipTableFactory;
     this.grainTypeManager       = grainTypeManager;
     this.versionStore           = versionStore;
 }
Exemplo n.º 32
0
 public ManagementGrain(
     GlobalConfiguration globalConfig,
     IMultiClusterOracle multiClusterOracle,
     IInternalGrainFactory internalGrainFactory,
     ISiloStatusOracle siloStatusOracle,
     MembershipTableFactory membershipTableFactory,
     GrainTypeManager grainTypeManager,
     IVersionStore versionStore)
 {
     this.globalConfig           = globalConfig;
     this.multiClusterOracle     = multiClusterOracle;
     this.internalGrainFactory   = internalGrainFactory;
     this.siloStatusOracle       = siloStatusOracle;
     this.membershipTableFactory = membershipTableFactory;
     this.grainTypeManager       = grainTypeManager;
     this.versionStore           = versionStore;
 }
        /// <summary>
        /// Create stream queue balancer by type requested
        /// </summary>
        /// <param name="balancerType">queue balancer type to create</param>
        /// <param name="strProviderName">name of requesting stream provider</param>
        /// <param name="siloStatusOracle">membership services interface.</param>
        /// <param name="runtime">stream provider runtime environment to run in</param>
        /// <param name="queueMapper">queue mapper of requesting stream provider</param>
        /// <returns>Constructed stream queue balancer</returns>
        public static IStreamQueueBalancer Create(
            StreamQueueBalancerType balancerType,
            string strProviderName,
            ISiloStatusOracle siloStatusOracle,
            IStreamProviderRuntime runtime,
            IStreamQueueMapper queueMapper)
        {
            if (string.IsNullOrWhiteSpace(strProviderName))
            {
                throw new ArgumentNullException("strProviderName");
            }
            if (siloStatusOracle == null)
            {
                throw new ArgumentNullException("siloStatusOracle");
            }
            if (runtime == null)
            {
                throw new ArgumentNullException("runtime");
            }
            if (queueMapper == null)
            {
                throw new ArgumentNullException("queueMapper");
            }
            switch (balancerType)
            {
            case StreamQueueBalancerType.ConsistentRingBalancer:
            {
                // Consider: for now re-use the same ConsistentRingProvider with 1 equally devided range. Remove later.
                IConsistentRingProviderForGrains ringProvider = runtime.GetConsistentRingProvider(0, 1);
                return(new ConsistentRingQueueBalancer(ringProvider, queueMapper));
            }

            case StreamQueueBalancerType.AzureDeploymentBasedBalancer:
            {
                IDelpoymentConfiguration deploymentConfiguration = new AzureDelpoymentConfiguration();
                return(new DeploymentBasedQueueBalancer(siloStatusOracle, deploymentConfiguration, queueMapper));
            }

            default:
            {
                string error = string.Format("Unsupported balancerType for stream provider. BalancerType: {0}, StreamProvider: {1}", balancerType, strProviderName);
                throw new ArgumentOutOfRangeException("balancerType", error);
            }
            }
        }
        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 DeploymentBasedQueueBalancer(
            ISiloStatusOracle siloStatusOracle,
            IDeploymentConfiguration deploymentConfig,
            IStreamQueueMapper queueMapper,
            TimeSpan maturityPeriod,
            bool isFixed)
        {
            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;
            allQueues = new ReadOnlyCollection<QueueId>(queueMapper.GetAllQueues().ToList());
            queueBalanceListeners = new List<IStreamQueueBalanceListener>();
            immatureSilos = new ConcurrentDictionary<SiloAddress, bool>();
            this.isFixed = isFixed;
            siloMaturityPeriod = maturityPeriod;
            isStarting = true;

            // register for notification of changes to silo status for any silo in the cluster
            this.siloStatusOracle.SubscribeToSiloStatusEvents(this);

            // record all already active silos as already mature. 
            // Even if they are not yet, they will be mature by the time I mature myself (after I become !isStarting).
            foreach (var silo in siloStatusOracle.GetApproximateSiloStatuses(true).Keys.Where(s => !s.Equals(siloStatusOracle.SiloAddress)))
            {
                immatureSilos[silo] = false;     // record as mature
            }

            NotifyAfterStart().Ignore();
        }
Exemplo n.º 36
0
 private bool IsValidSilo(SiloAddress silo)
 {
     if (membership == null)
     {
         membership = Silo.CurrentSilo.LocalSiloStatusOracle;
     }
     return membership.IsFunctionalDirectory(silo);
 }
Exemplo n.º 37
0
 internal GrainDirectoryPartition()
 {
     partitionData = new Dictionary<GrainId, IGrainInfo>();
     lockable = new object();
     log = TraceLogger.GetLogger("DirectoryPartition");
     membership = Silo.CurrentSilo.LocalSiloStatusOracle;
 }
 private static List<string> GetActiveSilos(ISiloStatusOracle siloStatusOracle, ConcurrentDictionary<SiloAddress, bool> immatureSilos)
 {
     var activeSiloNames = new List<string>();
     foreach (var kvp in siloStatusOracle.GetApproximateSiloStatuses(true))
     {
         bool immatureBit;
         if (!(immatureSilos.TryGetValue(kvp.Key, out immatureBit) && immatureBit)) // if not immature now or any more
         {
             string siloName;
             if (siloStatusOracle.TryGetSiloName(kvp.Key, out siloName))
             {
                 activeSiloNames.Add(siloName);
             }
         }
     }
     return activeSiloNames;
 }
 private static HashSet<QueueId> GetQueuesOfImmatureSilos(ISiloStatusOracle siloStatusOracle, 
     ConcurrentDictionary<SiloAddress, bool> immatureSilos, 
     Dictionary<string, List<QueueId>> idealDistribution)
 {
     HashSet<QueueId> queuesOfImmatureSilos = new HashSet<QueueId>();
     foreach (var silo in immatureSilos.Where(s => s.Value)) // take only those from immature set that have their immature status bit set
     {
         string siloName;
         if (siloStatusOracle.TryGetSiloName(silo.Key, out siloName))
         {
             List<QueueId> queues;
             if (idealDistribution.TryGetValue(siloName, out queues))
             {
                 queuesOfImmatureSilos.UnionWith(queues);
             }
         }
     }
     return queuesOfImmatureSilos;
 }