Skip to content

Commit

Permalink
[BugFix] Fix the issue of repeated migration of colocate tablets
Browse files Browse the repository at this point in the history
Signed-off-by: Jiao Mingye <mxdzs0612@gmail.com>
  • Loading branch information
mxdzs0612 committed Feb 11, 2025
1 parent d650aa8 commit f4c2177
Showing 1 changed file with 26 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,10 @@ private List<TabletSchedCtx> balanceClusterDisk(ClusterLoadStatistic clusterStat
continue;
}

if (!olapTable.needSchedule(false)) {
continue;
}

if (isDestBackendLocationMismatch(olapTable, hBackend.getId(), lBackend.getId(),
physicalPartition.getParentId(), tabletId)) {
continue;
Expand Down Expand Up @@ -742,8 +746,8 @@ private void balanceBackendDisk(TStorageMedium medium, double avgUsedPercent,
long destPathHash = pathStats.get(destPathIndex).getPathHash();

// (partition, index) => tabletIds
Map<Pair<Long, Long>, Set<Long>> srcPathPartitionTablets = getPartitionTablets(beId, medium, srcPathHash);
Map<Pair<Long, Long>, Set<Long>> destPathPartitionTablets = getPartitionTablets(beId, medium, destPathHash);
Map<Pair<Long, Long>, Set<Long>> srcPathPartitionTablets = getPartitionTablets(beId, medium, srcPathHash, true);
Map<Pair<Long, Long>, Set<Long>> destPathPartitionTablets = getPartitionTablets(beId, medium, destPathHash, true);
Map<Pair<Long, Long>, PartitionStat> partitionStats = getPartitionStats(medium, true, null, null);

boolean srcChanged = false;
Expand All @@ -755,13 +759,13 @@ private void balanceBackendDisk(TStorageMedium medium, double avgUsedPercent,
if (srcChanged) {
srcPathUsedCap = srcPathStat.getUsedCapacityB();
srcPathHash = srcPathStat.getPathHash();
srcPathPartitionTablets = getPartitionTablets(beId, medium, srcPathHash);
srcPathPartitionTablets = getPartitionTablets(beId, medium, srcPathHash, true);
srcChanged = false;
}
if (destChanged) {
destPathUsedCap = destPathStat.getUsedCapacityB();
destPathHash = destPathStat.getPathHash();
destPathPartitionTablets = getPartitionTablets(beId, medium, destPathHash);
destPathPartitionTablets = getPartitionTablets(beId, medium, destPathHash, true);
destChanged = false;
}

Expand Down Expand Up @@ -962,7 +966,8 @@ private boolean isTabletExistsInBackends(Long tabletId, List<Long> backends) {
/**
* @return map : (physical partition id, index) => tablets
*/
private Map<Pair<Long, Long>, Set<Long>> getPartitionTablets(long beId, TStorageMedium medium, long pathHash) {
private Map<Pair<Long, Long>, Set<Long>> getPartitionTablets(long beId, TStorageMedium medium, long pathHash,
boolean isLocalBalance) {
Map<Pair<Long, Long>, Set<Long>> partitionTablets = Maps.newHashMap();
List<Long> tabletIds =
GlobalStateMgr.getCurrentState().getTabletInvertedIndex().getTabletIdsByBackendIdAndStorageMedium(beId, medium);
Expand All @@ -984,6 +989,11 @@ private Map<Pair<Long, Long>, Set<Long>> getPartitionTablets(long beId, TStorage
}
}

OlapTable olapTable = getOlapTableById(tabletMeta.getDbId(), tabletMeta.getTableId());
if (olapTable != null && !olapTable.needSchedule(isLocalBalance)) {
continue;
}

Pair<Long, Long> key = new Pair<>(tabletMeta.getPhysicalPartitionId(), tabletMeta.getIndexId());
partitionTablets.computeIfAbsent(key, k -> Sets.newHashSet()).add(tabletId);
}
Expand Down Expand Up @@ -1465,6 +1475,16 @@ private List<Pair<Long, Set<Long>>> getPartitionTablets(Long dbId, Long tableId,
if (table == null) {
return result;
}
if (beIds != null) {
if (!table.needSchedule(true)) {
return result;
}
} else {
if (!table.needSchedule(false)) {
return result;
}
}

if (table.isCloudNativeTableOrMaterializedView()) {
// replicas are managed by StarOS and cloud storage.
return result;
Expand Down Expand Up @@ -1826,7 +1846,7 @@ private BackendBalanceState getBackendBalanceState(long backendId,
Map<Long, Integer> partitionReplicaCnt,
int backendCnt,
boolean sortPartition) {
Map<Pair<Long, Long>, Set<Long>> physicalPartitionTablets = getPartitionTablets(backendId, medium, -1L);
Map<Pair<Long, Long>, Set<Long>> physicalPartitionTablets = getPartitionTablets(backendId, medium, -1L, false);
Map<Pair<Long, Long>, List<Long>> partitionTabletList = new HashMap<>();
for (Map.Entry<Pair<Long, Long>, Set<Long>> entry : physicalPartitionTablets.entrySet()) {
partitionTabletList.put(entry.getKey(), new LinkedList<>(entry.getValue()));
Expand Down

0 comments on commit f4c2177

Please sign in to comment.