Ejemplo n.º 1
0
        /// <summary> Deleet / Clear state data function for this storage provider. </summary>
        /// <see cref="IStorageProvider.ClearStateAsync"/>
        public Task ClearStateAsync(string grainType, GrainReference grainReference, IGrainState grainState)
        {
            int num = FindStorageShard(grainType, grainReference);
            IStorageProvider provider = storageProviders[num];

            return(provider.ClearStateAsync(grainType, grainReference, grainState));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Async method to cause write of the current grain state data into backing store.
        /// </summary>
        public async Task ClearStateAsync()
        {
            const string   what     = "ClearState";
            Stopwatch      sw       = Stopwatch.StartNew();
            GrainReference grainRef = baseGrain.GrainReference;

            try
            {
                // Clear (most likely Delete) state from external storage
                await store.ClearStateAsync(grainTypeName, grainRef, grain.GrainState);

                // Reset the in-memory copy of the state
                grain.GrainState.State = Activator.CreateInstance(grain.GrainState.State.GetType());

                // Update counters
                StorageStatisticsGroup.OnStorageDelete(store, grainTypeName, grainRef, sw.Elapsed);
            }
            catch (Exception exc)
            {
                StorageStatisticsGroup.OnStorageDeleteError(store, grainTypeName, grainRef);

                string errMsg = MakeErrorMsg(what, exc);
                store.Log.Error((int)ErrorCode.StorageProvider_DeleteFailed, errMsg, exc);
                throw new OrleansException(errMsg, exc);
            }
            finally
            {
                sw.Stop();
            }
        }
Ejemplo n.º 3
0
        /// <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
            {
                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(store, name, grainRef, sw.Elapsed);
            }
            catch (Exception exc)
            {
                StorageStatisticsGroup.OnStorageDeleteError(store, name, grainRef);

                string errMsg = MakeErrorMsg(what, exc);
                store.Log.Error((int)ErrorCode.StorageProvider_DeleteFailed, errMsg, exc);
                if (!(exc is OrleansException))
                {
                    throw new OrleansException(errMsg, exc);
                }
                throw;
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Async method to cause write of the current grain state data into backin store.
        /// </summary>
        public async Task ClearStateAsync()
        {
            const string     what     = "ClearState";
            Stopwatch        sw       = Stopwatch.StartNew();
            GrainReference   grainRef = RuntimeClient.Current.CurrentActivationData.GrainReference;
            IStorageProvider storage  = GetCheckStorageProvider(what);

            try
            {
                // Clear (most likely Delete) state from external storage
                await storage.ClearStateAsync(grainTypeName, grainRef, this);

                // Null out the in-memory copy of the state
                SetAll(null);
                // Update counters
                StorageStatisticsGroup.OnStorageDelete(storage, grainTypeName, grainRef, sw.Elapsed);
            }
            catch (Exception exc)
            {
                StorageStatisticsGroup.OnStorageDeleteError(storage, grainTypeName, grainRef);
                string errMsg = MakeErrorMsg(what, grainRef, exc);

                storage.Log.Error((int)ErrorCode.StorageProvider_DeleteFailed, errMsg, exc);
                throw new OrleansException(errMsg, exc);
            }
            finally
            {
                sw.Stop();
            }
        }
Ejemplo n.º 5
0
        private async Task <GrainState <TestStoreGrainState> > Test_PersistenceProvider_WriteClearRead(string grainTypeName,
                                                                                                       IStorageProvider store, GrainState <TestStoreGrainState> grainState = null, GrainId grainId = null)
        {
            GrainReference reference = GrainReference.FromGrainId(grainId ?? GrainId.NewId());

            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;

            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);
        }