Ejemplo n.º 1
0
        public ProtocolServices(
            Grain gr,
            Factory <string, Logger> logFactory,
            IMultiClusterRegistrationStrategy strategy,
            SerializationManager serializationManager,
            IInternalGrainFactory grainFactory,
            GlobalConfiguration globalConfig,
            IMultiClusterOracle multiClusterOracle)
        {
            this.grain                = gr;
            this.log                  = logFactory("LogConsistencyProtocolServices");
            this.grainFactory         = grainFactory;
            this.RegistrationStrategy = strategy;
            this.SerializationManager = serializationManager;
            this.multiClusterOracle   = multiClusterOracle;
            this.globalConfig         = globalConfig;

            if (!globalConfig.HasMultiClusterNetwork)
            {
                // we are creating a default multi-cluster configuration containing exactly one cluster, this one.
                this.pseudoMultiClusterConfiguration = PseudoMultiClusterConfigurations.FindOrCreate(
                    this.globalConfig.ClusterId,
                    CreatePseudoConfig);
            }
        }
Ejemplo n.º 2
0
 public ClusterManifestProvider(
     ILocalSiloDetails localSiloDetails,
     SiloManifest localSiloManifest,
     IInternalGrainFactory grainFactory,
     ClusterMembershipService clusterMembershipService,
     IFatalErrorHandler fatalErrorHandler,
     ILogger <ClusterManifestProvider> logger,
     IOptions <TypeManagementOptions> options,
     IServiceProvider services)
 {
     _localSiloAddress         = localSiloDetails.SiloAddress;
     _grainFactory             = grainFactory;
     _logger                   = logger;
     _services                 = services;
     _clusterMembershipService = clusterMembershipService;
     _fatalErrorHandler        = fatalErrorHandler;
     _options                  = options.Value;
     _current                  = new ClusterManifest(
         MajorMinorVersion.Zero,
         ImmutableDictionary.CreateRange(new[] { new KeyValuePair <SiloAddress, SiloManifest>(localSiloDetails.SiloAddress, localSiloManifest) }));
     _updates = new AsyncEnumerable <ClusterManifest>(
         (previous, proposed) => previous.Version <= MajorMinorVersion.Zero || proposed.Version > previous.Version,
         _current)
     {
         OnPublished = update => Interlocked.Exchange(ref _current, update)
     };
 }
Ejemplo n.º 3
0
 public DeploymentLoadPublisher(
     ILocalSiloDetails siloDetails,
     ISiloStatusOracle siloStatusOracle,
     IOptions <DeploymentLoadPublisherOptions> options,
     IInternalGrainFactory grainFactory,
     OrleansTaskScheduler scheduler,
     ILoggerFactory loggerFactory,
     IMessageCenter messageCenter,
     ActivationDirectory activationDirectory,
     ActivationCollector activationCollector,
     IAppEnvironmentStatistics appEnvironmentStatistics,
     IHostEnvironmentStatistics hostEnvironmentStatistics,
     IOptions <LoadSheddingOptions> loadSheddingOptions)
     : base(Constants.DeploymentLoadPublisherSystemTargetId, siloDetails.SiloAddress, loggerFactory)
 {
     this.logger                    = loggerFactory.CreateLogger <DeploymentLoadPublisher>();
     this.siloDetails               = siloDetails;
     this.siloStatusOracle          = siloStatusOracle;
     this.grainFactory              = grainFactory;
     this.scheduler                 = scheduler;
     this.messageCenter             = messageCenter;
     this.activationDirectory       = activationDirectory;
     this.activationCollector       = activationCollector;
     this.appEnvironmentStatistics  = appEnvironmentStatistics;
     this.hostEnvironmentStatistics = hostEnvironmentStatistics;
     this.loadSheddingOptions       = loadSheddingOptions;
     statisticsRefreshTime          = options.Value.DeploymentLoadPublisherRefreshTime;
     periodicStats                  = new ConcurrentDictionary <SiloAddress, SiloRuntimeStatistics>();
     siloStatisticsChangeListeners  = new List <ISiloStatisticsChangeListener>();
 }
Ejemplo n.º 4
0
        public HostedClient(
            IRuntimeClient runtimeClient,
            ClientObserverRegistrar clientObserverRegistrar,
            ILocalSiloDetails siloDetails,
            ILogger <HostedClient> logger,
            IGrainReferenceRuntime grainReferenceRuntime,
            IInternalGrainFactory grainFactory,
            InvokableObjectManager invokableObjectManager,
            ISiloMessageCenter messageCenter)
        {
            this.runtimeClient           = runtimeClient;
            this.clientObserverRegistrar = clientObserverRegistrar;
            this.grainReferenceRuntime   = grainReferenceRuntime;
            this.grainFactory            = grainFactory;
            this.invokableObjects        = invokableObjectManager;
            this.siloMessageCenter       = messageCenter;
            this.logger = logger;

            this.ClientAddress = ActivationAddress.NewActivationAddress(siloDetails.SiloAddress, GrainId.NewClientId());

            // Register with the directory and message center so that we can receive messages.
            this.clientObserverRegistrar.SetHostedClient(this);
            this.clientObserverRegistrar.ClientAdded(this.ClientId);
            this.siloMessageCenter.SetHostedClient(this);

            // Start pumping messages.
            this.Start();
        }
Ejemplo n.º 5
0
 public GrainVersionStore(IInternalGrainFactory grainFactory, ILocalSiloDetails siloDetails, IServiceProvider services)
 {
     this.grainFactory = grainFactory;
     this.services     = services;
     this.clusterId    = siloDetails.ClusterId;
     this.IsEnabled    = false;
 }
Ejemplo n.º 6
0
            public bool KnowsMe; // used for optimizing pushes

            public SiloGossipWorker(MultiClusterOracle oracle, SiloAddress Silo, IInternalGrainFactory grainFactory)
                : base(oracle)
            {
                this.Cluster      = null; // only local cluster
                this.Silo         = Silo;
                this.grainFactory = grainFactory;
            }
Ejemplo n.º 7
0
        public ProtocolServices(
            Grain gr,
            ILoggerFactory loggerFactory,
            IMultiClusterRegistrationStrategy strategy,
            SerializationManager serializationManager,
            IInternalGrainFactory grainFactory,
            IOptions <SiloOptions> siloOptions,
            IOptions <MultiClusterOptions> multiClusterOptions,
            IMultiClusterOracle multiClusterOracle)
        {
            this.grain                = gr;
            this.log                  = loggerFactory.CreateLogger <ProtocolServices>();
            this.grainFactory         = grainFactory;
            this.RegistrationStrategy = strategy;
            this.SerializationManager = serializationManager;
            this.multiClusterOracle   = multiClusterOracle;
            this.siloOptions          = siloOptions.Value;
            this.multiClusterOptions  = multiClusterOptions.Value;

            if (!this.multiClusterOptions.HasMultiClusterNetwork)
            {
                // we are creating a default multi-cluster configuration containing exactly one cluster, this one.
                this.pseudoMultiClusterConfiguration = PseudoMultiClusterConfigurations.FindOrCreate(
                    this.siloOptions.ClusterId,
                    CreatePseudoConfig);
            }
        }
Ejemplo n.º 8
0
        public MultiClusterOracle(
            ILocalSiloDetails siloDetails,
            MultiClusterGossipChannelFactory channelFactory,
            ISiloStatusOracle siloStatusOracle,
            MembershipTableManager tableManager,
            IInternalGrainFactory grainFactory,
            ILoggerFactory loggerFactory,
            IOptions <MultiClusterOptions> multiClusterOptions)
            : base(Constants.MultiClusterOracleId, siloDetails.SiloAddress, loggerFactory)
        {
            this.loggerFactory    = loggerFactory;
            this.channelFactory   = channelFactory;
            this.siloStatusOracle = siloStatusOracle;
            this.tableManager     = tableManager;
            this.grainFactory     = grainFactory;

            logger    = loggerFactory.CreateLogger <MultiClusterOracle>();
            localData = new MultiClusterOracleData(logger, grainFactory);
            clusterId = siloDetails.ClusterId;
            var multiClusterOptionsSnapshot = multiClusterOptions.Value;

            defaultMultiCluster          = multiClusterOptionsSnapshot.DefaultMultiCluster?.ToList();
            this.multiClusterActive      = multiClusterOptionsSnapshot.HasMultiClusterNetwork;
            this.maxMultiClusterGateways = multiClusterOptionsSnapshot.MaxMultiClusterGateways;
            random = new SafeRandom();

            // to avoid convoying, each silo varies these period intervals a little
            backgroundGossipInterval = RandomizeTimespanSlightly(multiClusterOptionsSnapshot.BackgroundGossipInterval);
            resendActiveStatusAfter  = RandomizeTimespanSlightly(ResendActiveStatusAfter);
        }
Ejemplo n.º 9
0
        public HostedClient(
            IRuntimeClient runtimeClient,
            ClientObserverRegistrar clientObserverRegistrar,
            ILocalSiloDetails siloDetails,
            ILogger <HostedClient> logger,
            IGrainReferenceRuntime grainReferenceRuntime,
            IInternalGrainFactory grainFactory,
            InvokableObjectManager invokableObjectManager,
            MessageCenter messageCenter,
            MessagingTrace messagingTrace)
        {
            this.incomingMessages = Channel.CreateUnbounded <Message>(new UnboundedChannelOptions
            {
                SingleReader = true,
                SingleWriter = false,
                AllowSynchronousContinuations = false,
            });

            this.runtimeClient           = runtimeClient;
            this.clientObserverRegistrar = clientObserverRegistrar;
            this.grainReferenceRuntime   = grainReferenceRuntime;
            this.grainFactory            = grainFactory;
            this.invokableObjects        = invokableObjectManager;
            this.siloMessageCenter       = messageCenter;
            this.messagingTrace          = messagingTrace;
            this.logger = logger;

            this.ClientAddress = ActivationAddress.NewActivationAddress(siloDetails.SiloAddress, GrainId.NewClientId());
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Merges one partition into another, assuming partitions are disjoint.
        /// This method is supposed to be used by handoff manager to update the partitions when the system view (set of live silos) changes.
        /// </summary>
        /// <param name="grainFactory"></param>
        /// <param name="other"></param>
        internal void Merge(IInternalGrainFactory grainFactory, GrainDirectoryPartition other)
        {
            lock (lockable)
            {
                foreach (var pair in other.partitionData)
                {
                    if (partitionData.ContainsKey(pair.Key))
                    {
                        if (log.IsVerbose)
                        {
                            log.Verbose("While merging two disjoint partitions, same grain " + pair.Key + " was found in both partitions");
                        }
                        var activationsToDrop = partitionData[pair.Key].Merge(pair.Key, pair.Value);
                        if (activationsToDrop == null)
                        {
                            continue;
                        }

                        foreach (var siloActivations in activationsToDrop)
                        {
                            var remoteCatalog = grainFactory.GetSystemTarget <ICatalog>(Constants.CatalogId, siloActivations.Key);
                            remoteCatalog.DeleteActivations(siloActivations.Value).Ignore();
                        }
                    }
                    else
                    {
                        partitionData.Add(pair.Key, pair.Value);
                    }
                }
            }
        }
Ejemplo n.º 11
0
 public SiloGossipWorker(MultiClusterOracle oracle, string cluster, IInternalGrainFactory grainFactory)
     : base(oracle)
 {
     this.Cluster      = cluster;
     this.Silo         = null;
     this.grainFactory = grainFactory;
 }
Ejemplo n.º 12
0
 public ClusterGrainDirectory(LocalGrainDirectory r, GrainId grainId, string clusterId, IInternalGrainFactory grainFactory) : base(grainId, r.MyAddress)
 {
     this.router       = r;
     this.clusterId    = clusterId;
     this.grainFactory = grainFactory;
     this.logger       = r.Logger;
 }
 public GlobalSingleInstanceRegistrar(GrainDirectoryPartition partition, Logger logger, GlobalSingleInstanceActivationMaintainer gsiActivationMaintainer, int numRetries, IInternalGrainFactory grainFactory)
 {
     this.directoryPartition      = partition;
     this.logger                  = logger;
     this.gsiActivationMaintainer = gsiActivationMaintainer;
     this.numRetries              = numRetries;
     this.grainFactory            = grainFactory;
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GrainCreator"/> class.
 /// </summary>
 /// <param name="services">Service provider used to create new grains</param>
 /// <param name="getGrainRuntime">The delegate used to get the grain runtime.</param>
 /// <param name="serializationManager">The serialization manager.</param>
 /// <param name="grainFactory"></param>
 public GrainCreator(IServiceProvider services, Func <IGrainRuntime> getGrainRuntime, SerializationManager serializationManager, IInternalGrainFactory grainFactory)
 {
     this.services             = services;
     this.serializationManager = serializationManager;
     this.grainFactory         = grainFactory;
     this.grainRuntime         = new Lazy <IGrainRuntime>(getGrainRuntime);
     this.createFactory        = type => ActivatorUtilities.CreateFactory(type, Type.EmptyTypes);
 }
Ejemplo n.º 15
0
 public ClientProviderRuntime(IInternalGrainFactory grainFactory, IServiceProvider serviceProvider)
 {
     this.grainFactory    = grainFactory;
     this.ServiceProvider = serviceProvider;
     this.runtimeClient   = serviceProvider.GetService <IRuntimeClient>();
     caoTable             = new Dictionary <Type, Tuple <IGrainExtension, IAddressable> >();
     lockable             = new AsyncLock();
 }
Ejemplo n.º 16
0
 internal GlobalSingleInstanceActivationMaintainer(LocalGrainDirectory router, Logger logger, GlobalConfiguration config, IInternalGrainFactory grainFactory)
 {
     this.router       = router;
     this.logger       = logger;
     this.grainFactory = grainFactory;
     this.period       = config.GlobalSingleInstanceRetryInterval;
     logger.Verbose("GSIP:M GlobalSingleInstanceActivationMaintainer Started, Period = {0}", period);
 }
Ejemplo n.º 17
0
 internal MultipleStreamsTestRunner(IInternalGrainFactory grainFactory, string streamProvider, int testNum = 0, bool fullTest = true)
 {
     this.grainFactory       = grainFactory;
     this.streamProviderName = streamProvider;
     this.logger             = LogManager.GetLogger("MultipleStreamsTestRunner", LoggerType.Application);
     this.testNumber         = testNum;
     this.runFullTest        = fullTest;
 }
Ejemplo n.º 18
0
 internal MultiClusterOracleData(ILogger log, IInternalGrainFactory grainFactory)
 {
     logger                  = log;
     this.grainFactory       = grainFactory;
     localData               = new MultiClusterData();
     activeGatewaysByCluster = new Dictionary <string, List <SiloAddress> >();
     confListeners           = new HashSet <GrainReference>();
 }
Ejemplo n.º 19
0
        /// <summary>Gets a detailed grain report from a specified silo</summary>
        /// <param name="grainFactory">The grain factory.</param>
        /// <param name="grainId">The grain id we are requesting information from</param>
        /// <param name="siloHandle">The target silo that should provide this information from it's cache</param>
        internal static Task <DetailedGrainReport> GetDetailedGrainReport(IInternalGrainFactory grainFactory, GrainId grainId, SiloHandle siloHandle)
        {
            // Use the siloAddress here, not the gateway address, since we may be targeting a silo on which we are not
            // connected to the gateway
            var siloControl = grainFactory.GetSystemTarget <ISiloControl>(Constants.SiloControlType, siloHandle.SiloAddress);

            return(siloControl.GetDetailedGrainReport(grainId));
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Create a reference to a grain that we expect to support the stream consumer extension.
        /// </summary>
        /// <param name="grainFactory">The grain factory used to get consumer references.</param>
        /// <param name="streamId">The stream ID to use for the grain ID construction.</param>
        /// <param name="streamSubscriber">The GrainBindings for the grain to create</param>
        /// <returns></returns>
        private IStreamConsumerExtension MakeConsumerReference(
            IInternalGrainFactory grainFactory,
            InternalStreamId streamId,
            StreamSubscriber streamSubscriber)
        {
            var grainId = streamSubscriber.GetGrainId(streamId);

            return(grainFactory.GetGrain <IStreamConsumerExtension>(grainId));
        }
Ejemplo n.º 21
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;
 }
Ejemplo n.º 22
0
 public ClientProviderRuntime(
     IInternalGrainFactory grainFactory,
     IServiceProvider serviceProvider,
     ClientGrainContext clientContext)
 {
     this.grainFactory    = grainFactory;
     this.ServiceProvider = serviceProvider;
     this.clientContext   = clientContext;
 }
Ejemplo n.º 23
0
        /// <summary>
        /// Currently we only support a single GrainService per Silo, when multiple are supported we will request the number of GrainServices to partition per silo here.
        /// </summary>
        protected GrainServiceClient(IServiceProvider serviceProvider)
        {
            grainFactory = serviceProvider.GetRequiredService <IInternalGrainFactory>();
            ringProvider = serviceProvider.GetRequiredService <IConsistentRingProvider>();

            // GrainInterfaceMap only holds IGrain types, not ISystemTarget types, so resolved via Orleans.CodeGeneration.
            // Resolve this before merge.
            grainTypeCode = GrainInterfaceUtils.GetGrainClassTypeCode(typeof(TGrainService));
        }
Ejemplo n.º 24
0
 internal SingleStreamTestRunner(IInternalGrainFactory grainFactory, string streamProvider, int testNum = 0, bool fullTest = true)
 {
     this.grainFactory       = grainFactory;
     this.streamProviderName = streamProvider;
     this.logger             = LogManager.GetLogger("SingleStreamTestRunner", LoggerType.Application);
     this.testNumber         = testNum;
     this.runFullTest        = fullTest;
     this.random             = TestConstants.random;
 }
Ejemplo n.º 25
0
        public ImplicitStreamPubSub(IInternalGrainFactory grainFactory, ImplicitStreamSubscriberTable implicitPubSubTable)
        {
            if (implicitPubSubTable == null)
            {
                throw new ArgumentNullException("implicitPubSubTable");
            }

            this.grainFactory  = grainFactory;
            this.implicitTable = implicitPubSubTable;
        }
Ejemplo n.º 26
0
        /// <summary>
        /// Create a reference to a grain that we expect to support the stream consumer extension.
        /// </summary>
        /// <param name="grainFactory">The grain factory used to get consumer references.</param>
        /// <param name="streamId">The stream ID to use for the grain ID construction.</param>
        /// <param name="implTypeCode">The type code of the grain interface.</param>
        /// <returns></returns>
        private IStreamConsumerExtension MakeConsumerReference(IInternalGrainFactory grainFactory, StreamId streamId,
                                                               int implTypeCode)
        {
            var keyExtension = grainsWithKeyExtensions.Contains(implTypeCode)
                ? streamId.Namespace
                : null;
            GrainId grainId = LegacyGrainId.GetGrainId(implTypeCode, streamId.Guid, keyExtension);

            return(grainFactory.GetGrain <IStreamConsumerExtension>(grainId));
        }
Ejemplo n.º 27
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;
 }
Ejemplo n.º 28
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;
 }
        /// <summary>
        /// Create a reference to a grain that we expect to support the stream consumer extension.
        /// </summary>
        /// <param name="grainFactory">The grain factory used to get consumer references.</param>
        /// <param name="streamId">The stream ID to use for the grain ID construction.</param>
        /// <param name="subscriber">The subscriber prototype.</param>
        /// <returns></returns>
        private IStreamConsumerExtension MakeConsumerReference(
            IInternalGrainFactory grainFactory,
            StreamId streamId,
            StreamSubscriber subscriber)
        {
            var keyExtension = subscriber.IncludeNamespaceInGrainId ? streamId.Namespace : null;
            var grainId      = GrainId.Create(subscriber.GrainType, GrainIdKeyExtensions.CreateGuidKey(streamId.Guid, keyExtension));

            return(grainFactory.GetGrain <IStreamConsumerExtension>(grainId));
        }
 internal GrainDirectoryHandoffManager(LocalGrainDirectory localDirectory, ISiloStatusOracle siloStatusOracle, IInternalGrainFactory grainFactory)
 {
     logger = LogManager.GetLogger(this.GetType().FullName);
     this.localDirectory     = localDirectory;
     this.siloStatusOracle   = siloStatusOracle;
     this.grainFactory       = grainFactory;
     directoryPartitionsMap  = new Dictionary <SiloAddress, GrainDirectoryPartition>();
     silosHoldingMyPartition = new List <SiloAddress>();
     lastPromise             = new Dictionary <SiloAddress, Task>();
 }
Ejemplo n.º 31
0
 public MembershipFactory(IInternalGrainFactory grainFactory)
 {
     this.grainFactory = grainFactory;
     logger = LogManager.GetLogger("MembershipFactory", LoggerType.Runtime);
 }