Skip to content

fix(backup): close manifest summary writer before rename - #9885

Merged
shiva-istari merged 2 commits into
mainfrom
fix/s3-manifest-summary-close
Nov 17, 2026
Merged

shiva-istari merged 2 commits into
mainfrom
fix/s3-manifest-summary-close

Conversation

@matthewmcneely

@matthewmcneely matthewmcneely commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #9884.

CreateManifestSummary deferred w.Close() until after h.Rename(tmp, summary). On S3 the writer is a pipe to a background upload and the object only exists once Close() returns, so Rename copied the previous backup's manifest_summary_tmp.json. That left manifest_summary.json one backup behind manifest.json. On the first backup into a new directory the copy retried 100 times and failed with "The specified key does not exist". The file backend writes synchronously and wasn't affected.

The fix closes the writer and checks the error before Rename, the same way CreateManifest does. The writer is also closed on an encode error.

Test

Added TestCreateManifestSummary_DeferredUpload in worker/backup_manifest_test.go. It uses a handler whose CreateFile only writes the file on Close(), like the S3 upload. It runs two summaries back to back, then checks the first succeeds into an empty directory and the second publishes its own state. The test fails without the fix and passes with it. I ran the TestCreateManifestSummary and TestListBackupManifests tests in worker; I haven't run it against MinIO or real S3, and trunk check wasn't run.

🤖 Generated with Claude Code


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

Summary by CodeRabbit

  • Bug Fixes

    • Backup manifest summaries are now fully written and closed before being finalized, helping ensure saved summaries contain complete data.
    • File-close failures are reported, and summaries are not finalized when writing or closing fails.
  • Tests

    • Added coverage for repeated summary creation, confirming the latest manifest state is saved and temporary files are removed.

@matthewmcneely
matthewmcneely requested a review from a team as a code owner November 5, 2026 23:30
@coderabbitai

coderabbitai Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

CreateManifestSummary now closes the summary writer before renaming the temporary file. A new regression test uses a deferred-write handler to verify that the second summary is published and the temporary file is removed.

Changes: Manifest summary publication

Layer / File(s) Summary
Close summary before rename
worker/backup_manifest.go, worker/backup_manifest_test.go
CreateManifestSummary closes the writer after encoding and renames the temporary file only after a successful close. The regression test verifies that the second summary is published and that no temporary summary file remains.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Possibly related PRs

  • dgraph-io/dgraph#9874: Both PRs close the summary writer before rename. PR #9874 also updates dependencies and migrates Docker and metrics APIs.

Suggested labels: area/core, area/testing, go

Suggested reviewers: shiva-istari

Merge Risk: Minimal · up to 35dae

This change makes the backup manifest summary publish correctly on S3-style storage by closing the writer before the rename. No concrete merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: CreateManifestSummary now closes the manifest summary writer before the rename. The raw summary confirms the signature change, the close-before-rename ordering, and th…
Linked Issues check Passed [#9884] At head 35daedc, CreateManifestSummary in worker/backup_manifest.go no longer defers w.Close(). On encode failure it calls w.Close() (error ignored) and returns the encode error. On su…
Out of Scope Changes check Passed [#9884] All changed hunks relate to the reported defect. The CreateManifestSummary change removes the deferred close and adds the explicit close and error check. The signature change from named `ret…
Full details: Title check

Explanation

The title names the main change: CreateManifestSummary now closes the manifest summary writer before the rename. The raw summary confirms the signature change, the close-before-rename ordering, and the new test. The title is specific and matches the linked issue's objective.

Full details: Linked Issues check

Explanation

[#9884] At head 35daedc, CreateManifestSummary in worker/backup_manifest.go no longer defers w.Close(). On encode failure it calls w.Close() (error ignored) and returns the encode error. On success it calls w.Close(), wraps and returns any close error, and only then calls h.Rename. This matches the CreateManifest pattern the issue requests. The deferred-upload regression test TestCreateManifestSummary_DeferredUpload in worker/backup_manifest_test.go covers the first summary into an empty directory and the second summary publishing its own state. The MinIO system test in systest/backup/minio/backup_test.go checks that manifest_summary.json has the expected entry count and that manifest_summary_tmp.json is absent. The S3 CopyObject path is not exercised by unit tests and was not run against MinIO or S3 in this review. The issue's open question about whether the first-backup error fails the backup in worker/backup.go was not changed by this PR and is not a coding requirement here.

Full details: Out of Scope Changes check

Explanation

[#9884] All changed hunks relate to the reported defect. The CreateManifestSummary change removes the deferred close and adds the explicit close and error check. The signature change from named retErr to error follows from removing the deferred close. The unit test uses a deferred-upload fake handler to reproduce the S3 behavior. The systest addition validates summary contents and tmp-file removal after each backup, which the issue's fix depends on. No unrelated code changes were found in the reviewed diffs.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

golangci-lint (2.15.0)

level=error msg="[linters_context] typechecking error: build constraints exclude all Go files in /systest/backup/minio"

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 25e9d744-a229-408b-8f56-4d965bf58bee
Commits

Reviewing files that changed from the base of the PR and between e492894 and 35daedc.

Files selected for processing: 1

  • systest/backup/minio/backup_test.go

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@blacksmith-sh

This comment has been minimized.

Comment thread worker/backup_manifest_test.go Resolved
CreateManifestSummary deferred w.Close() until after h.Rename(). On S3 the
writer is a pipe to a background upload, so the object only exists once
Close returns. Rename copied the previous backup's temporary file, leaving
manifest_summary.json one backup behind. On the first backup into a new
directory the copy failed with "The specified key does not exist".

Close and check the error before Rename, as CreateManifest already does.
Add a regression test with a handler that only materializes the file on
Close.

Fixes #9884

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@shiva-istari
shiva-istari force-pushed the fix/s3-manifest-summary-close branch from 5ac2fdc to e492894 Compare November 16, 2026 06:42
After each backup, check that manifest_summary.json exists in the bucket with
the same number of entries as manifest.json and that manifest_summary_tmp.json
was removed. Covers the S3 CopyObject path that the fake-handler unit test
cannot exercise.
@shiva-istari
shiva-istari merged commit 765eb2e into main Nov 17, 2026
19 checks passed
@shiva-istari
shiva-istari deleted the fix/s3-manifest-summary-close branch November 17, 2026 07:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

backup: S3 manifest_summary.json is one backup behind manifest.json

2 participants