You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by ca...@apache.org on 2021/09/24 11:25:53 UTC
[incubator-doris] 05/05: fix
This is an automated email from the ASF dual-hosted git repository.
caiconghui pushed a commit to branch writeLock
in repository https://gitbox.apache.org/repos/asf/incubator-doris.git
commit 69d93ec45f54244c09523cb36a3f5d22870a0cb2
Author: caiconghui <ca...@163.com>
AuthorDate: Fri Sep 24 19:25:23 2021 +0800
fix
---
.../main/java/org/apache/doris/alter/Alter.java | 9 ++++++--
.../java/org/apache/doris/backup/RestoreJob.java | 26 ++++++++++++++--------
.../java/org/apache/doris/catalog/Catalog.java | 2 +-
.../java/org/apache/doris/catalog/Database.java | 9 --------
4 files changed, 25 insertions(+), 21 deletions(-)
diff --git a/fe/fe-core/src/main/java/org/apache/doris/alter/Alter.java b/fe/fe-core/src/main/java/org/apache/doris/alter/Alter.java
index 542acdd..f59e7c8 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/alter/Alter.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/alter/Alter.java
@@ -54,6 +54,7 @@ import org.apache.doris.common.DdlException;
import org.apache.doris.common.MetaNotFoundException;
import org.apache.doris.common.UserException;
import org.apache.doris.common.util.DynamicPartitionUtil;
+import org.apache.doris.common.util.MetaLockUtils;
import org.apache.doris.common.util.PropertyAnalyzer;
import org.apache.doris.persist.AlterViewInfo;
import org.apache.doris.persist.BatchModifyPartitionsInfo;
@@ -71,6 +72,7 @@ import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import java.util.Arrays;
+import java.util.Comparator;
import java.util.List;
import java.util.Map;
@@ -360,7 +362,9 @@ public class Alter {
try {
Table newTbl = db.getTableOrMetaException(newTblName, TableType.OLAP);
OlapTable olapNewTbl = (OlapTable) newTbl;
- origTable.writeLock();
+ List<Table> tableList = Lists.newArrayList(origTable, newTbl);
+ tableList.sort((Comparator.comparing(Table::getId)));
+ MetaLockUtils.writeLockTables(tableList);
try {
String oldTblName = origTable.getName();
// First, we need to check whether the table to be operated on can be renamed
@@ -374,7 +378,7 @@ public class Alter {
Catalog.getCurrentCatalog().getEditLog().logReplaceTable(log);
LOG.info("finish replacing table {} with table {}, is swap: {}", oldTblName, newTblName, swapTable);
} finally {
- origTable.writeUnlock();
+ MetaLockUtils.writeUnlockTables(tableList);
}
} finally {
db.writeUnlock();
@@ -433,6 +437,7 @@ public class Alter {
} else {
// not swap, the origin table is not used anymore, need to drop all its tablets.
Catalog.getCurrentCatalog().onEraseOlapTable(origTable, isReplay);
+ origTable.markDropped();
}
}
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 7614200..cc1b73a 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
@@ -1558,22 +1558,30 @@ public class RestoreJob extends AbstractJob {
// remove restored tbls
for (Table restoreTbl : restoredTbls) {
LOG.info("remove restored table when cancelled: {}", restoreTbl.getName());
- if (restoreTbl.getType() == TableType.OLAP) {
- OlapTable restoreOlapTable = (OlapTable) restoreTbl;
- restoreOlapTable.writeLock();
+ if (db.writeLockIfExist()) {
try {
- for (Partition part : restoreOlapTable.getPartitions()) {
- for (MaterializedIndex idx : part.getMaterializedIndices(IndexExtState.VISIBLE)) {
- for (Tablet tablet : idx.getTablets()) {
- Catalog.getCurrentInvertedIndex().deleteTablet(tablet.getId());
+ if (restoreTbl.getType() == TableType.OLAP) {
+ OlapTable restoreOlapTable = (OlapTable) restoreTbl;
+ restoreOlapTable.writeLock();
+ try {
+ for (Partition part : restoreOlapTable.getPartitions()) {
+ for (MaterializedIndex idx : part.getMaterializedIndices(IndexExtState.VISIBLE)) {
+ for (Tablet tablet : idx.getTablets()) {
+ Catalog.getCurrentInvertedIndex().deleteTablet(tablet.getId());
+ }
+ }
}
+ db.dropTable(restoreTbl.getName());
+ restoreTbl.markDropped();
+ } finally {
+ restoreTbl.writeUnlock();
}
}
} finally {
- restoreTbl.writeUnlock();
+ db.writeUnlock();
}
}
- db.dropTableWithLock(restoreTbl.getName());
+
}
// remove restored partitions
diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/Catalog.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/Catalog.java
index ca8fbfd..ee93261 100755
--- a/fe/fe-core/src/main/java/org/apache/doris/catalog/Catalog.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/Catalog.java
@@ -2859,10 +2859,10 @@ public class Catalog {
// log
RecoverInfo recoverInfo = new RecoverInfo(db.getId(), -1L, -1L);
editLog.logRecoverDb(recoverInfo);
+ db.unmarkDropped();
for (Table table : db.getTables()) {
table.unmarkDropped();
}
- db.unmarkDropped();
} finally {
unlock();
}
diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/Database.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/Database.java
index a370013..6a30c6d 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/catalog/Database.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/Database.java
@@ -373,15 +373,6 @@ public class Database extends MetaObject implements Writable {
return result;
}
- public void dropTableWithLock(String tableName) {
- writeLock();
- try {
- dropTable(tableName);
- } finally {
- writeUnlock();
- }
- }
-
public void dropTable(String tableName) {
if (Catalog.isStoredTableNamesLowerCase()) {
tableName = tableName.toLowerCase();
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org