Skip to content

[#12452] improvement(core): add OCC for catalog writes - #12455

Draft
yuqi1129 wants to merge 2 commits into
apache:mainfrom
yuqi1129:feat/12342-occ-catalog
Draft

[#12452] improvement(core): add OCC for catalog writes#12455
yuqi1129 wants to merge 2 commits into
apache:mainfrom
yuqi1129:feat/12342-occ-catalog

Conversation

@yuqi1129

@yuqi1129 yuqi1129 commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

Add database-backed optimistic concurrency control and transaction boundaries for catalog writes.

  • Advance the catalog OCC version on every alter, and guard alter and drop with a compare-and-set on the observed version, classifying a failed CAS as either a stale-version conflict or an already-missing entity.
  • Protect catalog creation with a shared lock on the parent metalake row on MySQL and PostgreSQL, without changing the parent version. H2 uses an exclusive lock because it has no shared row-lock syntax.
  • Keep the catalog CAS and the non-empty check or the cascade cleanup in one database transaction, and CAS-delete descendant schemas with their observed identifier-and-version pairs.
  • Discard the stale local cache entry when a drop loses the race to another server, so the drop stays idempotent.

Rebased on current main (on top of #12374). Second of three PRs replacing #12350. Stacked on the metalake PR; review the top commit only.

Why are the changes needed?

Managed catalog operations previously consisted of multiple independent reads and writes. Concurrent alter, create, and drop requests could overwrite newer metadata, create a catalog below a metalake that was being deleted, or run partial cascade cleanup.

Fix: #12452

Does this PR introduce any user-facing change?

Concurrent catalog version conflicts are reported as HTTP 409. If the observed entity was deleted or renamed away, alter reports not found and drop preserves its idempotent false result.

How was this patch tested?

  • ./gradlew :core:test :core:javadoc -PskipITs (H2)
  • New tests in TestCatalogMetaService, TestCatalogManager, TestPOConverters.
  • MySQL and PostgreSQL coverage is left to CI (-PskipDockerTests=false).

Advance the metalake OCC version on every alter and guard alter and
delete with a compare-and-set on the observed version, classifying a
failed CAS as either a stale conflict or a missing entity.

Keep the metalake root CAS and the non-empty check or the cascade
cleanup inside one database transaction. A cascade locks the catalog
rows first, then compare-and-set deletes descendant catalogs and schemas
with their observed identifier-and-version pairs, so a concurrent child
write is reported instead of silently dropped.

Also add the shared OptimisticLockException factories used by the
follow-up catalog and schema changes.
Advance the catalog OCC version on every alter and guard alter and
delete with a compare-and-set on the observed version, classifying a
failed CAS as either a stale conflict or a missing entity.

Protect catalog creation with a shared lock on the parent metalake row
on MySQL and PostgreSQL, without changing the parent version, so a
catalog can no longer be created below a metalake that is being
dropped. H2 uses an exclusive lock because it has no shared row-lock
syntax.

Keep the catalog CAS and the non-empty check or the cascade cleanup
inside one database transaction, and CAS-delete descendant schemas with
their observed identifier-and-version pairs.
@github-actions

Copy link
Copy Markdown

Code Coverage Report

Overall Project 68.7% +0.35% 🟢
Files changed 81.9% 🟢

Module Coverage
aliyun 1.72% 🔴
api 49.31% 🟢
authorization-common 85.96% 🟢
aws 42.04% 🟢
azure 2.47% 🔴
catalog-common 9.92% 🔴
catalog-fileset 79.77% 🟢
catalog-glue 68.95% 🟢
catalog-hive 79.4% 🟢
catalog-jdbc-common 45.7% 🟢
catalog-jdbc-doris 81.8% 🟢
catalog-jdbc-mysql 79.33% 🟢
catalog-jdbc-postgresql 83.39% 🟢
catalog-jdbc-starrocks 79.16% 🟢
catalog-kafka 77.01% 🟢
catalog-lakehouse-generic 59.18% 🟢
catalog-lakehouse-hudi 79.1% 🟢
catalog-lakehouse-iceberg 85.86% 🟢
catalog-lakehouse-paimon 84.23% 🟢
catalog-model 77.72% 🟢
cli 44.48% 🟢
client-java 78.46% 🟢
common 52.75% 🟢
core 83.69% -0.16% 🟢
filesystem-hadoop3 77.28% 🟢
flink 0.0% 🔴
flink-common 48.68% 🟢
flink-runtime 0.0% 🔴
gcp 14.12% 🔴
hadoop-auth 68.0% 🟢
hadoop-common 12.7% 🔴
hive-metastore-common 53.4% 🟢
iceberg-aliyun-bundle 0.0% 🔴
iceberg-common 64.75% 🟢
iceberg-rest-server 75.1% 🟢
idp-basic 86.02% 🟢
integration-test-common 0.0% 🔴
jobs 62.92% 🟢
lance-common 31.75% 🔴
lance-rest-server 63.47% 🟢
lineage 53.02% 🟢
optimizer 83.17% 🟢
optimizer-api 21.95% 🔴
server 87.38% 🟢
server-common 79.41% 🟢
spark 28.57% 🔴
spark-common 45.89% 🟢
tencent 69.84% 🟢
trino-connector 40.29% 🟢
Files
Module File Coverage
core MetalakeMetaSQLProviderFactory.java 100.0% 🟢
MetalakeMetaBaseSQLProvider.java 100.0% 🟢
MetalakeMetaService.java 98.65% 🟢
CatalogMetaService.java 94.35% 🟢
CatalogMetaSQLProviderFactory.java 89.66% 🟢
CatalogMetaBaseSQLProvider.java 89.47% 🟢
ExceptionUtils.java 88.89% 🟢
POConverters.java 88.32% 🟢
CatalogMetaPostgreSQLProvider.java 83.33% 🟢
MetalakeMetaPostgreSQLProvider.java 83.33% 🟢
SchemaMetaSQLProviderFactory.java 71.88% 🟢
SchemaMetaPostgreSQLProvider.java 71.43% 🟢
CatalogManager.java 70.56% 🟢
MetalakeManager.java 65.88% 🟢
SchemaMetaBaseSQLProvider.java 63.64% 🟢
CatalogMetaMapper.java 0.0% 🔴
MetalakeMetaMapper.java 0.0% 🔴
SchemaMetaMapper.java 0.0% 🔴

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.

[Subtask] Add version-CAS OCC for catalog writes

1 participant