Skip to content
This repository was archived by the owner on Mar 31, 2026. It is now read-only.

Commit 78088db

Browse files
committed
minor changes
1 parent 359a23c commit 78088db

8 files changed

Lines changed: 481 additions & 328 deletions

File tree

google/cloud/storage/_experimental/asyncio/_utils.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,8 @@ def raise_if_no_fast_crc32c():
3333
"C extension is required for faster data integrity checks."
3434
"For more information, see https://github.com/googleapis/python-crc32c."
3535
)
36+
37+
def update_write_handle_if_exists(obj, response):
38+
"""Update the write_handle attribute of an object if it exists in the response."""
39+
if hasattr(response, "write_handle") and response.write_handle is not None:
40+
obj.write_handle = response.write_handle

google/cloud/storage/_experimental/asyncio/async_abstract_object_stream.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class _AsyncAbstractObjectStream(abc.ABC):
3232
:param generation_number: (Optional) If present, selects a specific revision of
3333
this object.
3434
35-
:type handle: bytes
35+
:type handle: Any
3636
:param handle: (Optional) The handle for the object, could be read_handle or
3737
write_handle, based on how the stream is used.
3838
"""
@@ -42,13 +42,13 @@ def __init__(
4242
bucket_name: str,
4343
object_name: str,
4444
generation_number: Optional[int] = None,
45-
handle: Optional[bytes] = None,
45+
handle: Optional[Any] = None,
4646
) -> None:
4747
super().__init__()
4848
self.bucket_name: str = bucket_name
4949
self.object_name: str = object_name
5050
self.generation_number: Optional[int] = generation_number
51-
self.handle: Optional[bytes] = handle
51+
self.handle: Optional[Any] = handle
5252

5353
@abc.abstractmethod
5454
async def open(self) -> None:

google/cloud/storage/_experimental/asyncio/async_appendable_object_writer.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
from google.cloud._storage_v2.types.storage import BidiWriteObjectRequest
3737

3838

39-
from ._utils import raise_if_no_fast_crc32c
39+
from . import _utils
4040
from google.cloud import _storage_v2
4141
from google.cloud.storage._experimental.asyncio.async_grpc_client import (
4242
AsyncGrpcClient,
@@ -117,8 +117,8 @@ def __init__(
117117
client: AsyncGrpcClient.grpc_client,
118118
bucket_name: str,
119119
object_name: str,
120-
generation=None,
121-
write_handle=None,
120+
generation: Optional[int] = None,
121+
write_handle: Optional[_storage_v2.BidiWriteHandle] = None,
122122
writer_options: Optional[dict] = None,
123123
):
124124
"""
@@ -164,7 +164,7 @@ def __init__(
164164
:type object_name: str
165165
:param object_name: The name of the GCS Appendable Object to be written.
166166
167-
:type generation: int
167+
:type generation: Optional[int]
168168
:param generation: (Optional) If present, creates writer for that
169169
specific revision of that object. Use this to append data to an
170170
existing Appendable Object.
@@ -174,10 +174,10 @@ def __init__(
174174
overwriting existing objects).
175175
176176
Warning: If `None`, a new object is created. If an object with the
177-
same name already exists, it will be overwritten the moment
177+
same name already exists, it will be overwritten the moment
178178
`writer.open()` is called.
179179
180-
:type write_handle: bytes
180+
:type write_handle: _storage_v2.BidiWriteHandle
181181
:param write_handle: (Optional) An handle for writing the object.
182182
If provided, opening the bidi-gRPC connection will be faster.
183183
@@ -189,7 +189,7 @@ def __init__(
189189
servers. Default is `_DEFAULT_FLUSH_INTERVAL_BYTES`.
190190
Must be a multiple of `_MAX_CHUNK_SIZE_BYTES`.
191191
"""
192-
raise_if_no_fast_crc32c()
192+
_utils.raise_if_no_fast_crc32c()
193193
self.client = client
194194
self.bucket_name = bucket_name
195195
self.object_name = object_name

google/cloud/storage/_experimental/asyncio/async_multi_range_downloader.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ async def create_mrd(
129129
bucket_name: str,
130130
object_name: str,
131131
generation_number: Optional[int] = None,
132-
read_handle: Optional[bytes] = None,
132+
read_handle: Optional[_storage_v2.BidiReadHandle] = None,
133133
retry_policy: Optional[AsyncRetry] = None,
134134
metadata: Optional[List[Tuple[str, str]]] = None,
135135
) -> AsyncMultiRangeDownloader:
@@ -149,7 +149,7 @@ async def create_mrd(
149149
:param generation_number: (Optional) If present, selects a specific
150150
revision of this object.
151151
152-
:type read_handle: bytes
152+
:type read_handle: _storage_v2.BidiReadHandle
153153
:param read_handle: (Optional) An existing handle for reading the object.
154154
If provided, opening the bidi-gRPC connection will be faster.
155155
@@ -172,7 +172,7 @@ def __init__(
172172
bucket_name: str,
173173
object_name: str,
174174
generation_number: Optional[int] = None,
175-
read_handle: Optional[bytes] = None,
175+
read_handle: Optional[_storage_v2.BidiReadHandle] = None,
176176
) -> None:
177177
"""Constructor for AsyncMultiRangeDownloader, clients are not adviced to
178178
use it directly. Instead it's adviced to use the classmethod `create_mrd`.
@@ -190,7 +190,7 @@ def __init__(
190190
:param generation_number: (Optional) If present, selects a specific revision of
191191
this object.
192192
193-
:type read_handle: bytes
193+
:type read_handle: _storage_v2.BidiReadHandle
194194
:param read_handle: (Optional) An existing read handle.
195195
"""
196196

@@ -200,7 +200,7 @@ def __init__(
200200
self.bucket_name = bucket_name
201201
self.object_name = object_name
202202
self.generation_number = generation_number
203-
self.read_handle = read_handle
203+
self.read_handle: Optional[_storage_v2.BidiReadHandle] = read_handle
204204
self.read_obj_str: Optional[_AsyncReadObjectStream] = None
205205
self._is_stream_open: bool = False
206206
self._routing_token: Optional[str] = None

google/cloud/storage/_experimental/asyncio/async_read_object_stream.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class _AsyncReadObjectStream(_AsyncAbstractObjectStream):
5151
:param generation_number: (Optional) If present, selects a specific revision of
5252
this object.
5353
54-
:type read_handle: bytes
54+
:type read_handle: _storage_v2.BidiReadHandle
5555
:param read_handle: (Optional) An existing handle for reading the object.
5656
If provided, opening the bidi-gRPC connection will be faster.
5757
"""
@@ -62,7 +62,7 @@ def __init__(
6262
bucket_name: str,
6363
object_name: str,
6464
generation_number: Optional[int] = None,
65-
read_handle: Optional[bytes] = None,
65+
read_handle: Optional[_storage_v2.BidiReadHandle] = None,
6666
) -> None:
6767
if client is None:
6868
raise ValueError("client must be provided")
@@ -77,7 +77,7 @@ def __init__(
7777
generation_number=generation_number,
7878
)
7979
self.client: AsyncGrpcClient.grpc_client = client
80-
self.read_handle: Optional[bytes] = read_handle
80+
self.read_handle: Optional[_storage_v2.BidiReadHandle] = read_handle
8181

8282
self._full_bucket_name = f"projects/_/buckets/{self.bucket_name}"
8383

tests/perf/microbenchmarks/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,13 @@ pytest --benchmark-json=output.json -vv -s tests/perf/microbenchmarks/reads/test
1515

1616
To run a single test, append `::` followed by the test name to the file path.
1717

18-
Example:
18+
Examples:
1919
```bash
2020
pytest --benchmark-json=output.json -vv -s tests/perf/microbenchmarks/reads/test_reads.py::test_downloads_single_proc_single_coro
2121
```
22+
```bash
23+
pytest --benchmark-json=output.json -vv -s tests/perf/microbenchmarks/writes/test_writes.py::test_uploads_single_proc_single_coro
24+
```
2225

2326
## Configuration
2427

tests/perf/microbenchmarks/conftest.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
AsyncAppendableObjectWriter,
2727
)
2828
from google.cloud.storage._experimental.asyncio.async_grpc_client import AsyncGrpcClient
29+
from tests.perf.microbenchmarks.writes.parameters import WriteParameters
2930

3031
_OBJECT_NAME_PREFIX = "micro-benchmark"
3132

@@ -72,7 +73,7 @@ def publish_resource_metrics(benchmark: Any, monitor: ResourceMonitor) -> None:
7273

7374
async def upload_appendable_object(bucket_name, object_name, object_size, chunk_size):
7475
# flush interval set to little over 1GiB to minimize number of flushes.
75-
# this method is to write "appendable" objects which will be used for
76+
# this method is to write "appendable" objects which will be used for
7677
# benchmarking reads, hence not concerned performance of writes here.
7778
writer = AsyncAppendableObjectWriter(
7879
AsyncGrpcClient().grpc_client, bucket_name, object_name, writer_options={"FLUSH_INTERVAL_BYTES": 1026 * 1024 ** 2}
@@ -135,10 +136,16 @@ def _create_files(num_files, bucket_name, bucket_type, object_size, chunk_size=1
135136
@pytest.fixture
136137
def workload_params(request):
137138
params = request.param
138-
files_names = _create_files(
139-
params.num_files,
140-
params.bucket_name,
141-
params.bucket_type,
142-
params.file_size_bytes,
143-
)
144-
return params, files_names
139+
if isinstance(params, WriteParameters):
140+
files_names = [
141+
f"{_OBJECT_NAME_PREFIX}-{uuid.uuid4().hex[:5]}"
142+
for _ in range(params.num_files)
143+
]
144+
else:
145+
files_names = _create_files(
146+
params.num_files,
147+
params.bucket_name,
148+
params.bucket_type,
149+
params.file_size_bytes,
150+
)
151+
return params, files_names

0 commit comments

Comments
 (0)