diff --git a/fe/fe-core/src/main/java/org/apache/doris/load/BrokerFileGroup.java b/fe/fe-core/src/main/java/org/apache/doris/load/BrokerFileGroup.java index 2b493eefb4573a..35bd0b8db7d9c6 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/load/BrokerFileGroup.java +++ b/fe/fe-core/src/main/java/org/apache/doris/load/BrokerFileGroup.java @@ -31,6 +31,7 @@ import org.apache.doris.catalog.OlapTable; import org.apache.doris.catalog.OlapTable.OlapTableState; import org.apache.doris.catalog.Partition; +import org.apache.doris.catalog.Partition.PartitionState; import org.apache.doris.catalog.Table; import org.apache.doris.common.AnalysisException; import org.apache.doris.common.DdlException; @@ -181,11 +182,21 @@ public void parse(Database db, DataDescription dataDescription) throws DdlExcept throw new DdlException("Unknown partition '" + pName + "' in table '" + olapTable.getName() + "'"); } + // partition which need load data + if (partition.getState() == PartitionState.RESTORE) { + throw new DdlException("Table [" + olapTable.getName() + + "], Partition[" + partition.getName() + "] is under restore"); + } partitionIds.add(partition.getId()); } } - if (olapTable.getState() == OlapTableState.RESTORE) { + boolean isPartitionRestoring = olapTable.getPartitions().stream().anyMatch( + partition -> partition.getState() == PartitionState.RESTORE + ); + + // restore table + if (!isPartitionRestoring && olapTable.getState() == OlapTableState.RESTORE) { throw new DdlException("Table [" + olapTable.getName() + "] is under restore"); } diff --git a/fe/fe-core/src/main/java/org/apache/doris/transaction/DatabaseTransactionMgr.java b/fe/fe-core/src/main/java/org/apache/doris/transaction/DatabaseTransactionMgr.java index d733d863f4e136..d99f9ba60f6efa 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/transaction/DatabaseTransactionMgr.java +++ b/fe/fe-core/src/main/java/org/apache/doris/transaction/DatabaseTransactionMgr.java @@ -22,7 +22,9 @@ import org.apache.doris.catalog.Env; import org.apache.doris.catalog.MaterializedIndex; import org.apache.doris.catalog.OlapTable; +import org.apache.doris.catalog.OlapTable.OlapTableState; import org.apache.doris.catalog.Partition; +import org.apache.doris.catalog.Partition.PartitionState; import org.apache.doris.catalog.PartitionInfo; import org.apache.doris.catalog.PartitionType; import org.apache.doris.catalog.Replica; @@ -474,16 +476,24 @@ private void checkCommitStatus(List tableList, TransactionState transacti continue; } - if (tbl.getState() == OlapTable.OlapTableState.RESTORE) { - throw new LoadException("Table " + tbl.getName() + " is in restore process. " - + "Can not load into it"); - } - long partitionId = tabletMeta.getPartitionId(); - if (tbl.getPartition(partitionId) == null) { + Partition partition = tbl.getPartition(partitionId); + if (partition == null) { // this can happen when partitionId == -1 (tablet being dropping) // or partition really not exist. continue; + } else if (partition.getState() == PartitionState.RESTORE) { + // partition which need load data + throw new LoadException("Table [" + tbl.getName() + "], Partition [" + + partition.getName() + "] is in restore process. Can not load into it"); + } + boolean isPartitionRestoring = tbl.getPartitions().stream().anyMatch( + curPartition -> curPartition.getState() == PartitionState.RESTORE + ); + // restore table + if (!isPartitionRestoring && tbl.getState() == OlapTableState.RESTORE) { + throw new LoadException("Table " + tbl.getName() + " is in restore process. " + + "Can not load into it"); } if (!tableToPartition.containsKey(tableId)) {