This is an automated email from the ASF dual-hosted git repository.
w41ter pushed a commit to branch branch-2.0
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-2.0 by this push:
new cab615f8023 [opt](binlog) Support drop view binlog #39781 (#44114)
cab615f8023 is described below
commit cab615f8023e12fd3239a7f18b14fe444965e520
Author: walter <[email protected]>
AuthorDate: Wed Nov 20 14:09:56 2024 +0800
[opt](binlog) Support drop view binlog #39781 (#44114)
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 | 15 ++++++++-------
.../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(+), 21 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 9e997da1c0a..52bcbb71ab8 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
@@ -935,7 +935,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 1db289dbaa9..709df8dfe57 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
@@ -2069,13 +2069,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 e78ef3334f1..a65c82f721e 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
@@ -916,23 +916,24 @@ public class InternalCatalog implements
CatalogIf<Database> {
}
}
- dropTableInternal(db, table, stmt.isForceDrop());
+ dropTableInternal(db, table, stmt.isView(), stmt.isForceDrop());
} catch (UserException e) {
throw new DdlException(e.getMessage(), e.getMysqlErrorCode());
} finally {
db.writeUnlock();
}
- LOG.info("finished dropping table: {} from db: {}, is force: {}",
tableName, dbName, stmt.isForceDrop());
+ LOG.info("finished dropping table: {} from db: {}, is view: {}, is
force: {}",
+ tableName, dbName, stmt.isView(), stmt.isForceDrop());
}
// 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);
+ dropTableInternal(db, table, isView, forceDrop);
} catch (Exception e) {
LOG.warn("drop table without check", e);
throw e;
@@ -942,7 +943,7 @@ public class InternalCatalog implements CatalogIf<Database>
{
}
// Drop a table, the db lock must hold.
- private void dropTableInternal(Database db, Table table, boolean
forceDrop) throws DdlException {
+ private void dropTableInternal(Database db, Table table, boolean isView,
boolean forceDrop) throws DdlException {
table.writeLock();
String tableName = table.getName();
long recycleTime = 0;
@@ -955,7 +956,7 @@ public class InternalCatalog implements CatalogIf<Database>
{
table.writeUnlock();
}
- 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().getQueryStats().clear(Env.getCurrentEnv().getCurrentCatalog().getId(),
db.getId(), table.getId());
@@ -2732,7 +2733,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 bad7011e872..54c12dfd046 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
@@ -336,7 +336,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]