Exemple #1
0
        protected virtual async Task ReadSnapshotAsync()
        {
            if (Logger.IsEnabled(LogLevel.Trace))
            {
                Logger.LogTrace("Start read snapshot  with Id = {0}", GrainId.ToString());
            }
            try
            {
                Snapshot = await SnapshotStorage.Get(GrainId);

                if (Snapshot == default)
                {
                    //从归档中恢复状态
                    if (ArchiveOptions.On && LastArchive != default)
                    {
                        Snapshot = await ArchiveStorage.GetById(LastArchive.Id);
                    }
                }
                if (Snapshot == default)
                {
                    //新建状态
                    var createTask = CreateSnapshot();
                    if (!createTask.IsCompletedSuccessfully)
                    {
                        await createTask;
                    }
                }
                else if (IsTxShadow)
                {
                    Snapshot = new TxSnapshot <PrimaryKey, StateType>()
                    {
                        Base  = new TxSnapshotBase <PrimaryKey>(Snapshot.Base),
                        State = Snapshot.State
                    };
                }
                if (Logger.IsEnabled(LogLevel.Trace))
                {
                    Logger.LogTrace("The snapshot of id = {0} read completed, state version = {1}", GrainId.ToString(), this.Snapshot.Base.Version);
                }
            }
            catch (Exception ex)
            {
                if (Logger.IsEnabled(LogLevel.Critical))
                {
                    Logger.LogCritical(ex, "The snapshot of id = {0} read failed", GrainId.ToString());
                }
                throw;
            }
        }
Exemple #2
0
        protected virtual async Task ReadSnapshotAsync()
        {
            if (Logger.IsEnabled(LogLevel.Trace))
            {
                Logger.LogTrace(LogEventIds.GrainSnapshot, "Start read snapshot  with Id = {0} ,state version = {1}", GrainId.ToString(), Snapshot.Base.Version);
            }
            try
            {
                //从快照中恢复状态
                Snapshot = await SnapshotStorage.Get(GrainId);

                if (Snapshot == default)
                {
                    //从归档中恢复状态
                    if (ArchiveOptions.On && LastArchive != default)
                    {
                        Snapshot = await ArchiveStorage.GetState(LastArchive.Id);
                        await SaveSnapshotAsync(true, false);
                    }
                    if (Snapshot == default)
                    {
                        //新建状态
                        var createTask = CreateState();
                        if (!createTask.IsCompletedSuccessfully)
                        {
                            await createTask;
                        }
                    }
                }
                SnapshotEventVersion = Snapshot.Base.Version;
                if (Logger.IsEnabled(LogLevel.Trace))
                {
                    Logger.LogTrace(LogEventIds.GrainSnapshot, "The snapshot of id = {0} read completed, state version = {1}", GrainId.ToString(), Snapshot.Base.Version);
                }
            }
            catch (Exception ex)
            {
                if (Logger.IsEnabled(LogLevel.Critical))
                {
                    Logger.LogCritical(LogEventIds.GrainSnapshot, ex, "The snapshot of id = {0} read failed", GrainId.ToString());
                }
                throw;
            }
        }
Exemple #3
0
        protected virtual async Task ReadSnapshotAsync()
        {
            try
            {
                Snapshot = await SnapshotStorage.Get(GrainId);

                if (Snapshot is null)
                {
                    //从归档中恢复状态
                    if (ArchiveOptions.On && LastArchive != null)
                    {
                        Snapshot = await ArchiveStorage.GetById(LastArchive.Id);
                    }
                }
                if (Snapshot is null)
                {
                    //新建状态
                    var createTask = CreateSnapshot();
                    if (!createTask.IsCompletedSuccessfully)
                    {
                        await createTask;
                    }
                }
                else if (IsTxShadow)
                {
                    Snapshot = new TxSnapshot <PrimaryKey, StateType>()
                    {
                        Base  = new TxSnapshotBase <PrimaryKey>(Snapshot.Base),
                        State = Snapshot.State
                    };
                }
                if (Logger.IsEnabled(LogLevel.Trace))
                {
                    Logger.LogTrace("ReadSnapshot completed: {0}->{1}", GrainType.FullName, Serializer.Serialize(Snapshot));
                }
            }
            catch (Exception ex)
            {
                Logger.LogCritical(ex, "ReadSnapshot failed: {0}->{1}", GrainType.FullName, GrainId.ToString());
                throw;
            }
        }
Exemple #4
0
        protected virtual async Task ReadSnapshotAsync()
        {
            try
            {
                //从快照中恢复状态
                Snapshot = await SnapshotStorage.Get(GrainId);

                if (Snapshot is null)
                {
                    //从归档中恢复状态
                    if (ArchiveOptions.On && LastArchive != null)
                    {
                        Snapshot = await ArchiveStorage.GetById(LastArchive.Id);
                    }
                    if (Snapshot is null)
                    {
                        //新建状态
                        var createTask = CreateSnapshot();
                        if (!createTask.IsCompletedSuccessfully)
                        {
                            await createTask;
                        }
                    }
                }
                SnapshotEventVersion = Snapshot.Base.Version;
                if (Logger.IsEnabled(LogLevel.Trace))
                {
                    Logger.LogTrace("ReadSnapshot completed: {0}->{1}", GrainType.FullName, Serializer.Serialize(Snapshot));
                }
            }
            catch (Exception ex)
            {
                Logger.LogCritical(ex, "ReadSnapshot failed: {0}->{1}", GrainType.FullName, GrainId.ToString());
                throw;
            }
        }