private int computeDatabaseLoadSquaredSum(
      int[] currentAssignment,
      List<TConsensusGroupId> regionKeys,
      Map<TConsensusGroupId, String> regionDatabaseMap) {
    Map<String, int[]> extraLoadPerDb = new HashMap<>();
    // Initialize extra load counters for each database using the number of nodes from
    // regionCounter.
    for (String db : initialDbLoad.keySet()) {
      extraLoadPerDb.put(db, new int[regionCounter.length]);
    }
    // Accumulate extra load per database based on the current assignment.
    for (int i = 0; i < regionKeys.size(); i++) {
      TConsensusGroupId regionId = regionKeys.get(i);
      String db = regionDatabaseMap.get(regionId);
      int nodeId = currentAssignment[i];
      extraLoadPerDb.get(db)[nodeId]++;
    }
    int sumSquared = 0;
    // For each database, compute the maximum load across nodes and add its square to the sum.
    for (String db : initialDbLoad.keySet()) {
      int[] initLoads = initialDbLoad.get(db);
      int[] extras = extraLoadPerDb.get(db);
      int maxLoad = 0;
      for (int nodeId = 0; nodeId < regionCounter.length; nodeId++) {
        int load = initLoads[nodeId] + extras[nodeId];
        if (load > maxLoad) {
          maxLoad = load;
        }
      }
      sumSquared += maxLoad * maxLoad;
    }
    return sumSquared;
  }
Computes the squared sum of the maximum load for each database.

<p>For each database, this method calculates the maximum load on any data node by summing the
initial load (from {@code initialDbLoad}) with the additional load assigned during migration
(accumulated in {@code currentAssignment}), and then squares this maximum load. Finally, it
returns the sum of these squared maximum loads across all databases.

@param currentAssignment an array where each element is the nodeId assigned for the
    corresponding region in {@code regionKeys}.
@param regionKeys a list of region identifiers (TConsensusGroupId) representing the regions
    under migration.
@param regionDatabaseMap a mapping from each region identifier to its corresponding database
    name.
@return the sum of the squares of the maximum loads computed for each database.
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/load/balancer/region/GreedyCopySetRegionGroupAllocator.java