-
Notifications
You must be signed in to change notification settings - Fork 918
[#12345] improvement(core): add OCC for table writes #12551
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
Changes from 14 commits
791f5e9
0192405
7011c5d
cc97151
ce9eb5d
23d0f3c
14a737e
60649b9
57d8513
ed8d3e2
c763996
43ed77d
81e19f4
1d874db
5376053
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,6 +35,7 @@ | |
| import org.apache.gravitino.connector.PropertiesMetadata; | ||
| import org.apache.gravitino.connector.capability.Capability; | ||
| import org.apache.gravitino.exceptions.NoSuchEntityException; | ||
| import org.apache.gravitino.exceptions.OptimisticLockException; | ||
| import org.apache.gravitino.file.FilesetChange; | ||
| import org.apache.gravitino.messaging.TopicChange; | ||
| import org.apache.gravitino.rel.SupportsPartitions; | ||
|
|
@@ -214,11 +215,23 @@ protected StringIdentifier getStringIdFromProperties(Map<String, String> propert | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * Runs a store operation as a best-effort side effect of the request. | ||
| * | ||
| * <p>Every failure is logged and reported as a null result, because the external catalog is the | ||
| * source of truth on these paths: a load that imports or repairs the Gravitino copy must still | ||
| * return the entity it read, and the next load repairs what this one could not write. | ||
| */ | ||
| protected <R extends HasIdentifier> R operateOnEntity( | ||
| NameIdentifier ident, ThrowableFunction<NameIdentifier, R> fn, String opName, long id) { | ||
| R ret = null; | ||
| try { | ||
| ret = fn.apply(ident); | ||
| } catch (OptimisticLockException e) { | ||
|
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. Altitude: this special case depends on an unenforced fact about callers. The comment concedes
Contributor
Author
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. see above. |
||
| // Managed operations do not use this best-effort helper, so their conflicts still reach the | ||
| // caller. Here the external catalog was already changed and remains the source of truth; | ||
| // failing the request would encourage a retry that could apply the external change twice. | ||
| LOG.warn(FormattedErrorMessages.STORE_OP_FAILURE, opName, ident, e); | ||
| } catch (NoSuchEntityException e) { | ||
| // Case 2: The table is created by Gravitino, but has no corresponding entity in Gravitino. | ||
| LOG.error(FormattedErrorMessages.ENTITY_NOT_FOUND, ident); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,6 +51,7 @@ | |
| import org.apache.gravitino.exceptions.NoSuchEntityException; | ||
| import org.apache.gravitino.exceptions.NoSuchSchemaException; | ||
| import org.apache.gravitino.exceptions.NoSuchTableException; | ||
| import org.apache.gravitino.exceptions.OptimisticLockException; | ||
| import org.apache.gravitino.exceptions.TableAlreadyExistsException; | ||
| import org.apache.gravitino.lock.LockType; | ||
| import org.apache.gravitino.lock.TreeLockUtils; | ||
|
|
@@ -416,6 +417,8 @@ public boolean dropTable(NameIdentifier ident) { | |
| if (droppedFromCatalog) { | ||
| try { | ||
| store.delete(ident, TABLE); | ||
| } catch (OptimisticLockException e) { | ||
|
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. Correctness: concurrent-alter-vs-drop race can permanently orphan the internal table_meta row. Sequence: (1) Because the external table is already gone, a client retry of the same Contrast with
Contributor
Author
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. The sequence is real. I opened #12597 to handle it for every entity type instead of patching this one path. Two things pushed me that way. Removing the There is also a design question underneath: retrying the delete until it wins is close to not checking the version on that path at all, since delete is idempotent and a conflict only means the row moved on. #12597 lists that alongside a shared retry and an orphan-cleanup job. Note the block already documents that an out-of-band drop can leave a stale registration needing separate cleanup, so this is a new trigger for an accepted outcome rather than a new class of outcome. |
||
| throw e; | ||
| } catch (NoSuchEntityException e) { | ||
| LOG.warn("The table to be dropped does not exist in the store: {}", ident, e); | ||
| } catch (Exception e) { | ||
|
|
@@ -470,6 +473,8 @@ public boolean purgeTable(NameIdentifier ident) throws UnsupportedOperationExcep | |
| if (droppedFromCatalog) { | ||
| try { | ||
| store.delete(ident, TABLE); | ||
| } catch (OptimisticLockException e) { | ||
| throw e; | ||
| } catch (NoSuchEntityException e) { | ||
| LOG.warn("The table to be purged does not exist in the store: {}", ident, e); | ||
| } catch (Exception e) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.