Example #1
0
        /// <summary>
        /// Serializes the object to JSON.
        /// </summary>
        /// <param name="writer">The <see cref="T: Newtonsoft.Json.JsonWriter" /> to write to.</param>
        /// <param name="obj">The object to serialize to JSON.</param>
        internal static void Serialize(JsonWriter writer, PartitionDataLossProgress obj)
        {
            // Required properties are always serialized, optional properties are serialized when not null.
            writer.WriteStartObject();
            writer.WriteProperty(obj.State, "State", OperationStateConverter.Serialize);
            if (obj.InvokeDataLossResult != null)
            {
                writer.WriteProperty(obj.InvokeDataLossResult, "InvokeDataLossResult", InvokeDataLossResultConverter.Serialize);
            }

            writer.WriteEndObject();
        }
Example #2
0
            internal static PartitionDataLossProgress CreateFromNative(NativeClient.IFabricPartitionDataLossProgressResult nativeResult)
            {
                if (nativeResult == null)
                {
                    return(null);
                }

                var progress = PartitionDataLossProgress.FromNative(nativeResult.get_Progress());

                GC.KeepAlive(nativeResult);
                return(progress);
            }
        public async Task <PartitionDataLossProgress> GetInvokeDataLossProgressAsync(
            Guid operationId,
            TimeSpan timeout,
            CancellationToken cancellationToken)
        {
            this.ThrowIfNotReady();
            PartitionDataLossProgress progress = null;

            TestabilityTrace.TraceSource.WriteInfo(TraceType, "Inside GetInvokeDataLossProgressAsync, operationId = {0}", operationId);

            try
            {
                ActionStateBase actionState = await this.MessageProcessor.ProcessGetProgressAsync(operationId, timeout, cancellationToken);

                StepStateNames stateName = actionState.StateProgress.Peek();

                TestCommandProgressState state = FaultAnalysisServiceUtility.ConvertState(actionState, TraceType);

                InvokeDataLossState invokeDataLossState = actionState as InvokeDataLossState;
                if (invokeDataLossState == null)
                {
                    throw new InvalidCastException("State object could not be converted");
                }

                StepStateNames stepState         = actionState.StateProgress.Peek();
                var            selectedPartition = new SelectedPartition
                {
                    ServiceName = invokeDataLossState.Info.PartitionSelector.ServiceName,
                    PartitionId = invokeDataLossState.Info.PartitionId
                };

                PartitionDataLossResult result = new PartitionDataLossResult(selectedPartition, actionState.ErrorCausingRollback);

                progress = new PartitionDataLossProgress(state, result);
                TestabilityTrace.TraceSource.WriteInfo(
                    TraceType,
                    "{0} - {1} progress - {2}, Exception - {3}",
                    operationId,
                    ActionType.InvokeDataLoss,
                    progress.Result != null ? progress.Result.SelectedPartition.ToString() : FASConstants.UnavailableMessage,
                    (progress.Result != null && progress.Result.Exception != null) ? progress.Result.Exception.ToString() : FASConstants.UnavailableMessage);
            }
            catch (Exception e)
            {
                TestabilityTrace.TraceSource.WriteWarning(TraceType, "{0} - Caught {1}", operationId, e.ToString());
                FaultAnalysisServiceUtility.ThrowTransientExceptionIfRetryable(e);

                throw;
            }

            return(progress);
        }
        internal static async Task <PartitionDataLossProgress> GetPartitionDataLossProgress(Guid dataLossGuid, TimeSpan timeout)
        {
            PartitionDataLossProgress partitionDataLossProgress = null;

            try
            {
                partitionDataLossProgress = await InvokeWithRetryAsync <PartitionDataLossProgress>(() =>
                {
                    return(FabricClient.TestManager.GetPartitionDataLossProgressAsync(dataLossGuid));
                }
                                                                                                   );
            }
            catch (Exception)
            {
            }
            return(partitionDataLossProgress);
        }
        private async Task <PartitionDataLossProgress> GetPartitionDataLossProgress(string processQueueTypeTrace)
        {
            PartitionDataLossProgress partitionDataLossProgress = null;

            try
            {
                partitionDataLossProgress = await FabricClientHelper.GetPartitionDataLossProgress(this.DataLossGuid, Constants.GetDataLossProgressTimeout);

                BackupRestoreTrace.TraceSource.WriteInfo(processQueueTypeTrace,
                                                         "Get GetPartitionDataLossProgress Resulted as {0} with State as {1}",
                                                         partitionDataLossProgress.Result, partitionDataLossProgress.State.ToString());
            }
            catch (Exception exception)
            {
                BackupRestoreTrace.TraceSource.WriteInfo(processQueueTypeTrace,
                                                         "Exception in GetPartitionDataLossProgress {0}",
                                                         exception.ToString());
            }
            return(partitionDataLossProgress);
        }
        public async Task ProcessRestore(StatefulService statefulService, CancellationToken cancellationToken, string processQueueTypeTrace)
        {
            BackupRestoreTrace.TraceSource.WriteInfo(processQueueTypeTrace, "Processing the Restore for request Service Uri :  {0} , PartitionId {1}", this.ServiceUri, this.PartitionId);
            WorkItemStore workItemStore = await WorkItemStore.CreateOrGetWorkItemStore(statefulService);

            RestoreStore restoreStore = await RestoreStore.CreateOrGetRestoreStatusStore(statefulService);

            string fabricUri = UtilityHelper.GetBackupMappingKey(this.ServiceUri, this.PartitionId);
            PartitionDataLossProgress partitionDataLossProgress = await this.GetPartitionDataLossProgress(processQueueTypeTrace);

            if (this.RestoreStatusStateModel == RestoreStatusStateModel.TriggerDataLoss)
            {
                if (partitionDataLossProgress == null)
                {
                    bool isInitiateDataLossSuccess = await this.InitiateDataLoss(processQueueTypeTrace);

                    if (isInitiateDataLossSuccess)
                    {
                        this.RestoreStatusStateModel = RestoreStatusStateModel.DataLossTriggered;
                    }
                }
                await workItemStore.UpdateValueAsync(this.WorkItemGuid, this);

                BackupRestoreTrace.TraceSource.WriteInfo(processQueueTypeTrace, "RestoreStatusStateModel as DataLossTriggered for request Service Uri :  {0} , PartitionId {1}", this.ServiceUri, this.PartitionId);
            }
            if (this.RestoreStatusStateModel == RestoreStatusStateModel.DataLossTriggered)
            {
                RestoreStatus restoreStatus = null;
                do
                {
                    partitionDataLossProgress = await this.GetPartitionDataLossProgress(processQueueTypeTrace);

                    switch (partitionDataLossProgress.State)
                    {
                    case TestCommandProgressState.Running:
                    case TestCommandProgressState.RollingBack:
                    case TestCommandProgressState.Completed:
                        break;

                    case TestCommandProgressState.Cancelled:
                    case TestCommandProgressState.Faulted:
                    case TestCommandProgressState.ForceCancelled:
                        this.DataLossGuid = Guid.NewGuid();
                        await workItemStore.UpdateValueAsync(this.WorkItemGuid, this);

                        await this.InitiateDataLoss(processQueueTypeTrace);

                        break;
                    }
                    await Task.Delay(Constants.CheckRestoreTimeSpan, cancellationToken);

                    restoreStatus = await restoreStore.GetValueAsync(fabricUri);

                    if (restoreStatus.RestoreStatusState == RestoreState.Timeout && restoreStatus.RestoreRequestGuid.Equals(this.RestoreRequestGuid))
                    {
                        partitionDataLossProgress = await this.GetPartitionDataLossProgress(processQueueTypeTrace);

                        switch (partitionDataLossProgress.State)
                        {
                        case TestCommandProgressState.Running:
                        case TestCommandProgressState.RollingBack:
                            await this.CancelDataLoss(processQueueTypeTrace);

                            break;

                        case TestCommandProgressState.Cancelled:
                        case TestCommandProgressState.Faulted:
                        case TestCommandProgressState.ForceCancelled:
                        case TestCommandProgressState.Completed:
                            break;
                        }
                    }
                } while ((restoreStatus.RestoreStatusState == RestoreState.RestoreInProgress ||
                          restoreStatus.RestoreStatusState == RestoreState.Accepted) &&
                         this.RestoreRequestGuid.Equals(restoreStatus.RestoreRequestGuid) &&
                         !cancellationToken.IsCancellationRequested);
                cancellationToken.ThrowIfCancellationRequested();
            }
        }