github-actions[bot] commented on code in PR #62530:
URL: https://github.com/apache/doris/pull/62530#discussion_r3086739874


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/DropConstraintCommand.java:
##########
@@ -72,8 +75,14 @@ public void run(ConnectContext ctx, StmtExecutor executor) 
throws Exception {
                     + "falling back to name-based lookup: {}", name, 
e.getMessage());
             tableNameInfo = extractTableNameFromPlan(ctx);
         }
-        Env.getCurrentEnv().getConstraintManager().dropConstraint(
-                tableNameInfo, name, false);
+        Constraint constraint = 
Env.getCurrentEnv().getConstraintManager().getConstraint(tableNameInfo, name);
+        if (constraint == null) {
+            throw new AnalysisException(
+                    String.format("Unknown constraint %s on table %s.", name, 
tableNameInfo));
+        }
+        List<MTMV> dependentMtmvs = 
MTMVUtil.getDependentMtmvsByConstraint(tableNameInfo, constraint);
+        
Env.getCurrentEnv().getConstraintManager().dropConstraint(tableNameInfo, name, 
false);
+        MTMVUtil.invalidateRewriteCaches(dependentMtmvs);

Review Comment:
   `dropConstraint()` happens before `invalidateRewriteCaches()`, but 
`MTMV.getOrGenerateCache()` returns any already-built cache immediately. That 
leaves a window where another planner can observe the new constraint state in 
`ConstraintManager` while still reusing a rewrite cache built with the old 
PK/FK/UK metadata, so a `DROP CONSTRAINT` can still allow one stale rewrite. 
Can we make the constraint-state change and MTMV cache invalidation atomically 
visible to readers on the drop path?



##########
fe/fe-core/src/main/java/org/apache/doris/persist/EditLog.java:
##########
@@ -1200,38 +1202,32 @@ public static void loadJournal(Env env, Long logId, 
JournalEntity journal) {
                 }
                 case OperationType.OP_ADD_CONSTRAINT: {
                     final AlterConstraintLog log = (AlterConstraintLog) 
journal.getData();
-                    try {
-                        TableNameInfo tni = log.getTableNameInfo();
-                        Constraint constraint = log.getConstraint();
-                        if (tni == null) {
-                            LOG.warn("Failed to replay add constraint {}: "
-                                    + "table name could not be resolved",
-                                    constraint.getName());
-                            break;
-                        }
-                        env.getConstraintManager().addConstraint(
-                                tni, constraint.getName(), constraint, true);
-                    } catch (Exception e) {
-                        LOG.warn("Failed to replay add constraint", e);
+                    TableNameInfo tni = log.getTableNameInfo();
+                    Constraint constraint = log.getConstraint();
+                    if (tni == null) {
+                        LOG.warn("Skip replaying add constraint {} because 
table name could not be resolved",
+                                constraint.getName());
+                        break;
                     }
+                    List<MTMV> dependentMtmvs = 
MTMVUtil.getDependentMtmvsByConstraint(tni, constraint);
+                    env.getConstraintManager().addConstraint(
+                            tni, constraint.getName(), constraint, true);
+                    MTMVUtil.invalidateRewriteCaches(dependentMtmvs);
                     break;
                 }
                 case OperationType.OP_DROP_CONSTRAINT: {
                     final AlterConstraintLog log = (AlterConstraintLog) 
journal.getData();
-                    try {
-                        TableNameInfo tni = log.getTableNameInfo();
-                        Constraint constraint = log.getConstraint();
-                        if (tni == null) {
-                            LOG.warn("Failed to replay drop constraint {}: "
-                                    + "table name could not be resolved",
-                                    constraint.getName());
-                            break;
-                        }
-                        env.getConstraintManager().dropConstraint(
-                                tni, constraint.getName(), true);
-                    } catch (Exception e) {
-                        LOG.warn("Failed to replay drop constraint", e);
+                    TableNameInfo tni = log.getTableNameInfo();
+                    Constraint constraint = log.getConstraint();
+                    if (tni == null) {
+                        LOG.warn("Skip replaying drop constraint {} because 
table name could not be resolved",
+                                constraint.getName());
+                        break;
                     }
+                    List<MTMV> dependentMtmvs = 
MTMVUtil.getDependentMtmvsByConstraint(tni, constraint);
+                    env.getConstraintManager().dropConstraint(
+                            tni, constraint.getName(), true);
+                    MTMVUtil.invalidateRewriteCaches(dependentMtmvs);

Review Comment:
   The replay path has the same ordering issue as the live DDL path: the 
constraint is dropped first, then dependent MTMV caches are invalidated. If a 
cached MTMV is already present, `getOrGenerateCache()` can still hand out the 
old rewrite cache after replay has removed the constraint metadata, so replay 
can also preserve a stale rewrite for one more planning step.



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to