Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.apache.polaris.core.entity.PolarisEntityCore;
import org.apache.polaris.core.entity.PolarisEntitySubType;
import org.apache.polaris.core.entity.PolarisEntityType;
import org.apache.polaris.core.exceptions.CommitConflictException;
import org.apache.polaris.core.persistence.PolarisMetaStoreManager;
import org.apache.polaris.core.persistence.PolarisResolvedPathWrapper;
import org.apache.polaris.core.persistence.PolicyMappingAlreadyExistsException;
Expand Down Expand Up @@ -249,12 +250,10 @@ public Policy updatePolicy(
newPolicyEntity)
.getEntity())
.map(PolicyEntity::of)
.orElse(null);

if (newPolicyEntity == null) {
throw new IllegalStateException(
String.format("Failed to update policy %s", policyIdentifier));
}
.orElseThrow(
() ->
new CommitConflictException(
"Concurrent modification on policy '%s'; retry later", policyIdentifier));

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.

From the API client POV, I believe changing from a 500 error to 409 is a backward-compatible change.

However, should we mention 409 in the API spec?


return constructPolicy(newPolicyEntity);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,12 @@
import org.apache.polaris.core.entity.CatalogEntity;
import org.apache.polaris.core.entity.PolarisEntity;
import org.apache.polaris.core.entity.PrincipalEntity;
import org.apache.polaris.core.exceptions.CommitConflictException;
import org.apache.polaris.core.identity.provider.ServiceIdentityProvider;
import org.apache.polaris.core.persistence.PolarisMetaStoreManager;
import org.apache.polaris.core.persistence.PolicyMappingAlreadyExistsException;
import org.apache.polaris.core.persistence.dao.entity.BaseResult;
import org.apache.polaris.core.persistence.dao.entity.EntityResult;
import org.apache.polaris.core.persistence.resolver.ResolutionManifestFactory;
import org.apache.polaris.core.persistence.resolver.ResolverFactory;
import org.apache.polaris.core.policy.PredefinedPolicyTypes;
Expand Down Expand Up @@ -420,6 +423,31 @@ public void testUpdatePolicyWithWrongVersion() {
.isInstanceOf(PolicyVersionMismatchException.class);
}

@Test
public void testUpdatePolicyLosingConcurrentUpdateIsRetryableConflict() {
icebergCatalog.createNamespace(NS);
policyCatalog.createPolicy(
POLICY1, PredefinedPolicyTypes.DATA_COMPACTION.getName(), "test", "{\"enable\": false}");

// Simulate another writer winning the compare-and-swap on the policy entity.
PolarisMetaStoreManager concurrentlyModified = Mockito.spy(metaStoreManager);
Mockito.doReturn(
new EntityResult(
BaseResult.ReturnStatus.TARGET_ENTITY_CONCURRENTLY_MODIFIED, "simulated"))
.when(concurrentlyModified)
.updateEntityPropertiesIfNotChanged(Mockito.any(), Mockito.any(), Mockito.any());

PolicyCatalog catalog =
new PolicyCatalog(
concurrentlyModified,
polarisContext,
new PolarisPassthroughResolutionView(
resolutionManifestFactory, authenticatedRoot, CATALOG_NAME));

assertThatThrownBy(() -> catalog.updatePolicy(POLICY1, "updated", "{\"enable\": true}", 0))
.isInstanceOf(CommitConflictException.class);
}

@Test
public void testUpdatePolicyWithInvalidContent() {
icebergCatalog.createNamespace(NS);
Expand Down
2 changes: 1 addition & 1 deletion spec/generated/bundled-polaris-catalog-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1766,7 +1766,7 @@ paths:
PolicyToUpdateDoesNotExist:
$ref: '#/components/examples/NoSuchPolicyError'
'409':
description: The policy version doesn't match the current-policy-version; retry after fetching latest version
description: The policy version doesn't match the current-policy-version, or the policy was concurrently modified; retry after fetching latest version
content:
application/json:
schema:
Expand Down
2 changes: 1 addition & 1 deletion spec/polaris-catalog-apis/policy-apis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ paths:
PolicyToUpdateDoesNotExist:
$ref: '#/components/examples/NoSuchPolicyError'
409:
description: "The policy version doesn't match the current-policy-version; retry after fetching latest version"
description: "The policy version doesn't match the current-policy-version, or the policy was concurrently modified; retry after fetching latest version"
content:
application/json:
schema:
Expand Down