Repository navigation
Description
Summary
AsyncAppendableObjectWriter.append() only requests persistence (flush=True) each time flush_interval bytes have been sent, and the counter carries across calls. When an append() call does not end on a flush_interval boundary, its trailing bytes have been sent but not flushed.
On a real Zonal bucket, the server can drop those unflushed bytes if the stream breaks shortly afterwards. For example, append(12 MiB) with the default 16 MiB interval followed by an immediate stream reset reopened with persisted_size=0. After about 3 seconds the bytes were persisted.
The writer no longer holds those bytes. append(data) only wraps the current call's data, so a reconnect during the next append() cannot resend them.
After #19092 this case raises DataLoss instead of silently truncating the object. That is safe, but the failure is avoidable because the writer had the bytes moments earlier.
Who hits it
Appends that are not aligned to flush_interval are the common case:
- gcsfs
ZonalFile.write()passes everywrite()through as anappend(). - gcsfs
put_fileuses 50 MiB chunks with the 16 MiB default interval. append_from_filewith ablock_sizethat is not a multiple offlush_interval.
Real-GCS results with FLUSH_INTERVAL_BYTES=4 MiB and one stream reset (from review of #19092):
- 2 x 5 MiB appends, reset at 9 MiB: recovers with fix(storage): seek relative to initial_offset when retrying multi-call append #19092.
- 2 x 5 MiB appends, reset at 6 MiB:
DataLosswith fix(storage): seek relative to initial_offset when retrying multi-call append #19092. - 10 x 1 MiB appends, reset at 5 MiB:
DataLosswith fix(storage): seek relative to initial_offset when retrying multi-call append #19092.
close() and finalize() have the same gap. After #19092 they raise DataLoss on a reconnect offset mismatch instead of retrying until the deadline, but they cannot recover either.
Proposal
Keep the bytes sent since the last server-confirmed persisted offset on the writer (normally less than flush_interval) and replay them after a reconnect:
- Store the unconfirmed tail as a list of copied segments. Callers may reuse their buffer after
append()returns, so the tail must be a copy. - Feed
_WriteStatea reader that chains[tail, data], withinitial_offsetset to the tail start. The existingreset_to_persisted()then rewinds into the tail and resends frompersisted_size. - Trim the tail whenever the server confirms a new
persisted_size(flush(),state_lookup(), flush responses insideappend()). Cap it at2 * flush_interval. - In
close()andfinalize(), replay the missing range from the tail after a reconnect, then close. - Keep
DataLosswhen the server reportspersisted_sizebelow the tail start.
Activity
fix(storage): replay unflushed tail after reconnect in AsyncAppendabl…
fix(storage): replay unflushed tail after reconnect in AsyncAppendabl…
fix(storage): replay unflushed tail after reconnect in AsyncAppendabl…
fix(storage): replay unflushed tail after reconnect in AsyncAppendabl…
fix(storage): replay unflushed tail after reconnect in AsyncAppendabl…
fix(storage): replay unflushed tail after reconnect in AsyncAppendabl…