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

Commit eaac82c

Browse files
committed
add more logs
1 parent 1945a9b commit eaac82c

3 files changed

Lines changed: 22 additions & 21 deletions

File tree

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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
@@ -173,7 +173,7 @@ async def open(self, metadata: Optional[List[Tuple[str, str]]] = None) -> None:
173173
await self.socket_like_rpc.open() # this is actually 1 send
174174
print(f"in _AsyncWriteObjectStream open: rpc opened")
175175
response = await self.socket_like_rpc.recv()
176-
print(f"in _AsyncWriteObjectStream open: received response: {response}")
176+
print(f"in _AsyncWriteObjectStream open: received response:")
177177
self._is_stream_open = True
178178

179179
if response.persisted_size:
@@ -216,7 +216,7 @@ async def send(
216216
The request message to send. This is typically used to specify
217217
the read offset and limit.
218218
"""
219-
print(f"in _AsyncWriteObjectStream send: sending request: {bidi_write_object_request}")
219+
print(f"in _AsyncWriteObjectStream send: sending request")
220220
if not self._is_stream_open:
221221
raise ValueError("Stream is not open")
222222
await self.socket_like_rpc.send(bidi_write_object_request)
@@ -235,7 +235,7 @@ async def recv(self) -> _storage_v2.BidiWriteObjectResponse:
235235
raise ValueError("Stream is not open")
236236
print(f"in _AsyncWriteObjectStream recv: receiving response")
237237
response = await self.socket_like_rpc.recv()
238-
print(f"in _AsyncWriteObjectStream recv: received response: {response}")
238+
print(f"in _AsyncWriteObjectStream recv: received response")
239239
# Update write_handle if present in response
240240
if response:
241241
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)