-
Notifications
You must be signed in to change notification settings - Fork 5.1k
[Storage] [DataMovement] Convert TransferStatus from enum to class #38374
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
b1d0eaf
WIP
amnguye 2ec9d50
Merge branch 'main' into feature/storage/dm-status
amnguye a2ab1b3
WIP
amnguye a0f761a
WIP
amnguye 04e6d46
WIP
amnguye c0ce59f
Merge branch 'main' into feature/storage/dm-status
amnguye a22c375
WIP - tests updated
amnguye 08eb456
Merge branch 'main' into feature/storage/dm-status
amnguye c7ce11f
Finished fixing tests with changes
amnguye 6a56b48
Cleanup
amnguye 8c89104
Merge branch 'main' into feature/storage/dm-status
amnguye 42276f3
ExportApi
amnguye 2325ddb
WIP
amnguye 407a88f
Fixes to live tests
amnguye b2c92cc
PR Comments - part 1
amnguye 99ad775
Merge branch 'main' into feature/storage/dm-status
amnguye 00b194a
Export API
amnguye 39298ca
Merge branch 'main' into feature/storage/dm-status
amnguye f6fb5ec
Merge branch 'main' into feature/storage/dm-status
amnguye 69db6d5
PR Comments
amnguye File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
sdk/storage/Azure.Storage.DataMovement/src/DataTransferState.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System.Threading; | ||
|
|
||
| namespace Azure.Storage.DataMovement | ||
| { | ||
| /// <summary> | ||
| /// Defines the types of the state a transfer can have. | ||
| /// </summary> | ||
| public enum DataTransferState | ||
| { | ||
| /// <summary> | ||
| /// Default value. | ||
| /// </summary> | ||
| None = 0, | ||
|
|
||
| /// <summary> | ||
| /// The transfer has been queued up but has not yet started. | ||
| /// </summary> | ||
| Queued = 1, | ||
|
|
||
| /// <summary> | ||
| /// The transfer has started, but has not yet completed. | ||
| /// </summary> | ||
| InProgress = 2, | ||
|
|
||
| /// <summary> | ||
| /// The transfer is in progress and is in the process of being paused. | ||
| /// | ||
| /// Transfer can be stopped if <see cref="TransferManager.PauseTransferIfRunningAsync(string, System.Threading.CancellationToken)"/> | ||
| /// or <see cref="DataTransfer.PauseAsync(CancellationToken)"/> is called. | ||
| /// </summary> | ||
| Pausing = 3, | ||
|
|
||
| /// <summary> | ||
| /// The transfer is in progress and is in the process of being stopped. | ||
| /// | ||
| /// Transfer can be stopped if <see cref="DataTransferErrorMode.StopOnAnyFailure"/> is | ||
| /// enabled in the <see cref="TransferManagerOptions.ErrorHandling"/>. | ||
| /// </summary> | ||
| Stopping = 4, | ||
|
|
||
| /// <summary> | ||
| /// The transfer has been paused. When transfer is paused | ||
| /// (e.g. see <see cref="TransferManager.PauseTransferIfRunningAsync(string, System.Threading.CancellationToken)"/>) | ||
| /// during the transfer, this will be the value. | ||
| /// </summary> | ||
| Paused = 5, | ||
|
|
||
| /// <summary> | ||
| /// The transfer has come to a completed state. If the transfer has started and | ||
| /// has fully stopped will also come to this state. | ||
| /// </summary> | ||
| Completed = 6 | ||
| } | ||
| } | ||
118 changes: 91 additions & 27 deletions
118
sdk/storage/Azure.Storage.DataMovement/src/DataTransferStatus.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,66 +1,130 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System; | ||
| using System.Runtime.CompilerServices; | ||
| using System.Threading; | ||
|
|
||
| namespace Azure.Storage.DataMovement | ||
| { | ||
| /// <summary> | ||
| /// Defines the status of the Transfer Job. | ||
| /// </summary> | ||
| public enum DataTransferStatus | ||
| public class DataTransferStatus : IEquatable<DataTransferStatus> | ||
| { | ||
| private int _hasFailedItemValue; | ||
| private int _hasSkippedItemValue; | ||
| private int _stateValue; | ||
|
|
||
| /// <summary> | ||
| /// Default value. | ||
| /// Equivalent to <see cref="DataTransferStatus.None"/>. | ||
| /// Defines the state of the transfer. | ||
| /// </summary> | ||
| None = 0, | ||
| public DataTransferState State => (DataTransferState)_stateValue; | ||
|
|
||
| /// <summary> | ||
| /// The Job has been queued up but has not yet begun any transfers. | ||
| /// Equivalent to <see cref="DataTransferStatus.Queued"/>. | ||
| /// Represents if the transfer has completed successfully without any failure or skipped items. | ||
| /// </summary> | ||
| Queued = 1, | ||
| public bool HasCompletedSuccessfully => | ||
| (State == DataTransferState.Completed) && | ||
| !HasFailedItems && | ||
| !HasSkippedItems; | ||
|
|
||
| /// <summary> | ||
| /// The Job has started, but has not yet completed. | ||
| /// Equivalent to <see cref="DataTransferStatus.InProgress"/>. | ||
| /// Represents if transfer has any failure items. | ||
| /// | ||
| /// If set to `true`, the transfer has at least one failure item. | ||
| /// If set to `false`, the transfer currently has no failures. | ||
| /// </summary> | ||
| InProgress = 2, | ||
| public bool HasFailedItems => _hasFailedItemValue != 0; | ||
|
|
||
| /// <summary> | ||
| /// The Job has been paused. When transfer is paused (e.g. see <see cref="TransferManager.PauseTransferIfRunningAsync(string, System.Threading.CancellationToken)"/>) during the transfer, | ||
| /// this will be the value. | ||
| /// Represents if transfer has any skipped items. | ||
| /// | ||
| /// This status is a resumable state, only | ||
| /// transfers that failed will be retried when <see cref="TransferManager.StartTransferAsync(StorageResource, StorageResource, DataTransferOptions, CancellationToken)"/> | ||
| /// with the respective transfer ID to resume. | ||
| /// If set to `true`, the transfer has at least one item it has skipped. | ||
| /// If set to `false`, the transfer currently has no items that has been skipped. | ||
| /// | ||
| /// It's possible to never have any items skipped if | ||
| /// <see cref="StorageResourceCreationPreference.SkipIfExists"/> is not enabled in the <see cref="DataTransferOptions.CreationPreference"/>. | ||
| /// </summary> | ||
| Paused = 3, | ||
| public bool HasSkippedItems => _hasSkippedItemValue != 0; | ||
|
|
||
| /// <summary> | ||
| /// The Job has completed successfully with no failures or skips. | ||
| /// Constructor to set the initial state to <see cref="DataTransferState.Queued"/> with no failures or skipped items. | ||
| /// </summary> | ||
| Completed = 4, | ||
| protected internal DataTransferStatus() | ||
| { | ||
| _stateValue = (int)DataTransferState.Queued; | ||
| _hasFailedItemValue = 0; // Initialized to false | ||
| _hasSkippedItemValue = 0; // Initialized to false | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// The Job has been completed with at least one skipped transfer. | ||
| /// Constructor to have a custom state, failure state, and skipped state. | ||
| /// </summary> | ||
| CompletedWithSkippedTransfers = 5, | ||
| protected internal DataTransferStatus(DataTransferState state, bool hasFailureItems, bool hasSkippedItems) | ||
| { | ||
| _stateValue = (int)state; | ||
| _hasFailedItemValue = hasFailureItems ? 1 : 0; | ||
| _hasSkippedItemValue = hasSkippedItems ? 1 : 0; | ||
| } | ||
|
|
||
| internal bool IsCompletedWithFailedItems => State.Equals(DataTransferState.Completed) && HasFailedItems; | ||
| internal bool IsCompletedWithSkippedItems => State.Equals(DataTransferState.Completed) && HasSkippedItems; | ||
|
|
||
| /// <summary> | ||
| /// The Job has been completed with at least one failed transfer. | ||
| /// Accordingly update the <see cref="HasFailedItems"/> to true. If already set to true, nothing will happen. | ||
| /// | ||
| /// This should only be triggered when a failed item has been seen. | ||
| /// </summary> | ||
| /// <returns>True if <see cref="HasFailedItems"/> was updated. False otherwise.</returns> | ||
| internal bool TrySetFailedItem() | ||
| { | ||
| return Interlocked.Exchange(ref _hasFailedItemValue, 1) != 1; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Accordingly update the <see cref="HasSkippedItems"/> to true. If already set to true, nothing will happen. | ||
| /// | ||
| /// This should only be triggered when a skipped item has been seen. | ||
| /// </summary> | ||
| /// /// <returns>True if <see cref="HasSkippedItems"/> was updated. False otherwise.</returns> | ||
| internal bool TrySetSkippedItem() | ||
| { | ||
| return Interlocked.Exchange(ref _hasSkippedItemValue, 1) != 1; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Accordingly update the <see cref="State"/>. If the current State is the same as the parameter, | ||
| /// then nothing will happen. | ||
| /// | ||
| /// This should only be triggered when the state updates. | ||
| /// </summary> | ||
| CompletedWithFailedTransfers = 6, | ||
| /// <returns>True if <see cref="State"/> was updated. False otherwise.</returns> | ||
| internal bool TrySetTransferStateChange(DataTransferState state) | ||
| { | ||
| return Interlocked.Exchange(ref _stateValue, (int)state) != (int)state; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// A pause was called on the transfer job and is in progress. | ||
| /// Indicates whether the current object is equal to another object of the same type. | ||
| /// </summary> | ||
| PauseInProgress = 7, | ||
| /// <param name="other">An object to compare with this object.</param> | ||
| /// <returns>Returns true if the current object is equal to the other parameter; otherwise, false.</returns> | ||
| public bool Equals(DataTransferStatus other) | ||
|
amnguye marked this conversation as resolved.
|
||
| => State.Equals(other.State) && | ||
| HasFailedItems.Equals(other.HasFailedItems) && | ||
| HasSkippedItems.Equals(other.HasSkippedItems); | ||
|
|
||
| /// <summary> | ||
| /// A pause was called on the transfer job and is in progress. | ||
| /// Performs a Deep Copy of the <see cref="DataTransferStatus"/>. | ||
| /// </summary> | ||
| CancellationInProgress = 8, | ||
| }; | ||
| /// <returns>A deep copy of the respective <see cref="DataTransferStatus"/>.</returns> | ||
| internal DataTransferStatus DeepCopy() | ||
| => new() | ||
| { | ||
| _stateValue = _stateValue, | ||
| _hasFailedItemValue = _hasFailedItemValue, | ||
| _hasSkippedItemValue = _hasSkippedItemValue, | ||
| }; | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.