jerryshao commented on code in PR #12551:
URL: https://github.com/apache/gravitino/pull/12551#discussion_r3850866817


##########
core/src/main/java/org/apache/gravitino/storage/relational/service/TableMetaService.java:
##########
@@ -215,24 +219,35 @@ public <E extends Entity & HasIdentifier> TableEntity 
updateTable(
                       oldTablePO.getMetalakeId());
             }
           },
-          () ->
-              updateResult.set(
-                  SessionUtils.getWithoutCommit(
-                      TableMetaMapper.class,
-                      mapper -> ops.updatePO(mapper, newTablePO, oldTablePO))),
-          () ->
-              SessionUtils.doWithoutCommit(
-                  TableVersionMapper.class,
-                  mapper -> {
-                    mapper.softDeleteTableVersionByTableIdAndVersion(
-                        oldTablePO.getTableId(), 
oldTablePO.getCurrentVersion());
-                    mapper.insertTableVersionOnDuplicateKeyUpdate(newTablePO);
-                  }),
           () -> {
-            if (updateResult.get() > 0) {
-              TableColumnMetaService.getInstance()
-                  .updateColumnPOsFromTableDiff(oldTableEntity, 
newTableEntity, newTablePO);
+            // This update is the decision point for the whole transaction. 
current_version is the
+            // table's OCC token: if another writer changed the table after we 
read it, that writer
+            // has already increased the token and this UPDATE changes zero 
rows. Throwing here
+            // rolls back the transaction before it can touch the version 
history or columns.
+            int updated =
+                SessionUtils.getWithoutCommit(
+                    TableMetaMapper.class, mapper -> ops.updatePO(mapper, 
newTablePO, oldTablePO));
+            if (updated == 0) {
+              throw tableWriteFailure(identifier, oldTablePO);
             }
+          },
+          () -> {
+            // The table details live in table_version_info, while table_meta 
points to the current
+            // version. These two rows must move together. This step runs only 
after the table_meta
+            // CAS above succeeds, so a losing writer cannot overwrite the 
winner's version row.

Review Comment:
   Can you explain more about this behavior?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to