private async Task WriteScheduleToReliableStoreAsync(ChaosScheduleDescription scheduleDescription, CancellationToken cancellationToken) { TestabilityTrace.TraceSource.WriteInfo(TraceComponent, "Enter WriteScheduleToReliableStoreAsync with scheduleDescription={0}", scheduleDescription.ToString()); this.StatusDictionary = this.StatusDictionary ?? await this.StateManager.GetOrAddAsync <IReliableDictionary <string, byte[]> >(FASConstants.ChaosSchedulerStateName).ConfigureAwait(false); await FaultAnalysisServiceUtility.RunAndReportFaultOnRepeatedFailure( Guid.Empty, () => this.WriteScheduleToReliableStoreHelperAsync(scheduleDescription, cancellationToken), this.partition, "WriteScheduleToReliableStoreHelperAsync", FASConstants.MaxRetriesForReliableDictionary, cancellationToken).ConfigureAwait(false); }
internal async Task SetScheduleAsync(ChaosScheduleDescription scheduleDescription, bool useAutoVersion, CancellationToken cancellationToken) { TestabilityTrace.TraceSource.WriteInfo(TraceComponent, "Enter SetScheduleAsync with scheduleDescription={0} and useAutoVersion={1}", scheduleDescription.ToString(), useAutoVersion); if (!this.stateSemaphore.Wait(ChaosConstants.SchedulerLockWaitMilliseconds, cancellationToken)) { TestabilityTrace.TraceSource.WriteWarning(TraceComponent, "SetScheduleAsync - did not acquire lock in provisioned time. Not progressing."); return; } try { TestabilityTrace.TraceSource.WriteInfo(TraceComponent, "stateSemaphore Acquired by SetScheduleAsync"); if (useAutoVersion || scheduleDescription.Version == this.scheduleDescription.Version) { var newScheduleDescription = new ChaosScheduleDescription(this.scheduleDescription.Version, scheduleDescription.Schedule); newScheduleDescription.IncrementVersion(); await this.SetScheduleInternalAsync(newScheduleDescription, cancellationToken).ConfigureAwait(false); } else { throw new System.ArgumentException( string.Format( StringResources.ChaosScheduler_ScheduleVersionMismatch, this.scheduleDescription.Version, scheduleDescription.Version), "ChaosScheduleDescription.Version"); } } finally { this.stateSemaphore.Release(); TestabilityTrace.TraceSource.WriteInfo(TraceComponent, "stateSemaphore Released by SetScheduleAsync"); } }