-
Notifications
You must be signed in to change notification settings - Fork 557
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
Fix: Azure Device Behavior for Non-Existent Files #1066
Open
priyanjgupta
wants to merge
14
commits into
microsoft:main
Choose a base branch
from
priyanjgupta:usr/priyanjgupta/azureDeviceBlobNotFoundFix
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
1dd14e6
adding WLI auth support
priyanjgupta c2e2b52
Merge branch 'main' of https://github.com/priyanjaligupta/garnet into…
priyanjgupta 9d8d5e5
Updating Azure device to create a file if it doesn't exist when reading
priyanjgupta d5a47d1
Merge branch 'main' of https://github.com/priyanjgupta/garnet into pr…
priyanjgupta c3c5b73
reverting log level
priyanjgupta 7ef7782
reverting managedIdentity changes
priyanjgupta e20c65d
removing azure identity pkg reference
priyanjgupta c344f11
whitespace removed
priyanjgupta 58b3d2a
formatting whitespace bug
priyanjgupta 0cd2a6f
Merge branch 'main' into usr/priyanjgupta/azureDeviceBlobNotFoundFix
priyanjgupta 909b371
renaming function
priyanjgupta eef5fb3
Merge branch 'microsoft:main' into usr/priyanjgupta/azureDeviceBlobNo…
priyanjgupta 9b6e9c1
Merge branch 'usr/priyanjgupta/azureDeviceBlobNotFoundFix' of https:/…
priyanjgupta 560e007
Merge branch 'main' into usr/priyanjgupta/azureDeviceBlobNotFoundFix
badrishc 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 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 |
---|---|---|
|
@@ -440,29 +440,56 @@ public override unsafe void ReadAsync(int segmentId, ulong sourceAddress, IntPtr | |
// Lazily cache the blob entry for the segment being read | ||
if (!blobs.TryGetValue(segmentId, out BlobEntry blobEntry)) | ||
{ | ||
var blobClients = pageBlobDirectory.GetPageBlobClient(GetSegmentBlobName(segmentId)); | ||
var entry = new BlobEntry(blobClients, blobClients.Default.GetProperties().Value.ETag, this); | ||
blobs.TryAdd(segmentId, entry); | ||
BlobEntry entry = new(this); | ||
if (blobs.TryAdd(segmentId, entry)) | ||
{ | ||
var pageBlob = pageBlobDirectory.GetPageBlobClient(GetSegmentBlobName(segmentId)); | ||
|
||
// If segment size is -1 we use a default | ||
var size = segmentSize == -1 ? MAX_PAGEBLOB_SIZE : segmentSize; | ||
|
||
// If no blob exists for the segment, we must first create the segment asynchronouly. (Create call takes ~70 ms by measurement) | ||
// After creation is done, we can call read. | ||
_ = entry.CreateAsync(size, pageBlob); | ||
} | ||
// Otherwise, some other thread beat us to it. Okay to use their blobs. | ||
blobEntry = blobs[segmentId]; | ||
} | ||
|
||
ReadFromBlobUnsafeAsync(blobEntry.PageBlob, (long)sourceAddress, (long)destinationAddress, readLength, id) | ||
.ContinueWith((Task t) => | ||
{ | ||
if (pendingReadWriteOperations.TryRemove(id, out ReadWriteRequestInfo request)) | ||
{ | ||
if (t.IsFaulted) | ||
{ | ||
BlobManager?.StorageTracer?.TsavoriteStorageProgress($"StorageOpReturned AzureStorageDevice.ReadAsync id={id} (Failure)"); | ||
request.Callback(uint.MaxValue, request.NumBytes, request.Context); | ||
} | ||
else | ||
{ | ||
BlobManager?.StorageTracer?.TsavoriteStorageProgress($"StorageOpReturned AzureStorageDevice.ReadAsync id={id}"); | ||
request.Callback(0, request.NumBytes, request.Context); | ||
} | ||
} | ||
}, TaskContinuationOptions.ExecuteSynchronously); | ||
TryReadAsync(blobEntry, (long)sourceAddress, (long)destinationAddress, readLength, id); | ||
} | ||
|
||
void TryReadAsync(BlobEntry blobEntry, long sourceAddress, long destinationAddress, uint readLength, long id) | ||
{ | ||
// If pageBlob is null, it means the blob has not been created yet. We should wait for it to be created. | ||
if (blobEntry.PageBlob.Default == null | ||
&& blobEntry.TryQueueAction(() => ReadFromBlobAsync(blobEntry, sourceAddress, destinationAddress, readLength, id))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: indent |
||
{ | ||
return; | ||
} | ||
// Otherwise, we can proceed with the read. | ||
ReadFromBlobAsync(blobEntry, sourceAddress, destinationAddress, readLength, id); | ||
} | ||
|
||
unsafe void ReadFromBlobAsync(BlobEntry blobEntry, long sourceAddress, long destinationAddress, uint readLength, long id) | ||
{ | ||
ReadFromBlobUnsafeAsync(blobEntry, sourceAddress, destinationAddress, readLength, id) | ||
.ContinueWith((Task t) => | ||
{ | ||
if (pendingReadWriteOperations.TryRemove(id, out ReadWriteRequestInfo request)) | ||
{ | ||
if (t.IsFaulted) | ||
{ | ||
BlobManager?.StorageTracer?.TsavoriteStorageProgress($"StorageOpReturned AzureStorageDevice.ReadAsync id={id} (Failure)"); | ||
request.Callback(uint.MaxValue, request.NumBytes, request.Context); | ||
} | ||
else | ||
{ | ||
BlobManager?.StorageTracer?.TsavoriteStorageProgress($"StorageOpReturned AzureStorageDevice.ReadAsync id={id} for blob={blobEntry.ETag}"); | ||
request.Callback(0, request.NumBytes, request.Context); | ||
} | ||
} | ||
}, TaskContinuationOptions.ExecuteSynchronously); | ||
} | ||
|
||
/// <summary> | ||
|
@@ -557,12 +584,12 @@ await BlobManager.PerformWithRetriesAsync( | |
} | ||
} | ||
|
||
unsafe Task ReadFromBlobUnsafeAsync(BlobUtilsV12.PageBlobClients blob, long sourceAddress, long destinationAddress, uint readLength, long id) | ||
unsafe Task ReadFromBlobUnsafeAsync(BlobEntry blob, long sourceAddress, long destinationAddress, uint readLength, long id) | ||
{ | ||
return ReadFromBlobAsync(new UnmanagedMemoryStream((byte*)destinationAddress, readLength, readLength, FileAccess.Write), blob, sourceAddress, readLength, id); | ||
} | ||
|
||
async Task ReadFromBlobAsync(UnmanagedMemoryStream stream, BlobUtilsV12.PageBlobClients blob, long sourceAddress, uint readLength, long id) | ||
async Task ReadFromBlobAsync(UnmanagedMemoryStream stream, BlobEntry blob, long sourceAddress, uint readLength, long id) | ||
{ | ||
using (stream) | ||
{ | ||
|
@@ -577,7 +604,7 @@ await BlobManager.PerformWithRetriesAsync( | |
"PageBlobClient.DownloadStreamingAsync", | ||
"ReadFromDevice", | ||
$"id={id} readLength={length} sourceAddress={sourceAddress + offset}", | ||
blob.Default.Name, | ||
blob.PageBlob.Default.Name, | ||
1000 + (int)length / 1000, | ||
true, | ||
async (numAttempts) => | ||
|
@@ -589,7 +616,7 @@ await BlobManager.PerformWithRetriesAsync( | |
|
||
if (length > 0) | ||
{ | ||
var client = (numAttempts > 1 || length == MAX_DOWNLOAD_SIZE) ? blob.Default : blob.Aggressive; | ||
var client = (numAttempts > 1 || length == MAX_DOWNLOAD_SIZE) ? blob.PageBlob.Default : blob.PageBlob.Aggressive; | ||
|
||
var response = await client.DownloadStreamingAsync( | ||
range: new Azure.HttpRange(sourceAddress + offset, length), | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
naming: This is not an async method (same goes for
ReadFromBlobAsync
)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The convention in AzureStorageDevice currently is that methods that perform work asynchronously end in Async, even if they are not strictly within the async-await paradigm. So I would leave it as is for this PR.