/// <summary> /// Updates the replicator settings. Security credentials is the only setting that can be changed using this API /// </summary> /// <param name="updatedSettings"> New settings to be updated</param> protected void UpdateReplicatorSettings(ReliableStateManagerReplicatorSettings updatedSettings) { if (this.replicaState != ReplicaState.Opened) { throw new FabricException(FabricErrorCode.NotReady); } this.transactionalReplicator.LoggingReplicator.UpdateReplicatorSettings(updatedSettings); }
private static ReliableStateManagerReplicatorSettings GetReplicatorSettings(string endpoint) { var replicatorSettings = new ReliableStateManagerReplicatorSettings() { ReplicatorAddress = endpoint, SecurityCredentials = SecurityCredentials.LoadClusterSettings() }; return(replicatorSettings); }
private void UpdateReplicatorSettings(string endpoint) { ReliableStateManagerReplicatorSettings replicatorSettings = GetReplicatorSettings(endpoint, true); IStateProviderReplica stateProviderReplica = ((ReliableStateManager)this.StateManager).Replica; Microsoft.ServiceFabric.Data.ReliableStateManagerImpl impl = (Microsoft.ServiceFabric.Data.ReliableStateManagerImpl)stateProviderReplica; impl.Replicator.LoggingReplicator.UpdateReplicatorSettings(replicatorSettings); UpgradeOrchestrationTrace.TraceSource.WriteInfo(TraceType, "Updated replicator settings"); }
private void UpdateReplicatorSettings(string endpoint) { ReliableStateManagerReplicatorSettings replicatorSettings = GetReplicatorSettings(endpoint); var stateProviderReplica = ((ReliableStateManager)this.StateManager).Replica; var impl = (ReliableStateManagerImpl)stateProviderReplica; impl.Replicator.LoggingReplicator.UpdateReplicatorSettings(replicatorSettings); BackupRestoreTrace.TraceSource.WriteInfo(TraceType, "Updated replicator settings"); }
private static ReliableStateManagerReplicatorSettings GetReplicatorSettings(string endpoint, bool enableEndpointV2) { SecurityCredentials securityCredentials = null; if (enableEndpointV2) { securityCredentials = SecurityCredentials.LoadClusterSettings(); } ReliableStateManagerReplicatorSettings replicatorSettings = new ReliableStateManagerReplicatorSettings() { ReplicatorAddress = endpoint, SecurityCredentials = securityCredentials }; return(replicatorSettings); }
internal static void SetupLoggerPath( ref ReliableStateManagerReplicatorSettings replicatorSettings, ref StatefulServiceInitializationParameters initializationParameters) { string pathToSharedContainer; // Use this when running with the kernel mode logger as all replicas for all nodes should use the same log if (string.IsNullOrEmpty(replicatorSettings.SharedLogId) || string.IsNullOrEmpty(replicatorSettings.SharedLogPath)) { string fabricDataRoot; try { fabricDataRoot = System.Fabric.Common.FabricEnvironment.GetDataRoot(); } catch (Exception) { // // If the Fabric Data Root does not exist then we may be running in a container. And in // this case we count on the driver to do the mapping into the host path. So pick a random // path here knowing it will be mapped. // fabricDataRoot = "q:\\"; } // Use default log id and location {3CA2CCDA-DD0F-49c8-A741-62AAC0D4EB62} var staticLogContainerGuid = Constants.DefaultSharedLogContainerGuid; pathToSharedContainer = System.IO.Path.Combine( fabricDataRoot, Constants.DefaultSharedLogSubdirectory); pathToSharedContainer = System.IO.Path.Combine(pathToSharedContainer, Constants.DefaultSharedLogName); replicatorSettings.SharedLogId = staticLogContainerGuid; replicatorSettings.SharedLogPath = pathToSharedContainer; } }
/// <summary> /// OpenAsync is called when the replica is going to be actually used /// </summary> /// <param name="openMode">Open mode.</param> /// <param name="partitionObject">Service partition</param> /// <param name="cancellationToken">Cancellation token.</param> /// <returns>Task that represents the asynchronous operation.</returns> async Task <IReplicator> IStatefulServiceReplica.OpenAsync( ReplicaOpenMode openMode, IStatefulServicePartition partitionObject, CancellationToken cancellationToken) { FabricEvents.Events.Lifecycle( this.tracer.Type, "OpenAsync" + " openMode: " + openMode + " replica: " + this.initializationParameters.ReplicaId); TaskScheduler.UnobservedTaskException += this.ProcessUnobservedTaskException; // Store the partitionObject this.partition = partitionObject; var statefulServiceContext = new StatefulServiceContext( FabricRuntime.GetNodeContext(), this.initializationParameters.CodePackageActivationContext, this.initializationParameters.ServiceTypeName, this.initializationParameters.ServiceName, this.initializationParameters.InitializationData, this.initializationParameters.PartitionId, this.initializationParameters.ReplicaId); this.transactionalReplicator.Initialize(statefulServiceContext, partitionObject); FabricEvents.Events.Lifecycle(this.tracer.Type, "OpenAsync: StateManager initialized"); // create the replicator // The Windows Fabric Replicator is used to actually replicate the data // The ReplicatorSettings are used for configuring the replicator - here we ask for them from the derived class // When using service groups Replicator Settings are described in the Settings.xml inside the configuration package. // So when the service is part of a service group it should use null as its Replicator Setting. FabricReplicator replicator; ReliableStateManagerReplicatorSettings replicatorSettings = null; var onOpenInvoked = false; try { if (this.Partition is IServiceGroupPartition) { replicatorSettings = new ReliableStateManagerReplicatorSettings(); ReliableStateManagerReplicatorSettingsUtil.LoadDefaultsIfNotSet(ref replicatorSettings); replicator = this.partition.CreateReplicator( this.transactionalReplicator, ReliableStateManagerReplicatorSettingsUtil.ToReplicatorSettings(replicatorSettings)); } else { replicatorSettings = await this.OnOpenAsync(cancellationToken).ConfigureAwait(false); onOpenInvoked = true; if (replicatorSettings == null) { replicatorSettings = new ReliableStateManagerReplicatorSettings(); } ReliableStateManagerReplicatorSettingsUtil.LoadDefaultsIfNotSet(ref replicatorSettings); replicator = this.partition.CreateReplicator( this.transactionalReplicator, ReliableStateManagerReplicatorSettingsUtil.ToReplicatorSettings(replicatorSettings)); } ServiceReplicaUtils.SetupLoggerPath(ref replicatorSettings, ref this.initializationParameters); var transactionalReplicatorSettings = new TransactionalReplicatorSettings { PublicSettings = replicatorSettings }; ReliableStateManagerReplicatorSettingsUtil.LoadInternalSettingsDefault(ref transactionalReplicatorSettings); this.stateReplicator = replicator.StateReplicator; this.transactionalReplicator.LoggingReplicator.FabricReplicator = this.stateReplicator; this.transactionalReplicator.LoggingReplicator.Tracer = this.tracer; // Starting local recovery await this.transactionalReplicator.OpenAsync(openMode, transactionalReplicatorSettings).ConfigureAwait(false); // Change state this.replicaState = ReplicaState.Opened; FabricEvents.Events.Lifecycle( this.tracer.Type, "OpenAsync: Finished opening replica " + this.initializationParameters.ReplicaId + " ReplicatorAddress: " + replicatorSettings.ReplicatorAddress + " ReplicatorListenAddress: " + replicatorSettings.ReplicatorListenAddress + " ReplicatorPublishAddress: " + replicatorSettings.ReplicatorPublishAddress); return(replicator); } catch (Exception e) { int innerHResult = 0; var flattenedException = Utility.FlattenException(e, out innerHResult); FabricEvents.Events.Exception_TStatefulServiceReplica( this.tracer.Type, "OpenAsync", flattenedException.GetType().ToString(), flattenedException.Message, flattenedException.HResult != 0 ? flattenedException.HResult : innerHResult, flattenedException.StackTrace); if (onOpenInvoked) { this.OnAbort(); } TaskScheduler.UnobservedTaskException -= this.ProcessUnobservedTaskException; throw; } }