diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/TabletInvertedIndex.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/TabletInvertedIndex.java index c4650cb5e0..5fd7ae721f 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/catalog/TabletInvertedIndex.java +++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/TabletInvertedIndex.java @@ -617,8 +617,19 @@ public class TabletInvertedIndex { "tablet " + tabletId + " not exists, backend " + backendId); if (replicaMetaTable.containsRow(tabletId)) { Replica replica = replicaMetaTable.remove(tabletId, backendId); - replicaToTabletMap.remove(replica.getId()); - replicaMetaTable.remove(tabletId, backendId); + + // sometimes, replicas may have same replica id in different backend + // we need to cover this situation to avoid some "replica not found" issue + if (replicaMetaTable.containsRow(tabletId)) { + long replicaNum = replicaMetaTable.row(tabletId).values().stream() + .filter(c -> c.getId() == replica.getId()).count(); + if (replicaNum == 0) { + replicaToTabletMap.remove(replica.getId()); + } + } else { + replicaToTabletMap.remove(replica.getId()); + } + backingReplicaMetaTable.remove(backendId, tabletId); if (LOG.isDebugEnabled()) { LOG.debug("delete replica {} of tablet {} in backend {}",