Repository navigation
azure: fix race condition in PutContent() - #2088
Conversation
See #2077 for background. The PR #1438 which was not reviewed by azure folks basically introduced a race condition around uploads to the same blob by multiple clients concurrently as it used the "writer" type for PutContent(), introduced in #1438. This does chunked upload of blobs using "AppendBlob" type, which was not atomic. Usage of "writer" type and thus AppendBlobs on metadata files is currently not concurrency-safe and generally, they are not the right type of blob for the job. This patch fixes PutContent() to use the atomic upload operation that works for uploads smaller than 64 MB and creates blobs with "BlockBlob" type. To be backwards compatible, we query the type of the blob first and if it is not a "BlockBlob" we delete the blob first before doing an atomic PUT. This creates a small inconsistency/race window "only once". Once the blob is made "BlockBlob", it is overwritten with a single PUT atomicallly next time. Therefore, going forward, PutContent() will be producing BlockBlobs and it will silently migrate the AppendBlobs introduced in #1438 to BlockBlobs with this patch. Tested with existing code side by side, both registries with and without this patch work fine without breaking each other. So this should be good from a backwards/forward compatiblity perspective, with a cost of doing an extra HEAD checking the blob type. Fixes #2077. Signed-off-by: Ahmet Alp Balkan <[email protected]>
Current coverage is 51.07% (diff: 0.00%)@@ master #2088 diff @@
==========================================
Files 128 128
Lines 11399 11401 +2
Methods 0 0
Messages 0 0
Branches 0 0
==========================================
- Hits 6821 5823 -998
- Misses 3713 4827 +1114
+ Partials 865 751 -114
|
|
@ahmetalpbalkan can you link to the Azure documentation for this, I want to better understand the |
|
@dmcgowan https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/understanding-block-blobs--append-blobs--and-page-blobs Problem here was:
|
| // handle the case when the request was a HEAD and service error could not | ||
| // be parsed, such as "storage: service returned without a response body | ||
| // (404 The specified blob does not exist.)" | ||
| if strings.Contains(fmt.Sprintf("%v", err), "404 The specified blob does not exist") { |
There was a problem hiding this comment.
NOTE: we can remove this new conditional once we bring the following patch here by vendoring the latest azure-sdk-for-go Azure/azure-sdk-for-go#480
|
@dmcgowan what do you think? we've patched this locally and serves us well so far. |
|
LGTM |
|
@ahmetalpbalkan possible to get one other Azure folk to LGTM this? |
|
We actually reviewed this internally and already started deploying. 😄 cc: @yuwaMSFT can you please LGTM? |
|
LGTM |
See #2077 for the background.
The PR #1438 which was not reviewed by azure folks basically introduced
a race condition around uploads to the same blob by multiple clients
concurrently as it used the "writer" class introduced in #1438 which does
chunked upload of blobs using "AppendBlob" type, which was not atomic.
This patch fixes PutContent() to use the atomic upload operation that works
for uploads smaller than 64 MB and works on "BlockBlob" types only. To be
backwards compatible, we query the type of the blob first and if it is not
a "BlockBlob" we delete the blob first before doing an atomic PUT. This
creates a small inconsistency/race window "only once". Once the blob is made
"BlockBlob", it is overwritten with a single PUT atomically next time.
Tested with existing code side by side, both registries with and without this
patch work fine without breaking each other. So this should be good from a
backwards/forward compatibility perspective, with a cost of doing an extra
HEAD checking the blob type.
Fixes #2077.
Signed-off-by: Ahmet Alp Balkan [email protected]
cc: @yuwaMSFT