This is an automated email from the ASF dual-hosted git repository.

w41ter pushed a commit to branch branch-2.1
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-2.1 by this push:
     new c3dc1863bd7 [opt](binlog) Support drop view binlog #39781 (#44113)
c3dc1863bd7 is described below

commit c3dc1863bd7d425fa6cf0166adce46ab86435903
Author: walter <[email protected]>
AuthorDate: Tue Nov 19 10:41:34 2024 +0800

    [opt](binlog) Support drop view binlog #39781 (#44113)
    
    cherry pick from #39781
    
    Co-authored-by: smallx <[email protected]>
---
 .../org/apache/doris/alter/MaterializedViewHandler.java  |  2 +-
 .../main/java/org/apache/doris/backup/RestoreJob.java    |  6 ++++--
 .../java/org/apache/doris/binlog/DropTableRecord.java    |  7 ++++++-
 .../org/apache/doris/datasource/InternalCatalog.java     | 16 ++++++++--------
 .../src/main/java/org/apache/doris/persist/DropInfo.java | 16 ++++++++++++----
 .../src/main/java/org/apache/doris/persist/EditLog.java  |  2 +-
 .../org/apache/doris/persist/DropAndRecoverInfoTest.java | 10 +++++-----
 7 files changed, 37 insertions(+), 22 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/alter/MaterializedViewHandler.java 
b/fe/fe-core/src/main/java/org/apache/doris/alter/MaterializedViewHandler.java
index 41b14268136..1ed38748e18 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/alter/MaterializedViewHandler.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/alter/MaterializedViewHandler.java
@@ -951,7 +951,7 @@ public class MaterializedViewHandler extends AlterHandler {
             // Step3: log drop mv operation
             EditLog editLog = Env.getCurrentEnv().getEditLog();
             editLog.logDropRollup(
-                    new DropInfo(db.getId(), olapTable.getId(), 
olapTable.getName(), mvIndexId, false, 0));
+                    new DropInfo(db.getId(), olapTable.getId(), 
olapTable.getName(), mvIndexId, false, false, 0));
             LOG.info("finished drop materialized view [{}] in table [{}]", 
mvName, olapTable.getName());
         } catch (MetaNotFoundException e) {
             if (dropMaterializedViewStmt.isIfExists()) {
diff --git a/fe/fe-core/src/main/java/org/apache/doris/backup/RestoreJob.java 
b/fe/fe-core/src/main/java/org/apache/doris/backup/RestoreJob.java
index cc7cb86f645..c59bebbce7e 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/backup/RestoreJob.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/backup/RestoreJob.java
@@ -2114,13 +2114,15 @@ public class RestoreJob extends AbstractJob {
                     } else if (isCleanTables) {
                         // otherwise drop the entire table.
                         LOG.info("drop non restored table {}, table id: {}. 
{}", tableName, tableId, this);
+                        boolean isView = false;
                         boolean isForceDrop = false; // move this table into 
recyclebin.
-                        env.getInternalCatalog().dropTableWithoutCheck(db, 
table, isForceDrop);
+                        env.getInternalCatalog().dropTableWithoutCheck(db, 
table, isView, isForceDrop);
                     }
                 } else if (tableType == TableType.VIEW && isCleanTables && 
!restoredViews.contains(tableName)) {
                     LOG.info("drop non restored view {}, table id: {}. {}", 
tableName, tableId, this);
+                    boolean isView = false;
                     boolean isForceDrop = false; // move this view into 
recyclebin.
-                    env.getInternalCatalog().dropTableWithoutCheck(db, table, 
isForceDrop);
+                    env.getInternalCatalog().dropTableWithoutCheck(db, table, 
isView, isForceDrop);
                 }
             }
             return Status.OK;
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/binlog/DropTableRecord.java 
b/fe/fe-core/src/main/java/org/apache/doris/binlog/DropTableRecord.java
index 4417edeb973..c998f2e73fe 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/binlog/DropTableRecord.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/binlog/DropTableRecord.java
@@ -31,6 +31,8 @@ public class DropTableRecord {
     private long tableId;
     @SerializedName(value = "tableName")
     private String tableName;
+    @SerializedName(value = "isView")
+    private boolean isView = false;
     @SerializedName(value = "rawSql")
     private String rawSql;
 
@@ -39,7 +41,10 @@ public class DropTableRecord {
         this.dbId = info.getDbId();
         this.tableId = info.getTableId();
         this.tableName = info.getTableName();
-        this.rawSql = String.format("DROP TABLE IF EXISTS `%s`", 
this.tableName);
+        this.isView = info.isView();
+        this.rawSql = info.isView()
+            ? String.format("DROP VIEW IF EXISTS `%s`", this.tableName)
+            : String.format("DROP TABLE IF EXISTS `%s`", this.tableName);
     }
 
     public long getCommitSeq() {
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java 
b/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java
index 34475596c35..7916a4bf976 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java
@@ -912,7 +912,7 @@ public class InternalCatalog implements CatalogIf<Database> 
{
                 }
             }
 
-            dropTableInternal(db, table, stmt.isForceDrop(), watch, costTimes);
+            dropTableInternal(db, table, stmt.isView(), stmt.isForceDrop(), 
watch, costTimes);
         } catch (UserException e) {
             throw new DdlException(e.getMessage(), e.getMysqlErrorCode());
         } finally {
@@ -920,18 +920,18 @@ public class InternalCatalog implements 
CatalogIf<Database> {
         }
         watch.stop();
         costTimes.put("6:total", watch.getTime());
-        LOG.info("finished dropping table: {} from db: {}, is force: {} cost: 
{}",
-                tableName, dbName, stmt.isForceDrop(), costTimes);
+        LOG.info("finished dropping table: {} from db: {}, is view: {}, is 
force: {}, cost: {}",
+                tableName, dbName, stmt.isView(), stmt.isForceDrop(), 
costTimes);
     }
 
     // drop table without any check.
-    public void dropTableWithoutCheck(Database db, Table table, boolean 
forceDrop) throws DdlException {
+    public void dropTableWithoutCheck(Database db, Table table, boolean 
isView, boolean forceDrop) throws DdlException {
         if (!db.writeLockIfExist()) {
             return;
         }
         try {
             LOG.info("drop table {} without check, force: {}", 
table.getQualifiedName(), forceDrop);
-            dropTableInternal(db, table, forceDrop, null, null);
+            dropTableInternal(db, table, isView, forceDrop, null, null);
         } catch (Exception e) {
             LOG.warn("drop table without check", e);
             throw e;
@@ -941,7 +941,7 @@ public class InternalCatalog implements CatalogIf<Database> 
{
     }
 
     // Drop a table, the db lock must hold.
-    private void dropTableInternal(Database db, Table table, boolean forceDrop,
+    private void dropTableInternal(Database db, Table table, boolean isView, 
boolean forceDrop,
             StopWatch watch, Map<String, Long> costTimes) throws DdlException {
         table.writeLock();
         String tableName = table.getName();
@@ -972,7 +972,7 @@ public class InternalCatalog implements CatalogIf<Database> 
{
 
         
Env.getCurrentEnv().getQueryStats().clear(Env.getCurrentEnv().getCurrentCatalog().getId(),
                 db.getId(), table.getId());
-        DropInfo info = new DropInfo(db.getId(), table.getId(), tableName, 
-1L, forceDrop, recycleTime);
+        DropInfo info = new DropInfo(db.getId(), table.getId(), tableName, 
-1L, isView, forceDrop, recycleTime);
         Env.getCurrentEnv().getEditLog().logDropTable(info);
         Env.getCurrentEnv().getMtmvService().dropTable(table);
     }
@@ -2986,7 +2986,7 @@ public class InternalCatalog implements 
CatalogIf<Database> {
             try {
                 dropTable(db, tableId, true, false, 0L);
                 if (hadLogEditCreateTable) {
-                    DropInfo info = new DropInfo(db.getId(), tableId, 
olapTable.getName(), -1L, true, 0L);
+                    DropInfo info = new DropInfo(db.getId(), tableId, 
olapTable.getName(), -1L, false, true, 0L);
                     Env.getCurrentEnv().getEditLog().logDropTable(info);
                 }
             } catch (Exception ex) {
diff --git a/fe/fe-core/src/main/java/org/apache/doris/persist/DropInfo.java 
b/fe/fe-core/src/main/java/org/apache/doris/persist/DropInfo.java
index b30522e9425..461f3ddd67d 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/persist/DropInfo.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/persist/DropInfo.java
@@ -38,6 +38,8 @@ public class DropInfo implements Writable {
     private String tableName; // not used in equals and hashCode
     @SerializedName(value = "indexId")
     private long indexId;
+    @SerializedName(value = "isView")
+    private boolean isView = false;
     @SerializedName(value = "forceDrop")
     private boolean forceDrop = false;
     @SerializedName(value = "recycleTime")
@@ -46,11 +48,13 @@ public class DropInfo implements Writable {
     public DropInfo() {
     }
 
-    public DropInfo(long dbId, long tableId, String tableName, long indexId, 
boolean forceDrop, long recycleTime) {
+    public DropInfo(long dbId, long tableId, String tableName, long indexId, 
boolean isView, boolean forceDrop,
+                    long recycleTime) {
         this.dbId = dbId;
         this.tableId = tableId;
         this.tableName = tableName;
         this.indexId = indexId;
+        this.isView = isView;
         this.forceDrop = forceDrop;
         this.recycleTime = recycleTime;
     }
@@ -71,12 +75,16 @@ public class DropInfo implements Writable {
         return this.indexId;
     }
 
+    public boolean isView() {
+        return this.isView;
+    }
+
     public boolean isForceDrop() {
-        return forceDrop;
+        return this.forceDrop;
     }
 
     public Long getRecycleTime() {
-        return recycleTime;
+        return this.recycleTime;
     }
 
     @Override
@@ -119,7 +127,7 @@ public class DropInfo implements Writable {
         DropInfo info = (DropInfo) obj;
 
         return (dbId == info.dbId) && (tableId == info.tableId) && (indexId == 
info.indexId)
-                && (forceDrop == info.forceDrop) && (recycleTime == 
info.recycleTime);
+                && (isView == info.isView) && (forceDrop == info.forceDrop) && 
(recycleTime == info.recycleTime);
     }
 
     public String toJson() {
diff --git a/fe/fe-core/src/main/java/org/apache/doris/persist/EditLog.java 
b/fe/fe-core/src/main/java/org/apache/doris/persist/EditLog.java
index afb7fad4e23..7ad196178d6 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/persist/EditLog.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/persist/EditLog.java
@@ -342,7 +342,7 @@ public class EditLog {
                     for (long indexId : batchDropInfo.getIndexIdSet()) {
                         env.getMaterializedViewHandler().replayDropRollup(
                                 new DropInfo(batchDropInfo.getDbId(), 
batchDropInfo.getTableId(),
-                                        batchDropInfo.getTableName(), indexId, 
false, 0),
+                                        batchDropInfo.getTableName(), indexId, 
false, false, 0),
                                 env);
                     }
                     break;
diff --git 
a/fe/fe-core/src/test/java/org/apache/doris/persist/DropAndRecoverInfoTest.java 
b/fe/fe-core/src/test/java/org/apache/doris/persist/DropAndRecoverInfoTest.java
index bdaab002c53..88aa22ded22 100644
--- 
a/fe/fe-core/src/test/java/org/apache/doris/persist/DropAndRecoverInfoTest.java
+++ 
b/fe/fe-core/src/test/java/org/apache/doris/persist/DropAndRecoverInfoTest.java
@@ -44,7 +44,7 @@ public class DropAndRecoverInfoTest {
         DropInfo info1 = new DropInfo();
         info1.write(dos);
 
-        DropInfo info2 = new DropInfo(1, 2, "t2", -1, true, 0);
+        DropInfo info2 = new DropInfo(1, 2, "t2", -1, false, true, 0);
         info2.write(dos);
 
         dos.flush();
@@ -65,10 +65,10 @@ public class DropAndRecoverInfoTest {
 
         Assert.assertEquals(rInfo2, rInfo2);
         Assert.assertNotEquals(rInfo2, this);
-        Assert.assertNotEquals(info2, new DropInfo(0, 2, "t2", -1L, true, 0));
-        Assert.assertNotEquals(info2, new DropInfo(1, 0, "t0", -1L, true, 0));
-        Assert.assertNotEquals(info2, new DropInfo(1, 2, "t2", -1L, false, 0));
-        Assert.assertEquals(info2, new DropInfo(1, 2, "t2", -1L, true, 0));
+        Assert.assertNotEquals(info2, new DropInfo(0, 2, "t2", -1L, false, 
true, 0));
+        Assert.assertNotEquals(info2, new DropInfo(1, 0, "t0", -1L, false, 
true, 0));
+        Assert.assertNotEquals(info2, new DropInfo(1, 2, "t2", -1L, false, 
false, 0));
+        Assert.assertEquals(info2, new DropInfo(1, 2, "t2", -1L, false, true, 
0));
 
         // 3. delete files
         dis.close();


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

Reply via email to