Skip to content

Handle a lost destination-name race in AtomicOperationMetaStoreManager.renameEntity() #5985

Closed

Description

@ZephyrYWZhou

Background

During the review of #5892, @flyrain pointed out that a rename can lose a race for its destination name, and that the failure is not handled. This was agreed to be fixed in a follow-up, for both the JDBC and DynamoDB (atomic) backends.

The problem

AtomicOperationMetaStoreManager.renameEntity() checks that the destination name is free, then calls persistEntityAfterChange(...). If another writer claims that name between the check and the write, the write fails on the name constraint. renameEntity() only catches RetryOnConcurrencyException, so the failure escapes as an unhandled error instead of an ENTITY_ALREADY_EXISTS result.

The two backends surface it differently today:

  • DynamoDB (atomic, Persistence: DynamoDB (atomic) entity writes, CAS and name uniqueness #5892): the rename transaction fails on the destination name sentinel and throws EntityAlreadyExistsException, which renameEntity() does not catch.
  • JDBC: the update path in JdbcBasePersistenceImpl.writeEntity() does not check for a uniqueness violation the way the create path does, so the constraint error is wrapped by wrapEntityWriteFailure(...) into a generic RuntimeException.

A create in the same situation already returns ENTITY_ALREADY_EXISTS (persistNewEntity catches EntityAlreadyExistsException), so rename is the odd one out.

Proposed fix

  1. In AtomicOperationMetaStoreManager.renameEntity(), map EntityAlreadyExistsException to ENTITY_ALREADY_EXISTS, along the lines of:
try {
  renamedEntityToReturn =
      this.persistEntityAfterChange(
          callCtx, ms, refreshEntityToRenameBuilder.build(), true, refreshEntityToRename);
} catch (EntityAlreadyExistsException e) {
  return new EntityResult(
      BaseResult.ReturnStatus.ENTITY_ALREADY_EXISTS,
      e.getExistingEntity().getSubTypeCode());
} catch (RetryOnConcurrencyException e) {
  return new EntityResult(
      BaseResult.ReturnStatus.TARGET_ENTITY_CONCURRENTLY_MODIFIED, e.getMessage());
}
  1. In JdbcBasePersistenceImpl.writeEntity(), translate a uniqueness violation on the update path into EntityAlreadyExistsException, matching the create path.

Acceptance Criteria

  1. A rename whose destination name is claimed concurrently returns ENTITY_ALREADY_EXISTS on both JDBC and DynamoDB, instead of an unhandled exception.
  2. A test covers this race at the metastore-manager level.
  3. Existing rename and create behavior is unchanged.

Related: #5892, #5615

Activity

  1. flyrain commented on Nov 5, 2026

    @flyrain
    Contributor

    Thanks for filing this issue, @ZephyrYWZhou . I think the fix option 1 would be preferable, as it avoid coupling Iceberg exception to the persistence layer.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions