Skip to content

Commit 260eb65

Browse files
committed
[Fix](load) fix commit txn timeout when loading to table with many tablet (apache#40031)
fix commit txn timeout when loading to table with many tablet
1 parent d6ee2ff commit 260eb65

File tree

2 files changed

+43
-24
lines changed

2 files changed

+43
-24
lines changed

fe/fe-core/src/main/java/org/apache/doris/load/BrokerFileGroup.java

+10-7
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,16 @@ public void parse(Database db, DataDescription dataDescription) throws DdlExcept
191191
}
192192
}
193193

194-
boolean isPartitionRestoring = olapTable.getPartitions().stream().anyMatch(
195-
partition -> partition.getState() == PartitionState.RESTORE
196-
);
197-
198-
// restore table
199-
if (!isPartitionRestoring && olapTable.getState() == OlapTableState.RESTORE) {
200-
throw new DdlException("Table [" + olapTable.getName() + "] is under restore");
194+
// only do check when here's restore on this table now
195+
if (olapTable.getState() == OlapTableState.RESTORE) {
196+
boolean hasPartitionRestoring = olapTable.getPartitions().stream()
197+
.anyMatch(partition -> partition.getState() == PartitionState.RESTORE);
198+
// tbl RESTORE && all partition NOT RESTORE -> whole table restore
199+
// tbl RESTORE && some partition RESTORE -> just partitions restore, NOT WHOLE TABLE
200+
// so check wether the whole table restore here
201+
if (!hasPartitionRestoring) {
202+
throw new DdlException("Table [" + olapTable.getName() + "] is under restore");
203+
}
201204
}
202205

203206
if (olapTable.getKeysType() != KeysType.AGG_KEYS && dataDescription.isNegative()) {

fe/fe-core/src/main/java/org/apache/doris/transaction/DatabaseTransactionMgr.java

+33-17
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,9 @@ private void checkCommitStatus(List<Table> tableList, TransactionState transacti
462462
List<Long> tabletIds = tabletCommitInfos.stream()
463463
.map(TabletCommitInfo::getTabletId).collect(Collectors.toList());
464464
List<TabletMeta> tabletMetaList = tabletInvertedIndex.getTabletMetaList(tabletIds);
465+
HashMap<Long, Boolean> tableIdtoRestoring = new HashMap<>();
465466
for (int i = 0; i < tabletMetaList.size(); i++) {
467+
// get partition and table of this tablet
466468
TabletMeta tabletMeta = tabletMetaList.get(i);
467469
if (tabletMeta == TabletInvertedIndex.NOT_EXIST_TABLET_META) {
468470
continue;
@@ -471,29 +473,43 @@ private void checkCommitStatus(List<Table> tableList, TransactionState transacti
471473
long tableId = tabletMeta.getTableId();
472474
OlapTable tbl = (OlapTable) idToTable.get(tableId);
473475
if (tbl == null) {
474-
// this can happen when tableId == -1 (tablet being dropping)
475-
// or table really not exist.
476+
// this can happen when tableId == -1 (tablet being dropping) or table really not exist.
476477
continue;
477478
}
478479

480+
// check relative partition restore here
479481
long partitionId = tabletMeta.getPartitionId();
480-
Partition partition = tbl.getPartition(partitionId);
481-
if (partition == null) {
482-
// this can happen when partitionId == -1 (tablet being dropping)
483-
// or partition really not exist.
482+
if (tbl.getPartition(partitionId) == null) {
483+
// this can happen when partitionId == -1 (tablet being dropping) or partition really not exist.
484484
continue;
485-
} else if (partition.getState() == PartitionState.RESTORE) {
486-
// partition which need load data
485+
}
486+
if (tbl.getPartition(partitionId).getState() == PartitionState.RESTORE) {
487+
// partition in restore process which can not load data
487488
throw new LoadException("Table [" + tbl.getName() + "], Partition ["
488-
+ partition.getName() + "] is in restore process. Can not load into it");
489-
}
490-
boolean isPartitionRestoring = tbl.getPartitions().stream().anyMatch(
491-
curPartition -> curPartition.getState() == PartitionState.RESTORE
492-
);
493-
// restore table
494-
if (!isPartitionRestoring && tbl.getState() == OlapTableState.RESTORE) {
495-
throw new LoadException("Table " + tbl.getName() + " is in restore process. "
496-
+ "Can not load into it");
489+
+ tbl.getPartition(partitionId).getName() + "] is in restore process. Can not load into it");
490+
}
491+
492+
// only do check when here's restore on this table now
493+
if (tbl.getState() == OlapTableState.RESTORE) {
494+
boolean hasPartitionRestoring = false;
495+
if (tableIdtoRestoring.containsKey(tableId)) {
496+
hasPartitionRestoring = tableIdtoRestoring.get(tableId);
497+
} else {
498+
for (Partition partition : tbl.getPartitions()) {
499+
if (partition.getState() == PartitionState.RESTORE) {
500+
hasPartitionRestoring = true;
501+
break;
502+
}
503+
}
504+
tableIdtoRestoring.put(tableId, hasPartitionRestoring);
505+
}
506+
// tbl RESTORE && all partition NOT RESTORE -> whole table restore
507+
// tbl RESTORE && some partition RESTORE -> just partitions restore, NOT WHOLE TABLE
508+
// so check wether the whole table restore here
509+
if (!hasPartitionRestoring) {
510+
throw new LoadException(
511+
"Table " + tbl.getName() + " is in restore process. " + "Can not load into it");
512+
}
497513
}
498514

499515
if (!tableToPartition.containsKey(tableId)) {

0 commit comments

Comments
 (0)