public ActivationData(ActivationAddress addr, string genericArguments, PlacementStrategy placedUsing, MultiClusterRegistrationStrategy registrationStrategy, IActivationCollector collector, TimeSpan ageLimit) { if (null == addr) { throw new ArgumentNullException("addr"); } if (null == placedUsing) { throw new ArgumentNullException("placedUsing"); } if (null == collector) { throw new ArgumentNullException("collector"); } logger = TraceLogger.GetLogger("ActivationData", TraceLogger.LoggerType.Runtime); ResetKeepAliveRequest(); Address = addr; State = ActivationState.Create; PlacedUsing = placedUsing; RegistrationStrategy = registrationStrategy; if (!Grain.IsSystemTarget && !Constants.IsSystemGrain(Grain)) { this.collector = collector; } CollectionAgeLimit = ageLimit; GrainReference = GrainReference.FromGrainId(addr.Grain, genericArguments, Grain.IsSystemTarget ? addr.Silo : null); }
internal GrainClassData(int grainTypeCode, string grainClass, bool isGeneric, GrainInterfaceMap.GrainInterfaceData interfaceData, PlacementStrategy placement, MultiClusterRegistrationStrategy registrationStrategy) { GrainTypeCode = grainTypeCode; GrainClass = grainClass; this.isGeneric = isGeneric; this.interfaceData = interfaceData; genericClassNames = new Dictionary <string, string>(); // TODO: initialize only for generic classes placementStrategy = placement; this.registrationStrategy = registrationStrategy; }
public GrainTypeData(Type type, MultiClusterRegistrationStrategyManager registrationManager) { var typeInfo = type.GetTypeInfo(); Type = type; IsReentrant = typeInfo.GetCustomAttributes(typeof(ReentrantAttribute), true).Any(); // TODO: shouldn't this use GrainInterfaceUtils.IsStatelessWorker? IsStatelessWorker = typeInfo.GetCustomAttributes(typeof(StatelessWorkerAttribute), true).Any(); GrainClass = TypeUtils.GetFullName(typeInfo); RemoteInterfaceTypes = GetRemoteInterfaces(type); MayInterleave = GetMayInterleavePredicate(typeInfo) ?? (_ => false); MultiClusterRegistrationStrategy = registrationManager?.GetMultiClusterRegistrationStrategy(type); }
internal void AddEntry(Type iface, Type grain, PlacementStrategy placement, MultiClusterRegistrationStrategy registrationStrategy, bool primaryImplementation) { lock (this) { var grainTypeInfo = grain.GetTypeInfo(); var grainName = TypeUtils.GetFullName(grainTypeInfo); var isGenericGrainClass = grainTypeInfo.ContainsGenericParameters; var grainTypeCode = GrainInterfaceUtils.GetGrainClassTypeCode(grain); var grainInterfaceData = GetOrAddGrainInterfaceData(iface, isGenericGrainClass); var implementation = new GrainClassData(grainTypeCode, grainName, isGenericGrainClass); if (!implementationIndex.ContainsKey(grainTypeCode)) { implementationIndex.Add(grainTypeCode, implementation); } if (!placementStrategiesIndex.ContainsKey(grainTypeCode)) { placementStrategiesIndex.Add(grainTypeCode, placement); } if (!registrationStrategiesIndex.ContainsKey(grainTypeCode)) { registrationStrategiesIndex.Add(grainTypeCode, registrationStrategy); } grainInterfaceData.AddImplementation(implementation, primaryImplementation); if (primaryImplementation) { primaryImplementations[grainInterfaceData.GrainInterface] = grainName; } else { if (!primaryImplementations.ContainsKey(grainInterfaceData.GrainInterface)) { primaryImplementations.Add(grainInterfaceData.GrainInterface, grainName); } } if (localTestMode) { var assembly = grainTypeInfo.Assembly.CodeBase; if (!loadedGrainAsemblies.Contains(assembly)) { loadedGrainAsemblies.Add(assembly); } } } }
public ActivationData( ActivationAddress addr, string genericArguments, PlacementStrategy placedUsing, MultiClusterRegistrationStrategy registrationStrategy, IActivationCollector collector, TimeSpan ageLimit, NodeConfiguration nodeConfiguration, TimeSpan maxWarningRequestProcessingTime, TimeSpan maxRequestProcessingTime, IRuntimeClient runtimeClient) { if (null == addr) { throw new ArgumentNullException(nameof(addr)); } if (null == placedUsing) { throw new ArgumentNullException(nameof(placedUsing)); } if (null == collector) { throw new ArgumentNullException(nameof(collector)); } logger = LogManager.GetLogger("ActivationData", LoggerType.Runtime); this.lifecycle = new GrainLifecycle(logger); this.maxRequestProcessingTime = maxRequestProcessingTime; this.maxWarningRequestProcessingTime = maxWarningRequestProcessingTime; this.nodeConfiguration = nodeConfiguration; ResetKeepAliveRequest(); Address = addr; State = ActivationState.Create; PlacedUsing = placedUsing; RegistrationStrategy = registrationStrategy; if (!Grain.IsSystemTarget && !Constants.IsSystemGrain(Grain)) { this.collector = collector; } CollectionAgeLimit = ageLimit; GrainReference = GrainReference.FromGrainId(addr.Grain, runtimeClient.GrainReferenceRuntime, genericArguments, Grain.IsSystemTarget ? addr.Silo : null); this.SchedulingContext = new SchedulingContext(this); }
internal static MultiClusterRegistrationStrategy GetMultiClusterRegistrationStrategy(Type grainClass) { var attribs = grainClass.GetTypeInfo().GetCustomAttributes <Orleans.MultiCluster.RegistrationAttribute>(inherit: true).ToArray(); switch (attribs.Length) { case 0: return(MultiClusterRegistrationStrategy.GetDefault()); // no strategy is specified case 1: return(attribs[0].RegistrationStrategy); default: throw new InvalidOperationException( string.Format( "More than one {0} cannot be specified for grain interface {1}", typeof(MultiClusterRegistrationStrategy).Name, grainClass.Name)); } }
public static void GetGrainTypeInfo(this IPlacementContext @this, GrainId grainId, out string grainClass, out PlacementStrategy placement, out MultiClusterRegistrationStrategy activationStrategy, string genericArguments = null) { @this.GetGrainTypeInfo(grainId.GetTypeCode(), out grainClass, out placement, out activationStrategy, genericArguments); }
internal void GetTypeInfo(int typeCode, out string grainClass, out PlacementStrategy placement, out MultiClusterRegistrationStrategy activationStrategy, string genericArguments = null) { if (!grainInterfaceMap.TryGetTypeInfo(typeCode, out grainClass, out placement, out activationStrategy, genericArguments)) { throw new OrleansException(String.Format("Unexpected: Cannot find an implementation class for grain interface {0}", typeCode)); } }
internal RegistrationAttribute(MultiClusterRegistrationStrategy strategy) { RegistrationStrategy = strategy ?? MultiClusterRegistrationStrategy.GetDefault(); }
internal bool TryGetTypeInfo(int typeCode, out string grainClass, out PlacementStrategy placement, out MultiClusterRegistrationStrategy registrationStrategy, string genericArguments = null) { lock (this) { grainClass = null; placement = this.defaultPlacementStrategy; registrationStrategy = null; if (!implementationIndex.ContainsKey(typeCode)) { return(false); } var implementation = implementationIndex[typeCode]; grainClass = implementation.GetClassName(genericArguments); placement = implementation.PlacementStrategy ?? this.defaultPlacementStrategy; registrationStrategy = implementation.RegistrationStrategy; return(true); } }
internal RegistrationAttribute(MultiClusterRegistrationStrategy strategy) { this.RegistrationStrategy = strategy; }
internal void AddEntry(int interfaceId, Type iface, int grainTypeCode, string grainInterface, string grainClass, string assembly, bool isGenericGrainClass, PlacementStrategy placement, MultiClusterRegistrationStrategy registrationStrategy, bool primaryImplementation = false) { lock (this) { GrainInterfaceData grainInterfaceData; if (table.ContainsKey(interfaceId)) { grainInterfaceData = table[interfaceId]; } else { grainInterfaceData = new GrainInterfaceData(interfaceId, iface, grainInterface); table[interfaceId] = grainInterfaceData; var interfaceTypeKey = GetTypeKey(iface, isGenericGrainClass); typeToInterfaceData[interfaceTypeKey] = grainInterfaceData; } var implementation = new GrainClassData(grainTypeCode, grainClass, isGenericGrainClass, grainInterfaceData, placement, registrationStrategy); if (!implementationIndex.ContainsKey(grainTypeCode)) { implementationIndex.Add(grainTypeCode, implementation); } grainInterfaceData.AddImplementation(implementation, primaryImplementation); if (primaryImplementation) { primaryImplementations[grainInterface] = grainClass; } else { if (!primaryImplementations.ContainsKey(grainInterface)) { primaryImplementations.Add(grainInterface, grainClass); } } if (localTestMode) { if (!loadedGrainAsemblies.Contains(assembly)) { loadedGrainAsemblies.Add(assembly); } } } }
internal Silo(string name, SiloType siloType, ClusterConfiguration config, ILocalDataStore keyStore) { SystemStatus.Current = SystemStatus.Creating; CurrentSilo = this; var startTime = DateTime.UtcNow; this.siloType = siloType; Name = name; siloTerminatedEvent = new ManualResetEvent(false); OrleansConfig = config; globalConfig = config.Globals; config.OnConfigChange("Defaults", () => nodeConfig = config.GetOrCreateNodeConfigurationForSilo(name)); if (!LogManager.IsInitialized) { LogManager.Initialize(nodeConfig); } config.OnConfigChange("Defaults/Tracing", () => LogManager.Initialize(nodeConfig, true), false); MultiClusterRegistrationStrategy.Initialize(config.Globals); ActivationData.Init(config, nodeConfig); StatisticsCollector.Initialize(nodeConfig); SerializationManager.Initialize(globalConfig.SerializationProviders, this.globalConfig.FallbackSerializationProvider); initTimeout = globalConfig.MaxJoinAttemptTime; if (Debugger.IsAttached) { initTimeout = StandardExtensions.Max(TimeSpan.FromMinutes(10), globalConfig.MaxJoinAttemptTime); stopTimeout = initTimeout; } IPEndPoint here = nodeConfig.Endpoint; int generation = nodeConfig.Generation; if (generation == 0) { generation = SiloAddress.AllocateNewGeneration(); nodeConfig.Generation = generation; } LogManager.MyIPEndPoint = here; logger = LogManager.GetLogger("Silo", LoggerType.Runtime); logger.Info(ErrorCode.SiloGcSetting, "Silo starting with GC settings: ServerGC={0} GCLatencyMode={1}", GCSettings.IsServerGC, Enum.GetName(typeof(GCLatencyMode), GCSettings.LatencyMode)); if (!GCSettings.IsServerGC || !GCSettings.LatencyMode.Equals(GCLatencyMode.Batch)) { logger.Warn(ErrorCode.SiloGcWarning, "Note: Silo not running with ServerGC turned on or with GCLatencyMode.Batch enabled - recommend checking app config : <configuration>-<runtime>-<gcServer enabled=\"true\"> and <configuration>-<runtime>-<gcConcurrent enabled=\"false\"/>"); logger.Warn(ErrorCode.SiloGcWarning, "Note: ServerGC only kicks in on multi-core systems (settings enabling ServerGC have no effect on single-core machines)."); } logger.Info(ErrorCode.SiloInitializing, "-------------- Initializing {0} silo on host {1} MachineName {2} at {3}, gen {4} --------------", siloType, nodeConfig.DNSHostName, Environment.MachineName, here, generation); logger.Info(ErrorCode.SiloInitConfig, "Starting silo {0} with the following configuration= " + Environment.NewLine + "{1}", name, config.ToString(name)); if (keyStore != null) { // Re-establish reference to shared local key store in this app domain LocalDataStoreInstance.LocalDataStore = keyStore; } // Configure DI using Startup type bool usingCustomServiceProvider; Services = StartupBuilder.ConfigureStartup(nodeConfig.StartupTypeName, out usingCustomServiceProvider); healthCheckParticipants = new List <IHealthCheckParticipant>(); allSiloProviders = new List <IProvider>(); BufferPool.InitGlobalBufferPool(globalConfig); PlacementStrategy.Initialize(globalConfig); UnobservedExceptionsHandlerClass.SetUnobservedExceptionHandler(UnobservedExceptionHandler); AppDomain.CurrentDomain.UnhandledException += (obj, ev) => DomainUnobservedExceptionHandler(obj, (Exception)ev.ExceptionObject); try { grainFactory = Services.GetRequiredService <GrainFactory>(); } catch (InvalidOperationException exc) { logger.Error(ErrorCode.SiloStartError, "Exception during Silo.Start, GrainFactory was not registered in Dependency Injection container", exc); throw; } typeManager = new GrainTypeManager( here.Address.Equals(IPAddress.Loopback), grainFactory, new SiloAssemblyLoader(OrleansConfig.Defaults.AdditionalAssemblyDirectories)); // Performance metrics siloStatistics = new SiloStatisticsManager(globalConfig, nodeConfig); config.OnConfigChange("Defaults/LoadShedding", () => siloStatistics.MetricsTable.NodeConfig = nodeConfig, false); // The scheduler scheduler = new OrleansTaskScheduler(globalConfig, nodeConfig); healthCheckParticipants.Add(scheduler); // Initialize the message center var mc = new MessageCenter(here, generation, globalConfig, siloStatistics.MetricsTable); if (nodeConfig.IsGatewayNode) { mc.InstallGateway(nodeConfig.ProxyGatewayEndpoint); } messageCenter = mc; SiloIdentity = SiloAddress.ToLongString(); // GrainRuntime can be created only here, after messageCenter was created. grainRuntime = new GrainRuntime( globalConfig.ServiceId, SiloIdentity, grainFactory, new TimerRegistry(), new ReminderRegistry(), new StreamProviderManager(), Services); // Now the router/directory service // This has to come after the message center //; note that it then gets injected back into the message center.; localGrainDirectory = new LocalGrainDirectory(this); RegistrarManager.InitializeGrainDirectoryManager(localGrainDirectory, globalConfig.GlobalSingleInstanceNumberRetries); // Now the activation directory. // This needs to know which router to use so that it can keep the global directory in synch with the local one. activationDirectory = new ActivationDirectory(); // Now the consistent ring provider RingProvider = GlobalConfig.UseVirtualBucketsConsistentRing ? (IConsistentRingProvider) new VirtualBucketsRingProvider(SiloAddress, GlobalConfig.NumVirtualBucketsConsistentRing) : new ConsistentRingProvider(SiloAddress); // to preserve backwards compatibility, only use the service provider to inject grain dependencies if the user supplied his own // service provider, meaning that he is explicitly opting into it. var grainCreator = new GrainCreator(grainRuntime, usingCustomServiceProvider ? Services : null); Action <Dispatcher> setDispatcher; catalog = new Catalog(Constants.CatalogId, SiloAddress, Name, LocalGrainDirectory, typeManager, scheduler, activationDirectory, config, grainCreator, out setDispatcher); var dispatcher = new Dispatcher(scheduler, messageCenter, catalog, config); setDispatcher(dispatcher); RuntimeClient.Current = new InsideRuntimeClient( dispatcher, catalog, LocalGrainDirectory, SiloAddress, config, RingProvider, typeManager, grainFactory); messageCenter.RerouteHandler = InsideRuntimeClient.Current.RerouteMessage; messageCenter.SniffIncomingMessage = InsideRuntimeClient.Current.SniffIncomingMessage; siloStatistics.MetricsTable.Scheduler = scheduler; siloStatistics.MetricsTable.ActivationDirectory = activationDirectory; siloStatistics.MetricsTable.ActivationCollector = catalog.ActivationCollector; siloStatistics.MetricsTable.MessageCenter = messageCenter; DeploymentLoadPublisher.CreateDeploymentLoadPublisher(this, globalConfig); PlacementDirectorsManager.CreatePlacementDirectorsManager(globalConfig); // Now the incoming message agents incomingSystemAgent = new IncomingMessageAgent(Message.Categories.System, messageCenter, activationDirectory, scheduler, dispatcher); incomingPingAgent = new IncomingMessageAgent(Message.Categories.Ping, messageCenter, activationDirectory, scheduler, dispatcher); incomingAgent = new IncomingMessageAgent(Message.Categories.Application, messageCenter, activationDirectory, scheduler, dispatcher); membershipFactory = new MembershipFactory(); multiClusterFactory = new MultiClusterOracleFactory(); reminderFactory = new LocalReminderServiceFactory(); SystemStatus.Current = SystemStatus.Created; StringValueStatistic.FindOrCreate(StatisticNames.SILO_START_TIME, () => LogFormatter.PrintDate(startTime)); // this will help troubleshoot production deployment when looking at MDS logs. logger.Info(ErrorCode.SiloInitializingFinished, "-------------- Started silo {0}, ConsistentHashCode {1:X} --------------", SiloAddress.ToLongString(), SiloAddress.GetConsistentHashCode()); }