Skip to content

Commit

Permalink
[BugFix] Fix balance cause schema change failed bug (#17404)
Browse files Browse the repository at this point in the history
  • Loading branch information
gengjun-git authored Oct 12, 2023
1 parent d64127f commit fd39cfc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1379,6 +1379,12 @@ private Map<Pair<Long, Long>, PartitionStat> getPartitionStats(TStorageMedium me
}

OlapTable olapTbl = (OlapTable) table;
// Table not in NORMAL state is not allowed to do balance,
// because the change of tablet location can cause Schema change or rollup failed
if (olapTbl.getState() != OlapTable.OlapTableState.NORMAL) {
continue;
}

for (Partition partition : catalog.getAllPartitionsIncludeRecycleBin(olapTbl)) {
if (partition.getState() != PartitionState.NORMAL) {
// when alter job is in FINISHING state, partition state will be set to NORMAL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ public void testBalance(@Mocked Catalog catalog) {
Assert.assertTrue(tablets.stream().allMatch(t -> (t.getDestBackendId() == beId3)));
Assert.assertTrue(tablets.stream().anyMatch(t -> (t.getSrcBackendId() == beId1)));
Assert.assertTrue(tablets.stream().anyMatch(t -> (t.getSrcBackendId() == beId2)));

// set table state to schema_change, balance should be ignored
table.setState(OlapTable.OlapTableState.SCHEMA_CHANGE);
Assert.assertEquals(0, rebalancer.selectAlternativeTablets().size());
}

/**
Expand Down Expand Up @@ -518,6 +522,10 @@ public void testBalanceBackendTablet(@Mocked Catalog catalog) {
Assert.assertTrue(tablets.stream().anyMatch(t -> (t.getDestPathHash() == pathHash14)));
Assert.assertTrue(tablets.stream().anyMatch(t -> (t.getSrcPathHash() == pathHash10)));
Assert.assertTrue(tablets.stream().anyMatch(t -> (t.getSrcPathHash() == pathHash13)));

// set table state to schema_change, balance should be ignored
table.setState(OlapTable.OlapTableState.SCHEMA_CHANGE);
Assert.assertEquals(0, rebalancer.selectAlternativeTablets().size());
}

private Backend genBackend(long beId, String host, long availableCapB, long dataUsedCapB, long totalCapB,
Expand Down

0 comments on commit fd39cfc

Please sign in to comment.