Skip to content

[remove datanode] Load balancing for removing datanode#15022

Closed
HxpSerein wants to merge 4 commits intoapache:masterfrom
HxpSerein:load_balance
Closed

[remove datanode] Load balancing for removing datanode#15022
HxpSerein wants to merge 4 commits intoapache:masterfrom
HxpSerein:load_balance

Conversation

@HxpSerein
Copy link
Collaborator

@HxpSerein HxpSerein commented Mar 5, 2025

Description

Add region migration dest datanode selection algorithm for load balancing during removing datanode.

Please see https://apache-iotdb-project.feishu.cn/docx/G5aPdZJ4QozqmkxO9dsc7sEsnTe for detail design.

fakeToRealIdMap.keySet().stream()
.filter(fakeId -> !remainDataNodesFakeId.contains(fakeId))
.collect(Collectors.toSet());
return availableDataNodeMap.get(alternativeDataNodes.stream().findAny().orElse(null));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the meaning of get(null) ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

allocatedRegionGroups.remove(replicaSet);
List<TDataNodeLocation> dataNodeLocations = replicaSet.getDataNodeLocations();
dataNodeLocations.remove(replicaSetRemoved.get(replicaSet.getRegionId()));
replicaSet.setDataNodeLocations(dataNodeLocations);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to do this as you just remove it from replicaSet.getDataNodeLocations()

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now allocatedReplicaSets is HashSet, and the hash value of ReplicaSets will change. Removing, updating, and adding them is a safer approach

for (TRegionReplicaSet replicaSet : replicaSets) {
replicaSetRemoved.put(replicaSet.getRegionId(), dataNodeLocation);
}
migratedReplicas.addAll(replicaSets);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like it might repeat when we support removing multiple nodes in the future, right? Maybe we should use a set

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

.getClusterSchemaManager()
.getReplicationFactor(database, consensusGroupType);
} catch (DatabaseNotExistsException e) {
LOGGER.error(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use warn

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

allocatedRegionGroups.remove(remainReplicaSet);
List<TDataNodeLocation> dataNodeLocations = remainReplicaSet.getDataNodeLocations();
dataNodeLocations.add(selectedDestDataNode.getLocation());
remainReplicaSet.setDataNodeLocations(dataNodeLocations);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

Copy link
Collaborator Author

@HxpSerein HxpSerein Mar 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To ensure the correctness and readability of the code, it is recommended to retain the remove and add operations.

return regionMigrationPlans;
}

public List<RegionMigrationPlan> selectMigrationPlans(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe you can use gpt to refactor and improve the code here

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

break;
}
alternativeReplica[replicationFactor - 1] = dataNodeEntry.dataNodeId;
Pair<Integer, Integer> currentValue = valuation(alternativeReplica);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So should we consider the number of regions first instead of divergence?

Copy link
Collaborator Author

@HxpSerein HxpSerein Mar 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Such is the case. Only dataNodeEntries that meet the criteria of dataNodeEntry.freeDiskSpace == minFreeDiskSpace will be considered.

allocateResult.remove(remainReplicaSet);
List<TDataNodeLocation> dataNodeLocations = remainReplicaSet.getDataNodeLocations();
dataNodeLocations.add(selectedNode.getLocation());
remainReplicaSet.setDataNodeLocations(dataNodeLocations);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duplicated?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

List<TDataNodeLocation> dataNodeLocations = replicaSet.getDataNodeLocations();
allocateResult.remove(replicaSet);
dataNodeLocations.remove(REMOVE_DATANODE_LOCATION);
replicaSet.setDataNodeLocations(dataNodeLocations);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duplicated?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

selectedNodeIds.add(selectedNode.getLocation().getDataNodeId());
}

Assert.assertEquals(TEST_DATA_NODE_NUM - 1, selectedNodeIds.size());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we calculate how many new regions are added to each node, whether they are balanced, and so on? Otherwise this is a little bit broad at the moment?

maybe something like this
image

image

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added.

@HxpSerein HxpSerein deleted the load_balance branch September 21, 2025 09:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants