Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(storage): full object checksum: implement rolling checksum and verification in reads resumption strategy#17262
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
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
42ab953
feat(storage): parse finalize_time and server crc32c in async object …
chandra-siri d972c2c
feat(storage): implement rolling checksum and verification in reads r…
chandra-siri 7110744
style(storage): apply user feedback on finalize_time and fix unused i…
chandra-siri a437b66
merge: integrate updated finalize_time checks and lint fixes from PR 1
chandra-siri 9704da7
merge: integrate latest main to resolve pytest-asyncio event loop fai…
chandra-siri 31ef2e3
style(storage): run ruff format to resolve CI lint failures
chandra-siri 25c39e2
merge: integrate PR 1 updates including ruff formatting and pytest-as…
chandra-siri c371f59
test(storage): add conftest autouse event loop fixture to resolve pyt…
chandra-siri 21144f9
merge: integrate PR 1 updates including conftest.py event loop fixture
chandra-siri c470641
fix(storage): use second attribute instead of seconds for DatetimeWit…
chandra-siri 3820424
merge: integrate PR 1 second attribute fixes
chandra-siri 2f49dcb
perf(storage): bypass rolling checksum updates when checksum validati…
chandra-siri 8fdb571
chore: trigger workflows
chandra-siri 465d210
fix(storage): skip rolling checksum creation when validation is disabled
chandra-siri File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15 packages/google-cloud-storage/google/cloud/storage/asyncio/async_read_object_stream.py
This file contains hidden or 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
42 changes: 39 additions & 3 deletions
42 ...ages/google-cloud-storage/google/cloud/storage/asyncio/retry/reads_resumption_strategy.py
This file contains hidden or 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
116 changes: 114 additions & 2 deletions
116 packages/google-cloud-storage/tests/unit/asyncio/retry/test_reads_resumption_strategy.py
This file contains hidden or 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 |
|---|---|---|
| @@ -45,6 +45,48 @@ def test_initialization(self): | ||
| self.assertEqual(state.bytes_written, 0) | ||
| self.assertEqual(state.next_expected_offset, initial_offset) | ||
| self.assertFalse(state.is_complete) | ||
| self.assertFalse(state.is_full_object_read) | ||
| self.assertIsNone(state.rolling_checksum) | ||
| def test_initialization_with_full_object_read(self): | ||
| """Test that _DownloadState initializes correctly when is_full_object_read is True.""" | ||
| initial_offset = 10 | ||
| initial_length = 100 | ||
| user_buffer = io.BytesIO() | ||
| state_full = _DownloadState( | ||
| initial_offset, initial_length, user_buffer, is_full_object_read=True | ||
| ) | ||
| self.assertEqual(state_full.initial_offset, initial_offset) | ||
| self.assertEqual(state_full.initial_length, initial_length) | ||
| self.assertEqual(state_full.user_buffer, user_buffer) | ||
| self.assertEqual(state_full.bytes_written, 0) | ||
| self.assertEqual(state_full.next_expected_offset, initial_offset) | ||
| self.assertFalse(state_full.is_complete) | ||
| self.assertTrue(state_full.is_full_object_read) | ||
| self.assertIsNotNone(state_full.rolling_checksum) | ||
| def test_initialization_with_full_object_read_and_checksum_disabled(self): | ||
| """Test that _DownloadState does not initialize rolling_checksum when enable_checksum is False.""" | ||
| initial_offset = 10 | ||
| initial_length = 100 | ||
| user_buffer = io.BytesIO() | ||
| state_full = _DownloadState( | ||
| initial_offset, | ||
| initial_length, | ||
| user_buffer, | ||
| is_full_object_read=True, | ||
| enable_checksum=False, | ||
| ) | ||
| self.assertEqual(state_full.initial_offset, initial_offset) | ||
| self.assertEqual(state_full.initial_length, initial_length) | ||
| self.assertEqual(state_full.user_buffer, user_buffer) | ||
| self.assertEqual(state_full.bytes_written, 0) | ||
| self.assertEqual(state_full.next_expected_offset, initial_offset) | ||
| self.assertFalse(state_full.is_complete) | ||
| self.assertTrue(state_full.is_full_object_read) | ||
| self.assertIsNone(state_full.rolling_checksum) | ||
| class TestReadResumptionStrategy(unittest.TestCase): | ||
| @@ -53,12 +95,24 @@ def setUp(self): | ||
| self.state = {"download_states": {}, "read_handle": None, "routing_token": None} | ||
| def _add_download(self, read_id, offset=0, length=100, buffer=None): | ||
| def _add_download( | ||
| self, | ||
| read_id, | ||
| offset=0, | ||
| length=100, | ||
| buffer=None, | ||
| is_full_object_read=False, | ||
| enable_checksum=True, | ||
| ): | ||
| """Helper to inject a download state into the correct nested location.""" | ||
| if buffer is None: | ||
| buffer = io.BytesIO() | ||
| state = _DownloadState( | ||
| initial_offset=offset, initial_length=length, user_buffer=buffer | ||
| initial_offset=offset, | ||
| initial_length=length, | ||
| user_buffer=buffer, | ||
| is_full_object_read=is_full_object_read, | ||
| enable_checksum=enable_checksum, | ||
| ) | ||
| self.state["download_states"][read_id] = state | ||
| return state | ||
| @@ -358,3 +412,61 @@ async def run(): | ||
| # Token should remain unchanged | ||
| self.assertEqual(self.state["routing_token"], "existing-token") | ||
| def test_update_state_full_object_checksum_success(self): | ||
| """Test that full object checksum verification succeeds on range_end.""" | ||
| read_state = self._add_download( | ||
| _READ_ID, offset=0, length=9, is_full_object_read=True | ||
| ) | ||
| self.state["enable_checksum"] = True | ||
| self.state["full_obj_server_crc32c"] = google_crc32c.value(b"testdata1") | ||
| resp1 = self._create_response(b"test", _READ_ID, offset=0) | ||
| self.strategy.update_state_from_response(resp1, self.state) | ||
| resp2 = self._create_response(b"data1", _READ_ID, offset=4, range_end=True) | ||
| self.strategy.update_state_from_response(resp2, self.state) | ||
| self.assertTrue(read_state.is_complete) | ||
| self.assertEqual(read_state.bytes_written, 9) | ||
| def test_update_state_full_object_checksum_failure(self): | ||
| """Test that full object checksum verification raises DataCorruption on mismatch at range_end.""" | ||
| self._add_download(_READ_ID, offset=0, length=9, is_full_object_read=True) | ||
| self.state["enable_checksum"] = True | ||
| self.state["full_obj_server_crc32c"] = 111111 # Wrong server checksum! | ||
| resp1 = self._create_response(b"test", _READ_ID, offset=0) | ||
| self.strategy.update_state_from_response(resp1, self.state) | ||
| resp2 = self._create_response(b"data1", _READ_ID, offset=4, range_end=True) | ||
| with self.assertRaisesRegex(DataCorruption, "Full object checksum mismatch"): | ||
| self.strategy.update_state_from_response(resp2, self.state) | ||
| def test_update_state_checksum_mismatch_ignored_when_disabled(self): | ||
| """Test that a CRC32C mismatch is ignored when enable_checksum is False.""" | ||
| self._add_download(_READ_ID) | ||
| self.state["enable_checksum"] = False | ||
| response = self._create_response(b"data", _READ_ID, offset=0, crc=999999) | ||
| # Should NOT raise DataCorruption! | ||
| self.strategy.update_state_from_response(response, self.state) | ||
chandra-siri marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| def test_update_state_full_object_checksum_mismatch_ignored_when_disabled(self): | ||
| """Test that a full-object CRC32C mismatch is ignored when enable_checksum is False.""" | ||
| self._add_download( | ||
| _READ_ID, | ||
| offset=0, | ||
| length=9, | ||
| is_full_object_read=True, | ||
| enable_checksum=False, | ||
| ) | ||
| self.state["enable_checksum"] = False | ||
| self.state["full_obj_server_crc32c"] = 111111 # Wrong server checksum! | ||
| resp1 = self._create_response(b"test", _READ_ID, offset=0) | ||
| self.strategy.update_state_from_response(resp1, self.state) | ||
| resp2 = self._create_response(b"data1", _READ_ID, offset=4, range_end=True) | ||
| # Should NOT raise DataCorruption! | ||
| self.strategy.update_state_from_response(resp2, self.state) | ||
39 changes: 38 additions & 1 deletion
39 packages/google-cloud-storage/tests/unit/asyncio/test_async_read_object_stream.py
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| # -*- coding: utf-8 -*- | ||
| # Copyright 2026 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| import asyncio | ||
| import pytest | ||
| @pytest.fixture(autouse=True) | ||
| def set_event_loop(): | ||
| try: | ||
| asyncio.get_running_loop() | ||
| yield | ||
| except RuntimeError: | ||
| loop = asyncio.new_event_loop() | ||
| asyncio.set_event_loop(loop) | ||
| try: | ||
| yield | ||
| finally: | ||
| loop.close() | ||
| asyncio.set_event_loop(None) |
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
Uh oh!
There was an error while loading. Please reload this page.