Skip to content

storage: replay unflushed tail after reconnect in AsyncAppendableObjectWriter #19101

Open

Description

@Yonghui-Lee

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 every write() through as an append().
  • gcsfs put_file uses 50 MiB chunks with the 16 MiB default interval.
  • append_from_file with a block_size that is not a multiple of flush_interval.

Real-GCS results with FLUSH_INTERVAL_BYTES=4 MiB and one stream reset (from review of #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 _WriteState a reader that chains [tail, data], with initial_offset set to the tail start. The existing reset_to_persisted() then rewinds into the tail and resends from persisted_size.
  • Trim the tail whenever the server confirms a new persisted_size (flush(), state_lookup(), flush responses inside append()). Cap it at 2 * flush_interval.
  • In close() and finalize(), replay the missing range from the tail after a reconnect, then close.
  • Keep DataLoss when the server reports persisted_size below the tail start.

Follow-up to #19091 and #19092.

Activity

  1. added 5 commits that reference this issue on Nov 17, 2026
    f7ff5ac
    9f6154d
    bf4c9e1
    4789b32
    6097940
  2. added a commit that references this issue on Nov 25, 2026
    f7212a2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions