Skip to content

fix: #462 parallel uploads to the same blob storage #485

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
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions adlfs/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
from collections import defaultdict
from datetime import datetime, timedelta
from glob import has_magic
from typing import Optional, Tuple
from typing import List, Optional, Tuple
from uuid import uuid4

from azure.core.exceptions import (
HttpResponseError,
Expand Down Expand Up @@ -2138,8 +2139,7 @@ async def _async_upload_chunk(self, final: bool = False, **kwargs):
"""
data = self.buffer.getvalue()
length = len(data)
block_id = len(self._block_list)
block_id = f"{block_id:07d}"
block_id = self._get_block_id(self._block_list)
if self.mode == "wb":
try:
for chunk in self._get_chunks(data):
Expand All @@ -2152,8 +2152,7 @@ async def _async_upload_chunk(self, final: bool = False, **kwargs):
length=len(chunk),
)
self._block_list.append(block_id)
block_id = len(self._block_list)
block_id = f"{block_id:07d}"
block_id = self._get_block_id(self._block_list)

if final:
block_list = [BlobBlock(_id) for _id in self._block_list]
Expand All @@ -2168,7 +2167,7 @@ async def _async_upload_chunk(self, final: bool = False, **kwargs):
# which is throws an InvalidHeader error from Azure, so instead
# of staging a block, we directly upload the empty blob
# This isn't actually tested, since Azureite behaves differently.
if block_id == "0000000" and length == 0 and final:
if block_id == self._get_block_id([]) and length == 0 and final:
async with self.container_client.get_blob_client(
blob=self.blob
) as bc:
Expand Down Expand Up @@ -2197,6 +2196,10 @@ async def _async_upload_chunk(self, final: bool = False, **kwargs):
"File operation modes other than wb or ab are not yet supported for upload_chunk"
)

@staticmethod
def _get_block_id(block_list: List[str]) -> str:
return uuid4().hex if block_list else "0" * 32

_upload_chunk = sync_wrapper(_async_upload_chunk)

def __del__(self):
Expand Down
Loading