Пример #1
0
    public async Task RestoreOperationResultAsync(RestoreOperationResult operationResult, TimeSpan timeout,
                                                  CancellationToken cancellationToken)
    {
        BackupRestoreTrace.TraceSource.WriteInfo(TraceType, "RestoreOperationResultAsync invoked for partition {0}, ErrorCode {1}, message {2}",
                                                 operationResult.PartitionId, operationResult.ErrorCode, operationResult.Message);

        var restoreStore = await RestoreStore.CreateOrGetRestoreStatusStore(this.statefulService);

        var workItemQueue = await WorkItemQueue.CreateOrGetWorkItemQueue(this.statefulService);

        string brsServiceUri = await UtilityHelper.GetCustomServiceUri(operationResult.ServiceName, timeout, cancellationToken);

        var fabricUri = UtilityHelper.GetBackupMappingKey(brsServiceUri, operationResult.PartitionId.ToString());

        WorkItem pushPolicyAfterRestore = new SendToServiceNodeWorkItem(brsServiceUri, operationResult.PartitionId.ToString(), new WorkItemInfo()
        {
            WorkItemType = WorkItemPropogationType.UpdatePolicyAfterRestore,
        });
        await UtilityHelper.InvokeWithRetry(async() =>
        {
            BackupRestoreTrace.TraceSource.WriteInfo(TraceType, "Trying to Update the Restore request for partition {0}", operationResult.PartitionId);
            using (ITransaction transaction = this.statefulService.StateManager.CreateTransaction())
            {
                var restoreStatus = await restoreStore.GetValueWithUpdateLockModeAsync(fabricUri, timeout, cancellationToken, transaction);
                if ((restoreStatus != null) &&
                    (restoreStatus.RestoreStatusState == RestoreState.RestoreInProgress ||
                     restoreStatus.RestoreStatusState == RestoreState.Accepted) &&
                    (restoreStatus.RestoreRequestGuid.Equals(operationResult.OperationId)))
                //TODO: Add check for each request by Guid
                {
                    var updatedRestoreStatus = restoreStatus.ToBuilder()
                                               .WithState(operationResult.ErrorCode != 0 ? RestoreState.Failure : RestoreState.Success)
                                               .WithErrorCode(operationResult.ErrorCode)
                                               .WithMessage(operationResult.Message)
                                               .WithTimeStampUtc(operationResult.TimeStampUtc)
                                               .Build();

                    await restoreStore.UpdateValueAsync(fabricUri, updatedRestoreStatus, timeout, cancellationToken, transaction);
                    await workItemQueue.AddWorkItem(pushPolicyAfterRestore, timeout, cancellationToken, transaction);
                    await transaction.CommitAsync();
                    BackupRestoreTrace.TraceSource.WriteInfo(TraceType, "Updated the Restore request for partition {0}", operationResult.PartitionId);
                }
                else
                {
                    transaction.Abort();
                }
            }
        });
    }
Пример #2
0
        NativeCommon.IFabricAsyncOperationContext NativeBackupRestoreService.IFabricBackupRestoreService.BeginReportRestoreOperationResult(IntPtr operationResult, uint timeoutMilliseconds,
                                                                                                                                           NativeCommon.IFabricAsyncOperationCallback callback)
        {
            var managedOperationResult = RestoreOperationResult.FromNative(operationResult);
            var managedTimout          = TimeSpan.FromMilliseconds(timeoutMilliseconds);

            return(Utility.WrapNativeAsyncMethodImplementation(
                       cancellationToken =>
                       this.Service.RestoreOperationResultAsync(
                           managedOperationResult,
                           managedTimout,
                           cancellationToken),
                       callback,
                       "BackupRestoreServiceBroker.RestoreOperationResultAsync",
                       ThreadErrorMessageSetter));
        }