public async Task BackupOperationResultAsync(BackupOperationResult operationResult, TimeSpan timeout, CancellationToken cancellationToken) { BackupRestoreTrace.TraceSource.WriteInfo(TraceType, "BackupOperationResultAsync invoked for partition {0}, OperationId {1} ErrorCode {2}, message {3}", operationResult.PartitionId, operationResult.OperationId, operationResult.ErrorCode, operationResult.Message); var backupPartitionStore = await BackupPartitionStore.CreateOrGetBackupPartitionStore(this.statefulService); var fabricUri = UtilityHelper.GetBackupMappingKey(await UtilityHelper.GetCustomServiceUri(operationResult.ServiceName, timeout, cancellationToken), operationResult.PartitionId.ToString()); await UtilityHelper.InvokeWithRetry(async() => { BackupRestoreTrace.TraceSource.WriteInfo(TraceType, "Trying to update the Backup Request for Partition Id {0} ", operationResult.PartitionId); using (ITransaction transaction = this.statefulService.StateManager.CreateTransaction()) { var backupPartitionStatus = await backupPartitionStore.GetValueWithUpdateLockModeAsync(fabricUri, timeout, cancellationToken, transaction); if ((backupPartitionStatus != null) && (backupPartitionStatus.BackupPartitionStatusState == BackupState.BackupInProgress || backupPartitionStatus.BackupPartitionStatusState == BackupState.Accepted) && backupPartitionStatus.OperationId.Equals(operationResult.OperationId)) // TODO : Also check for Guid for the request { var backupPartitionStatusBuilder = backupPartitionStatus.ToBuilder() .WithState(operationResult.ErrorCode != 0 ? BackupState.Failure : BackupState.Success) .WithErrorCode(operationResult.ErrorCode) .WithMessage(operationResult.Message) .WithTimeStampUtc(operationResult.TimeStampUtc); if (operationResult.ErrorCode == 0) { var updatedEpoch = new BackupEpoch { ConfigurationNumber = operationResult.EpochOfLastBackupRecord.ConfigurationNumber, DataLossNumber = operationResult.EpochOfLastBackupRecord.DataLossNumber }; backupPartitionStatusBuilder .WithEpochOfLastBackupRecord(updatedEpoch) .WithLsnOfLastBackupRecord(operationResult.LsnOfLastBackupRecord) .WithBackupId(operationResult.BackupId) .WithBackupLocation(operationResult.BackupLocation); } await backupPartitionStore.UpdateValueAsync(fabricUri, backupPartitionStatusBuilder.Build(), transaction); await transaction.CommitAsync(); BackupRestoreTrace.TraceSource.WriteInfo(TraceType, "Updated the Backup Request for Partition Id {0} ", operationResult.PartitionId); } else { transaction.Abort(); } } }); }
public NativeCommon.IFabricAsyncOperationContext BeginReportBackupOperationResult(IntPtr operationResult, uint timeoutMilliseconds, NativeCommon.IFabricAsyncOperationCallback callback) { var managedOperationResult = BackupOperationResult.FromNative(operationResult); var managedTimout = TimeSpan.FromMilliseconds(timeoutMilliseconds); return(Utility.WrapNativeAsyncMethodImplementation( cancellationToken => this.Service.BackupOperationResultAsync( managedOperationResult, managedTimout, cancellationToken), callback, "BackupRestoreServiceBroker.BackupOperationResultAsync", ThreadErrorMessageSetter)); }