/// <summary>Faults if exception is provided, otherwise calls through to decorated storage provider.</summary> /// <param name="grainType">Type of this grain [fully qualified class name]</param> /// <param name="grainReference">Grain reference object for this grain.</param> /// <param name="grainState">Copy of last-known state data object for this grain.</param> /// <returns>Completion promise for the Delete operation on the specified grain.</returns> public async Task ClearStateAsync <T>(string grainType, GrainReference grainReference, IGrainState <T> grainState) { IStorageFaultGrain faultGrain = grainFactory.GetGrain <IStorageFaultGrain>(grainType); try { await InsertDelay(); await faultGrain.OnClear(grainReference); } catch (Exception) { logger.LogInformation( "Fault injected for ClearState for grain {GrainId} of type {GrainType}", grainReference.GrainId, grainType); throw; } logger.LogInformation( "ClearState for grain {GrainId} of type {GrainType}", grainReference.GrainId, grainType); await realStorageProvider.ClearStateAsync(grainType, grainReference, grainState); }
/// <summary> /// Async method to cause write of the current grain state data into backing store. /// </summary> public async Task ClearStateAsync() { const string what = "ClearState"; try { CheckRuntimeContext(); Stopwatch sw = Stopwatch.StartNew(); // Clear (most likely Delete) state from external storage await store.ClearStateAsync(name, grainRef, grainState); sw.Stop(); // Reset the in-memory copy of the state grainState.State = new TState(); // Update counters StorageStatisticsGroup.OnStorageDelete(name, grainRef, sw.Elapsed); } catch (Exception exc) { StorageStatisticsGroup.OnStorageDeleteError(name, grainRef); string errMsg = MakeErrorMsg(what, exc); this.logger.Error((int)ErrorCode.StorageProvider_DeleteFailed, errMsg, exc); if (!(exc is OrleansException)) { throw new OrleansException(errMsg, exc); } throw; } }
private async Task TestClearAsync <TGrain, TState, TKey>() where TState : Entity <TKey>, new() where TGrain : Grain <TState> { TestGrainState <TState> grainState = Internal.Utils.CreateAndStoreGrainState <TState>(_serviceProvider); TestGrainReference grainRef = TestGrainReference.Create(grainState.State); await _storage.ClearStateAsync(typeof(TGrain).FullName, grainRef, grainState ); var actual = Internal.Utils.FetchEntityFromDb(_serviceProvider, grainState.State); Assert.Null(actual); }
private async Task <GrainState <TestStoreGrainState> > Test_PersistenceProvider_WriteClearRead(string grainTypeName, IGrainStorage store, GrainState <TestStoreGrainState> grainState = null, GrainId grainId = default) { GrainReference reference = (GrainReference)this.fixture.InternalGrainFactory.GetGrain(grainId.IsDefault ? (GrainId)LegacyGrainId.NewId() : grainId); if (grainState == null) { grainState = TestStoreGrainState.NewRandomState(); } Stopwatch sw = new Stopwatch(); sw.Start(); await store.WriteStateAsync(grainTypeName, reference, grainState); TimeSpan writeTime = sw.Elapsed; sw.Restart(); await store.ClearStateAsync(grainTypeName, reference, grainState); var storedGrainState = new GrainState <TestStoreGrainState> { State = new TestStoreGrainState() }; await store.ReadStateAsync(grainTypeName, reference, storedGrainState); TimeSpan readTime = sw.Elapsed; this.output.WriteLine("{0} - Write time = {1} Read time = {2}", store.GetType().FullName, writeTime, readTime); Assert.NotNull(storedGrainState.State); Assert.Equal(default(string), storedGrainState.State.A); Assert.Equal(default(int), storedGrainState.State.B); Assert.Equal(default(long), storedGrainState.State.C); return(storedGrainState); }