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

Commit 53abafe

Browse files
committed
add more logs
1 parent 5e5916a commit 53abafe

3 files changed

Lines changed: 23 additions & 22 deletions

File tree

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ 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
180180
:type write_handle: bytes
@@ -432,8 +432,8 @@ async def generator():
432432
print(f"AsyncAppendableObjectWriter: append - sending state_lookup request: {chunk_req}")
433433
await self.write_obj_stream.send(chunk_req)
434434
resp = await self.write_obj_stream.recv()
435-
print(f"AsyncAppendableObjectWriter: append - received state_lookup response: {resp}")
436-
435+
print(f"AsyncAppendableObjectWriter: append - received state_lookup response")
436+
437437
# Update state from open response
438438
if resp:
439439
if resp.persisted_size is not None:
@@ -444,15 +444,15 @@ async def generator():
444444
self.write_handle = resp.write_handle
445445
write_state.write_handle = resp.write_handle
446446
continue
447-
447+
448448
# This is a data request - send it
449-
print(f"AsyncAppendableObjectWriter: append - sending data request: {chunk_req}")
449+
print(f"AsyncAppendableObjectWriter: append - sending data request:")
450450
await self.write_obj_stream.send(chunk_req)
451451

452452
# Get final response from the last request (which has state_lookup=True)
453453
resp = await self.write_obj_stream.recv()
454-
print(f"AsyncAppendableObjectWriter: append - received final response: {resp}")
455-
454+
print(f"AsyncAppendableObjectWriter: append - received final response")
455+
456456
if resp:
457457
if resp.persisted_size is not None:
458458
self.persisted_size = resp.persisted_size

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ async def open(self, metadata: Optional[List[Tuple[str, str]]] = None) -> None:
169169
await self.socket_like_rpc.open() # this is actually 1 send
170170
print(f"in _AsyncWriteObjectStream open: rpc opened")
171171
response = await self.socket_like_rpc.recv()
172-
print(f"in _AsyncWriteObjectStream open: received response: {response}")
172+
print(f"in _AsyncWriteObjectStream open: received response:")
173173
self._is_stream_open = True
174174

175175
if response.persisted_size:
@@ -212,7 +212,7 @@ async def send(
212212
The request message to send. This is typically used to specify
213213
the read offset and limit.
214214
"""
215-
print(f"in _AsyncWriteObjectStream send: sending request: {bidi_write_object_request}")
215+
print(f"in _AsyncWriteObjectStream send: sending request")
216216
if not self._is_stream_open:
217217
raise ValueError("Stream is not open")
218218
await self.socket_like_rpc.send(bidi_write_object_request)
@@ -231,7 +231,7 @@ async def recv(self) -> _storage_v2.BidiWriteObjectResponse:
231231
raise ValueError("Stream is not open")
232232
print(f"in _AsyncWriteObjectStream recv: receiving response")
233233
response = await self.socket_like_rpc.recv()
234-
print(f"in _AsyncWriteObjectStream recv: received response: {response}")
234+
print(f"in _AsyncWriteObjectStream recv: received response")
235235
# Update write_handle if present in response
236236
if response:
237237
if response.write_handle:

google/cloud/storage/_experimental/asyncio/retry/writes_resumption_strategy.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def __init__(
5454
)
5555
self.chunk_size = chunk_size
5656
self.user_buffer = user_buffer
57+
self.total_size = self.user_buffer.getbuffer().nbytes
5758
self.persisted_size: int = 0
5859
self.bytes_sent: int = 0
5960
self.bytes_since_last_flush: int = 0
@@ -109,11 +110,10 @@ def generate_requests(self, state: Dict[str, Any]):
109110
if not chunk:
110111
break
111112

112-
# Peek to see if this is the last chunk. This is safe because both
113-
# io.BytesIO and BufferedReader (used in file uploads) support peek().
114-
is_last_chunk = not getattr(write_state.user_buffer, "peek", lambda n: b"")(
115-
1
116-
)
113+
chunk_len = len(chunk)
114+
is_last_chunk = (
115+
write_state.bytes_sent + chunk_len
116+
) == write_state.total_size
117117

118118
checksummed_data = storage_type.ChecksummedData(content=chunk)
119119
checksum = google_crc32c.Checksum(chunk)
@@ -123,24 +123,25 @@ def generate_requests(self, state: Dict[str, Any]):
123123
write_offset=write_state.bytes_sent,
124124
checksummed_data=checksummed_data,
125125
)
126-
chunk_len = len(chunk)
126+
127127
write_state.bytes_sent += chunk_len
128128
write_state.bytes_since_last_flush += chunk_len
129129
print(f"Yielding request with offset: {request.write_offset}")
130130

131-
if (
131+
is_flush_point = (
132132
write_state.flush_interval
133133
and write_state.bytes_since_last_flush >= write_state.flush_interval
134-
):
135-
request.flush = True
136-
print("Marking request with flush=True")
137-
# reset counter after marking flush
138-
write_state.bytes_since_last_flush = 0
134+
)
139135

140136
if is_last_chunk:
141137
request.flush = True
142138
request.state_lookup = True
139+
write_state.bytes_since_last_flush = 0
143140
print("Marking request with flush=True and state_lookup=True")
141+
elif is_flush_point:
142+
request.flush = True
143+
write_state.bytes_since_last_flush = 0
144+
print("Marking request with flush=True")
144145

145146
yield request
146147

0 commit comments

Comments
 (0)