Skip to content

fix(storage): preserve source generation checks during atomic rename - #5239

Open
singh4jitendra wants to merge 1 commit into
GoogleCloudPlatform:masterfrom
singh4jitendra:fix/move-source-generation
Open

singh4jitendra wants to merge 1 commit into
GoogleCloudPlatform:masterfrom
singh4jitendra:fix/move-source-generation

Conversation

@singh4jitendra

Copy link
Copy Markdown
Contributor

Description

A rename should fail if another writer has replaced the source file. The SDK's Move call was not sending the generation selected on the source handle, so checking metageneration alone could miss that replacement.

This sends both source conditions together. The tests capture the actual HTTP request and cover a replacement with the same metageneration.

Link to the issue in case of a bug fix.

Fixes #5236

Testing details

Go 1.27.2, Ubuntu 24.04 under WSL.

  1. Manual -
    • make build - passed, including vet, lint (0 issues), formatting and compilation.
  2. Unit tests -
    • go test -mod=readonly -p 1 -count=1 -timeout=90s -run '^TestMoveObject(SourcePreconditions|RejectsReplacedSource)$' ./internal/storage - failed as expected before the fix.
    • go test -mod=readonly -p 1 -count=1 -race -timeout=90s -run '^TestMoveObject(SourcePreconditions|RejectsReplacedSource)$' ./internal/storage - passed after the fix.
    • go test -mod=readonly -p 1 -count=1 -race -timeout=5m ./internal/storage ./internal/fs/inode - passed.
  3. Integration tests - Not run against GCS. Request tests use a local HTTP server without credentials.

Any backward incompatible change? If so, please explain.

A stale rename now returns the existing precondition error instead of moving a replacement file. A zero source generation still means the latest object without a generation condition. Destination behavior is unchanged.

Send source generation and metageneration in the same Move conditions so a stale rename cannot move a replacement object. Add HTTP request regressions and keep zero-generation behavior unchanged.

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

Copy link
Copy Markdown
Contributor

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 updates the MoveObject operation in internal/storage/bucket_handle.go to correctly apply source preconditions (GenerationMatch and MetagenerationMatch) using storage.Conditions instead of directly setting the generation on the object handle. It also updates the documentation comments in internal/storage/gcs/request.go to clarify this behavior and adds comprehensive unit tests in internal/storage/bucket_handle_test.go to verify that source preconditions are correctly sent and handled. There are no review comments to address, and the changes look solid.

@singh4jitendra
singh4jitendra marked this pull request as ready for review November 12, 2026 08:11
@singh4jitendra
singh4jitendra requested a review from a team as a code owner November 12, 2026 08:11
@singh4jitendra

Copy link
Copy Markdown
Contributor Author

Hi @meet2mky, could you review this rename fix when you get a chance? Let me know if there's anything you'd like changed. Thanks!

@singh4jitendra

Copy link
Copy Markdown
Contributor Author

Hi @meet2mky, could you finish the review when you get a chance and merge if all looks good? Thanks!

@singh4jitendra

Copy link
Copy Markdown
Contributor Author

Hi @meet2mky, could you take a look at the source-generation check for rename when you get a chance? The regression test is in, and I'd be happy to make any changes needed. Thanks!

@singh4jitendra

Copy link
Copy Markdown
Contributor Author

Hi @meet2mky, I'd appreciate your review of the rename generation-check fix when you have a moment. Happy to make any adjustments needed. Thanks!

@singh4jitendra

Copy link
Copy Markdown
Contributor Author

Hi @meet2mky, could you review the rename generation-check fix when you get a chance? Thanks!

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

Labels

None yet

1 participant