From ff47dc750d7270b968980e19d89f195d1d812ff7 Mon Sep 17 00:00:00 2001 From: caiconghui <55968745+caiconghui@users.noreply.github.com> Date: Fri, 18 Jun 2021 10:50:47 +0800 Subject: [PATCH] [Bug] Fix problem for thread safety issues and setting the status of non-existent replica does not prompt any error message (#6019) Co-authored-by: caiconghui --- .../org/apache/doris/catalog/Catalog.java | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-) 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 9304161a8a..9782be6318 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 @@ -6709,12 +6709,13 @@ public class Catalog { if (db == null) { continue; } - db.writeLock(); + OlapTable tbl = (OlapTable) db.getTable(info.getTableId()); + if (tbl == null) { + continue; + } + tbl.writeLock(); try { - OlapTable tbl = (OlapTable) db.getTable(info.getTableId()); - if (tbl == null) { - continue; - } + Partition partition = tbl.getPartition(info.getPartitionId()); if (partition == null) { continue; @@ -6734,7 +6735,7 @@ public class Catalog { info.getReplicaId(), info.getTabletId(), info.getBackendId()); } } finally { - db.writeUnlock(); + tbl.writeUnlock(); } } } @@ -6874,7 +6875,7 @@ public class Catalog { } // Set specified replica's status. If replica does not exist, just ignore it. - public void setReplicaStatus(AdminSetReplicaStatusStmt stmt) { + public void setReplicaStatus(AdminSetReplicaStatusStmt stmt) throws MetaNotFoundException { long tabletId = stmt.getTabletId(); long backendId = stmt.getBackendId(); ReplicaStatus status = stmt.getStatus(); @@ -6882,33 +6883,33 @@ public class Catalog { } public void replaySetReplicaStatus(SetReplicaStatusOperationLog log) { - setReplicaStatusInternal(log.getTabletId(), log.getBackendId(), log.getReplicaStatus(), true); + try { + setReplicaStatusInternal(log.getTabletId(), log.getBackendId(), log.getReplicaStatus(), true); + } catch (MetaNotFoundException e) { + LOG.warn("replay setReplicaStatus failed", e); + } } - private void setReplicaStatusInternal(long tabletId, long backendId, ReplicaStatus status, boolean isReplay) { + private void setReplicaStatusInternal(long tabletId, long backendId, ReplicaStatus status, boolean isReplay) throws MetaNotFoundException { TabletMeta meta = tabletInvertedIndex.getTabletMeta(tabletId); if (meta == null) { - LOG.info("tablet {} does not exist", tabletId); - return; + throw new MetaNotFoundException(String.format("tablet %d does not exist", tabletId)); } long dbId = meta.getDbId(); Database db = getDb(dbId); if (db == null) { - LOG.info("tablet {} in database does not exist", tabletId, dbId); - return; + throw new MetaNotFoundException(String.format("tablet %d in database %d does not exist", tabletId, dbId)); } long tableId = meta.getTableId(); Table table = db.getTable(tableId); if (table == null) { - LOG.info("tablet {} of table {} in database {} does not exist", tabletId, tableId, dbId); - return; + throw new MetaNotFoundException(String.format("tablet %d of table %d in database %d does not exist", tabletId, tableId, dbId)); } table.writeLock(); try { Replica replica = tabletInvertedIndex.getReplica(tabletId, backendId); if (replica == null) { - LOG.info("replica of tablet {} does not exist", tabletId); - return; + throw new MetaNotFoundException(String.format("replica of tablet %d on backend %d does not exist", tabletId, backendId)); } if (status == ReplicaStatus.BAD || status == ReplicaStatus.OK) { if (replica.setBad(status == ReplicaStatus.BAD)) {