@@ -462,7 +462,9 @@ private void checkCommitStatus(List<Table> tableList, TransactionState transacti
462
462
List <Long > tabletIds = tabletCommitInfos .stream ()
463
463
.map (TabletCommitInfo ::getTabletId ).collect (Collectors .toList ());
464
464
List <TabletMeta > tabletMetaList = tabletInvertedIndex .getTabletMetaList (tabletIds );
465
+ HashMap <Long , Boolean > tableIdtoRestoring = new HashMap <>();
465
466
for (int i = 0 ; i < tabletMetaList .size (); i ++) {
467
+ // get partition and table of this tablet
466
468
TabletMeta tabletMeta = tabletMetaList .get (i );
467
469
if (tabletMeta == TabletInvertedIndex .NOT_EXIST_TABLET_META ) {
468
470
continue ;
@@ -471,29 +473,43 @@ private void checkCommitStatus(List<Table> tableList, TransactionState transacti
471
473
long tableId = tabletMeta .getTableId ();
472
474
OlapTable tbl = (OlapTable ) idToTable .get (tableId );
473
475
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.
476
477
continue ;
477
478
}
478
479
480
+ // check relative partition restore here
479
481
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.
484
484
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
487
488
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
+ }
497
513
}
498
514
499
515
if (!tableToPartition .containsKey (tableId )) {
0 commit comments