/// <inheritdoc/> protected override async Task ReadAsync() { enter_operation("ReadAsync"); while (true) { try { // for manual testing //await Task.Delay(5000); await globalGrainStorage.ReadStateAsync(grainTypeName, Services.GrainReference, GlobalStateCache); Services.Log(LogLevel.Debug, "read success {0}", GlobalStateCache); LastPrimaryIssue.Resolve(Host, Services); break; // successful } catch (Exception e) { LastPrimaryIssue.Record(new ReadFromStateStorageFailed() { Exception = e }, Host, Services); } Services.Log(LogLevel.Debug, "read failed {0}", LastPrimaryIssue); await LastPrimaryIssue.DelayBeforeRetry(); } exit_operation("ReadAsync"); }
public async Task ReadCustomGetterGrainState() { var entity = new EntityWithGuidKey(); Internal.Utils.StoreGrainState(_serviceProvider, entity); var state = new GrainStateWrapper <EntityWithGuidKey>() { Value = entity }; var grainState = new TestGrainState <GrainStateWrapper <EntityWithGuidKey> >() { State = state }; TestGrainReference grainRef = TestGrainReference.Create(entity); grainState.State = null; await _storage.ReadStateAsync(typeof(GrainWithCustomStateGuidKey).FullName, grainRef, grainState ); Internal.Utils.AssertEntityEqualityVsDb( _serviceProvider, grainState.State?.Value); }
public async Task ReadConfiguredCustomKeyStateShouldPass() { GrainState <ConfiguredEntityWithCustomGuidKey> grainState = Internal.Utils.CreateAndStoreGrainState <ConfiguredEntityWithCustomGuidKey>(_serviceProvider); TestGrainReference grainRef = TestGrainReference.Create <ConfiguredGrainWithCustomGuidKey>( grainState.State.CustomKey); await _storage.ReadStateAsync(typeof(ConfiguredGrainWithCustomGuidKey).FullName, grainRef, grainState); }
private async Task <GrainState <TestStoreGrainState> > Test_PersistenceProvider_WriteRead(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(); 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.Equal(grainState.State.A, storedGrainState.State.A); Assert.Equal(grainState.State.B, storedGrainState.State.B); Assert.Equal(grainState.State.C, storedGrainState.State.C); return(storedGrainState); }
private async Task Test_PersistenceProvider_Read(string grainTypeName, IGrainStorage store, GrainState <TestStoreGrainState> grainState = null, GrainId grainId = default) { var reference = this.fixture.InternalGrainFactory.GetGrain(grainId.IsDefault ? (GrainId)LegacyGrainId.NewId() : grainId); if (grainState == null) { grainState = new GrainState <TestStoreGrainState>(new TestStoreGrainState()); } var storedGrainState = new GrainState <TestStoreGrainState>(new TestStoreGrainState()); Stopwatch sw = new Stopwatch(); sw.Start(); await store.ReadStateAsync(grainTypeName, reference, storedGrainState); TimeSpan readTime = sw.Elapsed; this.output.WriteLine("{0} - Read time = {1}", store.GetType().FullName, readTime); var storedState = storedGrainState.State; Assert.Equal(grainState.State.A, storedState.A); Assert.Equal(grainState.State.B, storedState.B); Assert.Equal(grainState.State.C, storedState.C); }
/// <summary> /// Async method to cause refresh of the current grain state data from backing store. /// Any previous contents of the grain state data will be overwritten. /// </summary> public async Task ReadStateAsync() { const string what = "ReadState"; Stopwatch sw = Stopwatch.StartNew(); try { CheckRuntimeContext(); await store.ReadStateAsync(name, grainRef, grainState); StorageStatisticsGroup.OnStorageRead(name, grainRef, sw.Elapsed); } catch (Exception exc) { StorageStatisticsGroup.OnStorageReadError(name, grainRef); string errMsg = MakeErrorMsg(what, exc); this.logger.Error((int)ErrorCode.StorageProvider_ReadFailed, errMsg, exc); if (!(exc is OrleansException)) { throw new OrleansException(errMsg, exc); } throw; } finally { sw.Stop(); } }
protected override async Task ReadAsync() { enter_operation("ReadAsync"); while (true) { try { await _grainStorage.ReadStateAsync(_grainTypeName, Services.GrainReference, _snapshotState); await EnsureStateGlobalVersion(); Services.Log(LogLevel.Debug, "read success {0}", _snapshotState); if (_confirmedVersionInternal < _snapshotState.StateAndMetaData.SnapshotVersion) { _confirmedVersionInternal = _snapshotState.StateAndMetaData.SnapshotVersion; _confirmedViewInternal = _snapshotState.StateAndMetaData.Snapshot.DeepClone(); } var logs = await RetrieveLogSegment( _confirmedVersionInternal, _snapshotState.StateAndMetaData.GlobalVersion); Services.Log(LogLevel.Debug, "read success {0}", logs); UpdateConfirmedView(logs); LastPrimaryIssue.Resolve(Host, Services); break; // successful } catch (Exception e) { LastPrimaryIssue.Record(new ReadFromSnapshotStorageFailed() { Exception = e }, Host, Services); } Services.Log(LogLevel.Debug, "read failed {0}", LastPrimaryIssue); await LastPrimaryIssue.DelayBeforeRetry(); } exit_operation("ReadAsync"); }
public async Task StateShoudContainETag() { GrainState <EntityWithIntegerKeyWithEtag> grainState = Internal.Utils.CreateAndStoreGrainState <EntityWithIntegerKeyWithEtag>(_serviceProvider); TestGrainReference grainRef = TestGrainReference.Create(grainState.State); await _storage.ReadStateAsync(typeof(GrainWithIntegerKeyWithEtag).FullName, grainRef, grainState); string expected = BitConverter.ToString(grainState.State.ETag) .Replace("-", string.Empty); Assert.Equal(expected, grainState.ETag); }
/// <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">State data object to be populated for this grain.</param> /// <returns>Completion promise for the Read operation on the specified grain.</returns> public async Task ReadStateAsync(string grainType, GrainReference grainReference, IGrainState grainState) { IStorageFaultGrain faultGrain = grainFactory.GetGrain <IStorageFaultGrain>(grainType); try { await InsertDelay(); await faultGrain.OnRead(grainReference); } catch (Exception) { logger.Info($"Fault injected for ReadState for grain {grainReference} of type {grainType}, "); throw; } logger.Info($"ReadState for grain {grainReference} of type {grainType}"); await realStorageProvider.ReadStateAsync(grainType, grainReference, grainState); }
private async Task TestReadAsync <TGrain, TState, TKey>() where TState : Entity <TKey>, new() where TGrain : Grain <TState> { GrainState <TState> grainState = Internal.Utils.CreateAndStoreGrainState <TState>(_serviceProvider); TestGrainReference grainRef = TestGrainReference.Create(grainState.State); grainState.State = null; await _storage.ReadStateAsync(typeof(TGrain).FullName, grainRef, grainState ); Internal.Utils.AssertEntityEqualityVsDb(_serviceProvider, grainState.State); }
/// <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">State data object to be populated for this grain.</param> /// <returns>Completion promise for the Read operation on the specified grain.</returns> public async Task ReadStateAsync <T>(string grainType, GrainReference grainReference, IGrainState <T> grainState) { IStorageFaultGrain faultGrain = grainFactory.GetGrain <IStorageFaultGrain>(grainType); try { await InsertDelay(); await faultGrain.OnRead(grainReference); } catch (Exception) { logger.LogInformation( "Fault injected for ReadState for grain {GrainId} of type {GrainType}", grainReference.GrainId, grainType); throw; } logger.LogInformation( "ReadState for grain {GrainId} of type {GrainType}", grainReference.GrainId, grainType); await realStorageProvider.ReadStateAsync(grainType, grainReference, grainState); }