private void invalidateSchemaCacheOfOldLeaders() {
    BiConsumer<Map<TConsensusGroupId, Integer>, Set<TConsensusGroupId>> consumer =
        (oldLeaderMap, successTransferSet) -> {
          final DataNodeAsyncRequestContext<String, TSStatus> invalidateSchemaCacheRequestHandler =
              new DataNodeAsyncRequestContext<>(CnToDnAsyncRequestType.INVALIDATE_LAST_CACHE);
          final AtomicInteger requestIndex = new AtomicInteger(0);
          oldLeaderMap.entrySet().stream()
              .filter(entry -> successTransferSet.contains(entry.getKey()))
              .forEach(
                  entry -> {
                    // set target
                    final Integer dataNodeId = entry.getValue();
                    if (dataNodeId == -1) {
                      return;
                    }
                    final TDataNodeLocation dataNodeLocation =
                        getNodeManager().getRegisteredDataNode(dataNodeId).getLocation();
                    if (dataNodeLocation == null) {
                      LOGGER.warn("DataNodeLocation is null, datanodeId {}", dataNodeId);
                      return;
                    }
                    invalidateSchemaCacheRequestHandler.putNodeLocation(
                        requestIndex.get(), dataNodeLocation);
                    // set req
                    final TConsensusGroupId consensusGroupId = entry.getKey();
                    final String database =
                        getPartitionManager().getRegionDatabase(consensusGroupId);
                    invalidateSchemaCacheRequestHandler.putRequest(requestIndex.get(), database);
                    requestIndex.incrementAndGet();
                  });
          CnToDnInternalServiceAsyncRequestManager.getInstance()
              .sendAsyncRequest(invalidateSchemaCacheRequestHandler);
        };

    if (IS_ENABLE_AUTO_LEADER_BALANCE_FOR_DATA_REGION) {
      consumer.accept(lastDataRegion2OldLeaderMap, lastBalancedDataRegionSet);
    }
  }
Balance cluster RegionGroup leader distribution through configured algorithm.
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/manager/load/balancer/RouteBalancer.java