Azure / azure-storage-cpp

Microsoft Azure Storage Client Library for C++
http://azure.github.io/azure-storage-cpp
Apache License 2.0
132 stars 147 forks source link

Question: Another Edge case. upload_block and upload_block_list. How to unwind all blocks for a new blob without an empty blob being created until a real block is appended? #335

Closed yxiang92128 closed 4 years ago

yxiang92128 commented 4 years ago

@JinmingHu-MSFT

Hi, I have another very subtle edge case for you wrt to upload_block and upload_block_list. For an non-existing blob,

  1. I called upload_block several times to upload uncommitted blocks to the named blob for which it does not exist yet.
  2. Then the user changes mind and decides they need to unwind all uncommitted blocks. So I had to then call upload_block_list with an empty block list in order to achieve that. But the downside is that an empty blob is therefore created.
  3. I can't figure out a way NOT to call upload_block_list with an empty list to perform such cancel operation unless I build a client side list to track the changes and unwound blocks. Or I need to call delete_blob if the blob wasn't there before.

The use case is that the user can unwind and then insert new blocks until they decide to upload the finalized list later on. But in between, the new blob should not exist otherwise the application would fail with that empty blob.

Any idea how to work around that, ie, mark the blocks as "deleted" from the "uncommitted" state?

Thanks,

Yang

Jinming-Hu commented 4 years ago

@yxiang92128 How about just ignore those uncommitted blocks if the user changes his mind? Those uncommitted will be garbage collected in the future. See this section for more details about blocks.

Jinming-Hu commented 4 years ago

@yxiang92128 The uncommitted blob won't appear as 0-sized blob when listing blobs, unless you specify uncommittedblobbs.

As a workaround, I think you can call delete_blob to delete all uncommitted blocks. As long as there are any uncommitted blocks for this blob, no matter the blob itself exists or not, this function won't throw exception.

yxiang92128 commented 4 years ago

got it and delete_blob did the trick.