Skip to content

Server-side retry for conflicting rename operations - #4733

Open
Sasilekha wants to merge 3 commits into
apache:mainfrom
Sasilekha:rename-retry
Open

Sasilekha wants to merge 3 commits into
apache:mainfrom
Sasilekha:rename-retry

Conversation

@Sasilekha

@Sasilekha Sasilekha commented Jun 12, 2026 •

Copy link
Copy Markdown

PolarisEntity currentLeaf = leafEntity;
EntityResult returnedEntityResult = null;
IcebergTableLikeEntity toEntity = null;
for (int attempt = 1; attempt <= maxAttempts; attempt++) {

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.

Would it be possible to use the Tasks API from Iceberg. Example:

Tasks.foreach(ops)
.retry(maxCommitRetries)
.exponentialBackoff(
COMMIT_MIN_RETRY_WAIT_MS_DEFAULT,
COMMIT_MAX_RETRY_WAIT_MS_DEFAULT,
COMMIT_TOTAL_RETRY_TIME_MS_DEFAULT,
2.0 /* exponential */)
.onlyRetryOn(CommitFailedException.class)
.run(
taskOps -> {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

done @adutra, switched the rename retry over to Iceberg's Tasks API, same pattern as CatalogHandlerUtils (retry, exponentialBackoff, onlyRetryOn). Thanks for checking!

@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions Bot added the stale label Jul 16, 2026
@github-actions github-actions Bot closed this Jul 21, 2026
@github-project-automation github-project-automation Bot moved this from PRs In Progress to Done in Basic Kanban Board Jul 21, 2026
@flyrain flyrain reopened this Oct 26, 2026
@github-project-automation github-project-automation Bot moved this from Done to PRs In Progress in Basic Kanban Board Oct 26, 2026

@orca-review-bot orca-review-bot 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.

Thanks for picking this up. Retrying after a concurrent commit looks right. The problem is the case where the competing operation is another rename: on the atomic manager the retry renames the already-moved table, and on the transactional manager it surfaces as a misleading 404 (details inline).

Unanchored items:

  • Tests only stub renameEntity to return the conflict status, so no real competing rename is exercised. Can we add one that really moves the source first, plus a RENAME_RETRY_MAX_ATTEMPTS=0 case and a renameView case?
  • PR description is just #4729. Can we add the motivation, Fixes #4729, and the 500→503 / 500→404 status-code changes?
  • Verified fine: authz is unchanged (handler authorizes before renameTableLike), and the reload stays within the same catalog.

🤖 AI-generated review comment — agents make mistakes, so please verify before acting on it.

returnedEntityResult = new EntityResult(BaseResult.ReturnStatus.ENTITY_NOT_FOUND, null);
break;
}
currentLeaf = PolarisEntity.of(reloaded.getEntity());

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

After reloading we retry with whatever the entity looks like now, but we never check it's still from. If the conflict came from another rename that already succeeded, the retry renames the moved table to to. AtomicOperationMetaStoreManager.renameEntity only checks the version and re-parents onto the path we pass in, so this succeeds silently. The other client's rename gets overwritten, and in the same-namespace case the table moves back into the original namespace. Can we check that the reloaded name and parent id still match from, and throw NoSuchTableException/NoSuchViewException if they don't?

🤖 AI-generated review comment — agents make mistakes, so please verify before acting on it.


// Source or destination path was concurrently dropped. This is non-retriable: the
// client must observe the new namespace state before issuing another rename.
case BaseResult.ReturnStatus.ENTITY_CANNOT_BE_RESOLVED:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

On the transactional manager, this status also comes back when the source table was renamed by someone else: the resolver looks up the stale (parent, name) before it checks the version. In that case the namespace still exists. It's the table that's gone, so a 404 'namespace not found' sends the client looking in the wrong place. Should ENTITY_CANNOT_BE_RESOLVED map to NoSuchTableException/NoSuchViewException, and keep NoSuchNamespaceException only for CATALOG_PATH_CANNOT_BE_RESOLVED?

🤖 AI-generated review comment — agents make mistakes, so please verify before acting on it.

// off and retry. We avoid 409 here because the Iceberg rename endpoint reserves it
// for "target already exists" (handled by the ENTITY_ALREADY_EXISTS case above).
case BaseResult.ReturnStatus.TARGET_ENTITY_CONCURRENTLY_MODIFIED:
throw new ServiceUnavailableException(

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

If the sleep is interrupted we break out early, but this message still says we made maxAttempts attempts. Can we track the actual attempt count and print that?

🤖 AI-generated review comment — agents make mistakes, so please verify before acting on it.

.defaultValue(2)
.buildFeatureConfiguration();

public static final FeatureConfiguration<Integer> RENAME_RETRY_MAX_ATTEMPTS =

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Each retry sleeps on the request worker thread, and this flag has no upper bound. The default 3 is harmless, but a realm set to something large could keep threads busy under contention. Can we clamp it, e.g. to 10, in renameTableLike?

🤖 AI-generated review comment — agents make mistakes, so please verify before acting on it.

@Sasilekha
Sasilekha requested a review from adutra October 28, 2026 07:02

@vigneshio vigneshio 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.

Thanks @Sasilekha. Left a note on the retry reload.

new EntityResult(BaseResult.ReturnStatus.ENTITY_NOT_FOUND, null));
return;
}
leaf = PolarisEntity.of(reloaded.getEntity());

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.

After a reload, would you mind checking this is still from before we apply to? loadEntity is by id, so if another rename already moved the table, the retry would move it a second time and overwrite that rename.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done. After a reload we check the name and parent still match from before applying to. If another rename already moved the table we throw NoSuchTableException/NoSuchViewException instead of moving it again.

Stop a rename retry when the reloaded entity is no longer at the source name and parent, so an already-moved table is not renamed again.

@vigneshio vigneshio 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.

Thanks @Sasilekha. LGTM..

@dimas-b dimas-b 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.

Thanks for your contribution, @Sasilekha !

Comment thread CHANGELOG.md

### Fixes

- `renameTable` and `renameView` now retry a concurrent modification of the source entity

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.

This probably belongs in the "changes" section rather than "fixes"

.exponentialBackoff(
COMMIT_MIN_RETRY_WAIT_MS_DEFAULT,
COMMIT_MAX_RETRY_WAIT_MS_DEFAULT,
COMMIT_TOTAL_RETRY_TIME_MS_DEFAULT,

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.

These parameters should probably be configurable in Polaris.

Comment on lines 2981 to 2987
validateLocationsForRenamedTableLike(
subType,
from,
to,
IcebergTableLikeEntity.of(leafEntity),
resolvedEntities,
resolvedNewParentEntities);

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.

This should be done on every retry (leafEntity is reloaded).

if (isRetry.get()) {
EntityResult reloaded =
getMetaStoreManager()
.loadEntity(

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.

I believe retries should use the same loading method as the "main" (old) execution path.

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.

TBH, implementing this properly may require bigger changes. Cf. https://lists.apache.org/thread/hygmo5mby1k56g5d480nnd56p11k5gvg

Note that internal RBAC grants may change between retries. If entities are reloaded and internal RBAC is "on", grants ought to be reloaded too, I believe.

@dennishuo : WDYT?

2.0 /* exponential */)
.onlyRetryOn(ConcurrentRenameException.class)
.run(
source -> {

@dimas-b dimas-b Nov 3, 2026 •

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.

It might be worth using a dedicated private method for the (retriable) body of the rename operation.

@adutra

adutra commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Heads-up: #5967 has been merged, so CHANGELOG.md is no longer edited directly. Changelog entries now go in a fragment file under changelog.d/, which avoids merge conflicts on CHANGELOG.md. See changelog.d/README.md for the format.

Could you rebase onto main, revert your changes to CHANGELOG.md, and add a fragment file instead if your change needs a changelog entry? A fragment is only needed for things worth calling out in release notes, such as breaking changes, metastore schema changes, or changes that require manual steps during an upgrade. Thanks!

This branch has not been deployed

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants