Skip to content

feat: Use CLI to perform replace for on-conflict flag - #583

Draft
devanbenz wants to merge 4 commits into
mainfrom
db/27578/staged-replace
Draft

feat: Use CLI to perform replace for on-conflict flag#583
devanbenz wants to merge 4 commits into
mainfrom
db/27578/staged-replace

Conversation

@devanbenz

Copy link
Copy Markdown
Contributor

No description provided.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Moves --on-conflict replace handling into the CLI using a temporary bucket.

Changes:

  • Stages restored data before replacing an existing bucket.
  • Adds restore API mocks and replacement tests.
  • Clarifies CLI flag behavior.

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
clients/restore/restore.go Implements staged bucket replacement.
clients/restore/restore_internal_test.go Tests replacement workflows.
cmd/influx/restore.go Updates flag help text.
internal/mock/gen.go Adds restore mock generation.
internal/mock/api_restore.gen.go Provides generated restore API mock.
Files not reviewed (1)
  • internal/mock/api_restore.gen.go: Generated file

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread clients/restore/restore.go
Comment thread clients/restore/restore.go Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 5 changed files in this pull request and generated no new comments.

Files not reviewed (1)
  • internal/mock/api_restore.gen.go: Generated file
Suppressed comments (4)

clients/restore/restore.go:428

  • This generated aside name can also exceed InfluxDB's bucket-name limit. Because this rename occurs only after every shard has uploaded, a long but valid original name makes the replace fail at the final swap and leaves the restored data under its temporary name. Use a bounded name that does not include the full original name.
	asideName := fmt.Sprintf("%s-replaced-tmp-%d", swap.name, time.Now().UnixNano())

clients/restore/restore.go:435

  • The rollback reuses ctx. The CLI cancels this context on SIGINT/SIGTERM (pkg/signals/context.go:28-30), so if cancellation causes the promotion to fail, the rollback is guaranteed to fail too; the old bucket remains under the aside name and the original name disappears. Use a bounded context detached from cancellation for this compensating rename.
		if _, rollbackErr := c.PatchBucketsID(ctx, swap.oldID).PatchBucketRequest(api.PatchBucketRequest{Name: &swap.name}).Execute(); rollbackErr != nil {
			log.Printf("WARN: Failed to restore original name of bucket %q (currently %q): %v\n", swap.name, asideName, rollbackErr)
		}

clients/restore/restore.go:418

  • InfluxDB bucket names must be fewer than 64 characters, but this appends roughly 32 characters to an already-valid name. Any existing bucket with a moderately long name will therefore fail before staging starts. Generate a bounded temporary name independent of the original name.

This issue also appears on line 428 of the same file.

	bkt.BucketName = fmt.Sprintf("%s-restore-tmp-%d", bkt.BucketName, time.Now().UnixNano())

clients/restore/restore.go:371

  • If shard upload fails because the CLI context was canceled, this cleanup request reuses the already-canceled context and fails immediately, leaving a potentially full-size temporary bucket behind. Run the compensating delete with a bounded context detached from cancellation while preserving context values.

This issue also appears on line 433 of the same file.

		if err := c.DeleteBucketsID(ctx, bucketID).Execute(); err != nil {
			log.Printf("WARN: Failed to delete temporary bucket %q: %v\n", bkt.BucketName, err)
		}

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 5 changed files in this pull request and generated no new comments.

Files not reviewed (1)
  • internal/mock/api_restore.gen.go: Generated file
Suppressed comments (2)

clients/restore/restore.go:436

  • The same unbounded suffix issue occurs when renaming the old bucket aside: a valid long bucket name makes this PATCH fail, so the fully uploaded temporary bucket can never be promoted. Use the same bounded ID/nonce-based naming helper for the aside name.
	asideName := fmt.Sprintf("%s-replaced-tmp-%d", swap.name, time.Now().UnixNano())

clients/restore/restore.go:356

  • Appending the staging suffix to the user’s bucket name can exceed InfluxDB’s bucket-name length limit even though the original name is valid, causing --on-conflict replace to fail before any shards are uploaded. Generate a bounded temporary name independent of the full bucket name (for example, from the existing bucket ID plus a nonce) and cover a maximum-length bucket name.

This issue also appears on line 436 of the same file.

			bkt.BucketName = fmt.Sprintf("%s-restore-tmp-%d", bkt.BucketName, time.Now().UnixNano())

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.

2 participants