Skip to content

feat(storage): Adding takeover operation checksum for bidi appendable uploads#13361

Draft
Dhriti07 wants to merge 1 commit into
add-cumulative-hasher-bidi-flowfrom
takeover-checksum-impl
Draft

feat(storage): Adding takeover operation checksum for bidi appendable uploads#13361
Dhriti07 wants to merge 1 commit into
add-cumulative-hasher-bidi-flowfrom
takeover-checksum-impl

Conversation

@Dhriti07
Copy link
Copy Markdown
Contributor

@Dhriti07 Dhriti07 commented Jun 4, 2026

Adding takeover operation checksum for bidi appendable uploads

@Dhriti07 Dhriti07 requested review from a team as code owners June 4, 2026 05:34
@Dhriti07 Dhriti07 marked this pull request as draft June 4, 2026 05:34
@Dhriti07 Dhriti07 marked this pull request as ready for review June 4, 2026 05:35
@Dhriti07 Dhriti07 marked this pull request as draft June 4, 2026 05:35
@Dhriti07 Dhriti07 changed the base branch from main to add-cumulative-hasher-bidi-flow June 4, 2026 05:36
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces CumulativeHasher, a wrapper around Hasher that accumulates checksums and validates them at the end of a full object read. It integrates this cumulative validation into BaseObjectReadSessionStreamRead, GapicUnbufferedReadableByteChannel, and ObjectReadSessionStream, and adds comprehensive unit and integration tests. The reviewer feedback highlights two important issues: first, GapicUnbufferedReadableByteChannel should check !(hasher instanceof Hasher.NoOpHasher) before wrapping to prevent false-positive validation failures when checksumming is disabled; second, the cumulativeHash field in CumulativeHasher should be declared volatile to ensure thread safety and proper memory visibility across threads.

I am having trouble creating individual review comments. Click here to see my feedback.

java-storage/google-cloud-storage/src/main/java/com/google/cloud/storage/GapicUnbufferedReadableByteChannel.java (95-103)

critical

When checksum validation is disabled, hasher is an instance of Hasher.NoOpHasher. In GapicUnbufferedReadableByteChannel, we do not check for Hasher.NoOpHasher before wrapping it in CumulativeHasher. This will cause CumulativeHasher to be used even when checksumming is disabled, leading to a false-positive UncheckedCumulativeChecksumMismatchException at the end of a full-object read (since the cumulative hash will remain 0 while the expected metadata hash is non-zero).

We should add a check !(hasher instanceof Hasher.NoOpHasher) to match the behavior in BaseObjectReadSessionStreamRead.

    this.hasher =
        (req.getReadOffset() == 0 && !(hasher instanceof Hasher.NoOpHasher))
            ? new CumulativeHasher(
                hasher,
                0,
                req.getReadLimit() <= 0
                    ? OptionalLong.empty()
                    : OptionalLong.of(req.getReadLimit()))
            : hasher;

java-storage/google-cloud-storage/src/main/java/com/google/cloud/storage/CumulativeHasher.java (37)

medium

The cumulativeHash field is updated by the thread processing the stream responses (e.g., the gRPC callback thread or user thread) and read by another thread (e.g., the executor thread in ObjectReadSessionStream or user thread). To ensure proper memory visibility across different threads and avoid potential concurrency issues, cumulativeHash should be declared as volatile.

  private volatile Crc32cLengthKnown cumulativeHash;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant