-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[Storage] [STG 104] Unique Put Block IDs #47821
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
base: feature/storage/stg103-104
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,10 +9,11 @@ | |
| from itertools import islice | ||
| from math import ceil | ||
| from threading import Lock | ||
| from uuid import uuid4 | ||
|
|
||
| from azure.core.tracing.common import with_current_context | ||
|
|
||
| from . import encode_base64, url_quote | ||
| from . import encode_base64 | ||
| from .request_handlers import get_length | ||
| from .response_handlers import return_response_headers | ||
|
|
||
|
|
@@ -116,7 +117,7 @@ def upload_substream_blocks( | |
| else: | ||
| range_ids = [uploader.process_substream_block(b) for b in uploader.get_substream_blocks()] | ||
| if any(range_ids): | ||
| return sorted(range_ids) | ||
| return [block_id for _, block_id in sorted(range_ids, key=lambda r: r[0])] | ||
| return [] | ||
|
|
||
|
|
||
|
|
@@ -257,9 +258,10 @@ def __init__(self, *args, **kwargs): | |
| self.current_length = None | ||
|
|
||
| def _upload_chunk(self, chunk_offset, chunk_data): | ||
| # TODO: This is incorrect, but works with recording. | ||
| # Generate a unique block ID for each staged block. The chunk offset is | ||
| # still returned so the block list can be committed in the correct order. | ||
| index = f"{chunk_offset:032d}" | ||
| block_id = encode_base64(url_quote(encode_base64(index))) | ||
| block_id = encode_base64(uuid4().bytes) | ||
| self.service.stage_block( | ||
| block_id, | ||
| len(chunk_data), | ||
|
|
@@ -272,7 +274,7 @@ def _upload_chunk(self, chunk_offset, chunk_data): | |
|
|
||
| def _upload_substream_block(self, index, block_stream): | ||
| try: | ||
| block_id = f"BlockId{(index//self.chunk_size):05}" | ||
| block_id = encode_base64(uuid4().bytes) | ||
|
Member
Author
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. It would be breaking if we change to anything but 12 characters so make sure it's 12 characters.
Member
Author
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. Lowest collision rate with 12 characters when truncatting
Member
Author
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. Maybe use random
Member
Author
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. random.randomint(12) characters...we need to have a seed (os.urandom cryptographically safe random)
Member
Author
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. guids? (12 chars) |
||
| self.service.stage_block( | ||
| block_id, | ||
| len(block_stream), | ||
|
|
@@ -283,7 +285,7 @@ def _upload_substream_block(self, index, block_stream): | |
| ) | ||
| finally: | ||
| block_stream.close() | ||
| return block_id | ||
| return index, block_id | ||
|
|
||
|
|
||
| class PageBlobChunkUploader(_ChunkUploader): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,11 +9,11 @@ | |
| import pytest | ||
|
|
||
| from devtools_testutils import ( | ||
| add_body_regex_sanitizer, | ||
| add_general_regex_sanitizer, | ||
| add_header_regex_sanitizer, | ||
| add_oauth_response_sanitizer, | ||
| add_uri_regex_sanitizer, | ||
| test_proxy, | ||
| ) | ||
|
|
||
|
|
||
|
|
@@ -36,3 +36,11 @@ def add_sanitizers(test_proxy): | |
| regex=r"(?<=[?&]sktid=)[^&#]+", | ||
| value="00000000-0000-0000-0000-000000000000", | ||
| ) | ||
| add_uri_regex_sanitizer( | ||
| regex=r"(?<=[?&]blockid=)[^&#]+", | ||
| value="00000000-0000-0000-0000-000000000000", | ||
|
Member
Author
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. is this base 64 encoded? does it need to be? can just put sanitized or japan or anything you want |
||
| ) | ||
| add_body_regex_sanitizer( | ||
| regex=r"<Latest>[^<]+</Latest>", | ||
| value="<Latest>00000000-0000-0000-0000-000000000000</Latest>", | ||
| ) | ||
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.
Double check if encode_base64 always produces same amount of bytes given the same length string.
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.
Ensure the length of the left and right matches.
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.
Look into how to pad this correctly