-
Notifications
You must be signed in to change notification settings - Fork 906
[#12342] improvement(core): add OCC for namespace hierarchy #12350
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
yuqi1129
wants to merge
12
commits into
apache:main
from
yuqi1129:feat/12342-occ-namespace-hierarchy
Closed
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
472a791
[#12342] improvement(core): add OCC for namespace hierarchy
yuqi1129 c302751
[#12342] fix(core): make managed namespace mutations atomic
yuqi1129 51b3470
[#12342] test(fileset): initialize managed schema parents
yuqi1129 97e1fc8
[#12342] test(kafka): persist managed catalog parents
yuqi1129 31a90c8
[#12342] fix(core): close namespace OCC races
yuqi1129 11d7aa8
[#12342] fix(core): harden namespace OCC locking
yuqi1129 ca1b700
[#12342] fix(core): protect schema entity writes
yuqi1129 608fef5
Merge remote-tracking branch 'apache/main' into feat/12342-occ-namesp…
yuqi1129 adb7ee3
[#12342] fix(core): update catalog manager test setup
yuqi1129 ae0451d
Merge remote-tracking branch 'upstream/main' into feat/12342-occ-name…
yuqi1129 8fad8b8
[#12342] improvement(core): unify OptimisticLockException creation
yuqi1129 f070d75
Merge remote-tracking branch 'apache/main' into feat/12342-occ-namesp…
yuqi1129 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,6 +34,7 @@ | |
| import org.apache.gravitino.Namespace; | ||
| import org.apache.gravitino.exceptions.NoSuchEntityException; | ||
| import org.apache.gravitino.exceptions.NonEmptyEntityException; | ||
| import org.apache.gravitino.exceptions.OptimisticLockException; | ||
| import org.apache.gravitino.meta.CatalogEntity; | ||
| import org.apache.gravitino.meta.SchemaEntity; | ||
| import org.apache.gravitino.metrics.Monitored; | ||
|
|
@@ -229,15 +230,19 @@ public <E extends Entity & HasIdentifier> CatalogEntity updateCatalog( | |
| AtomicInteger updateResult = new AtomicInteger(0); | ||
| try { | ||
| SessionUtils.doMultipleWithCommit( | ||
| () -> | ||
| updateResult.set( | ||
| SessionUtils.getWithoutCommit( | ||
| CatalogMetaMapper.class, | ||
| mapper -> | ||
| mapper.updateCatalogMeta( | ||
| POConverters.updateCatalogPOWithVersion( | ||
| oldCatalogPO, newEntity, oldCatalogPO.getMetalakeId()), | ||
| oldCatalogPO))), | ||
| () -> { | ||
| updateResult.set( | ||
| SessionUtils.getWithoutCommit( | ||
| CatalogMetaMapper.class, | ||
| mapper -> | ||
| mapper.updateCatalogMeta( | ||
| POConverters.updateCatalogPOWithVersion( | ||
| oldCatalogPO, newEntity, oldCatalogPO.getMetalakeId()), | ||
| oldCatalogPO))); | ||
| if (updateResult.get() == 0) { | ||
| throw optimisticLockException(identifier); | ||
| } | ||
| }, | ||
| () -> { | ||
| if (updateResult.get() > 0) { | ||
| SessionUtils.doWithoutCommit( | ||
|
|
@@ -256,11 +261,7 @@ public <E extends Entity & HasIdentifier> CatalogEntity updateCatalog( | |
| throw re; | ||
| } | ||
|
|
||
| if (updateResult.get() > 0) { | ||
| return newEntity; | ||
| } else { | ||
| throw new IOException("Failed to update the entity: " + identifier); | ||
| } | ||
| return newEntity; | ||
| } | ||
|
|
||
| @Monitored( | ||
|
|
@@ -270,15 +271,14 @@ public boolean deleteCatalog(NameIdentifier identifier, boolean cascade) { | |
| NameIdentifierUtil.checkCatalog(identifier); | ||
|
|
||
| String catalogName = identifier.name(); | ||
| long catalogId = EntityIdService.getEntityId(identifier, Entity.EntityType.CATALOG); | ||
| CatalogPO catalogPO = getCatalogPOByName(identifier.namespace().level(0), catalogName); | ||
| long catalogId = catalogPO.getCatalogId(); | ||
| long currentVersion = catalogPO.getCurrentVersion(); | ||
| String metalakeName = identifier.namespace().level(0); | ||
|
|
||
| if (cascade) { | ||
| SessionUtils.doMultipleWithCommit( | ||
| () -> | ||
| SessionUtils.doWithoutCommit( | ||
| CatalogMetaMapper.class, | ||
| mapper -> mapper.softDeleteCatalogMetasByCatalogId(catalogId)), | ||
| () -> deleteCatalogWithVersion(identifier, catalogId, currentVersion), | ||
| () -> | ||
| SessionUtils.doWithoutCommit( | ||
| SchemaMetaMapper.class, | ||
|
|
@@ -368,10 +368,7 @@ public boolean deleteCatalog(NameIdentifier identifier, boolean cascade) { | |
| "Entity %s has sub-entities, you should remove sub-entities first", identifier); | ||
| } | ||
| SessionUtils.doMultipleWithCommit( | ||
| () -> | ||
| SessionUtils.doWithoutCommit( | ||
| CatalogMetaMapper.class, | ||
| mapper -> mapper.softDeleteCatalogMetasByCatalogId(catalogId)), | ||
| () -> deleteCatalogWithVersion(identifier, catalogId, currentVersion), | ||
| () -> | ||
| SessionUtils.doWithoutCommit( | ||
| OwnerMetaMapper.class, | ||
|
|
@@ -415,6 +412,22 @@ public boolean deleteCatalog(NameIdentifier identifier, boolean cascade) { | |
| return true; | ||
| } | ||
|
|
||
| private void deleteCatalogWithVersion( | ||
| NameIdentifier identifier, Long catalogId, Long currentVersion) { | ||
| int deleted = | ||
| SessionUtils.getWithoutCommit( | ||
| CatalogMetaMapper.class, | ||
| mapper -> mapper.softDeleteCatalogMetasByCatalogId(catalogId, currentVersion)); | ||
| if (deleted == 0) { | ||
| throw optimisticLockException(identifier); | ||
| } | ||
| } | ||
|
|
||
| private OptimisticLockException optimisticLockException(NameIdentifier identifier) { | ||
| return new OptimisticLockException( | ||
| "The catalog %s was modified concurrently; retry the operation", identifier); | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can define this method in the helper method. |
||
|
|
||
| @Monitored( | ||
| metricsSource = GRAVITINO_RELATIONAL_STORE_METRIC_NAME, | ||
| baseMetricName = "deleteCatalogMetasByLegacyTimeline") | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.