diff --git a/fe/fe-core/src/main/java/org/apache/doris/planner/EsScanNode.java b/fe/fe-core/src/main/java/org/apache/doris/planner/EsScanNode.java index 36984bffe1ad82..7db0e002ce8250 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/planner/EsScanNode.java +++ b/fe/fe-core/src/main/java/org/apache/doris/planner/EsScanNode.java @@ -204,13 +204,14 @@ private List getShardLocations() throws UserException { String.join(",", unPartitionedIndices), String.join(",", partitionedIndices)); } - int beIndex = random.nextInt(backendList.size()); + int size = backendList.size(); + int beIndex = random.nextInt(size); List result = Lists.newArrayList(); for (EsShardPartitions indexState : selectedIndex) { for (List shardRouting : indexState.getShardRoutings().values()) { // get backends Set colocatedBes = Sets.newHashSet(); - int numBe = Math.min(3, backendMap.size()); + int numBe = Math.min(3, size); List shardAllocations = new ArrayList<>(); for (EsShardRouting item : shardRouting) { shardAllocations.add(EsTable.TRANSPORT_HTTP.equals(table.getTransport()) ? item.getHttpAddress() : item.getAddress()); @@ -224,7 +225,7 @@ private List getShardLocations() throws UserException { List candidateBeList = Lists.newArrayList(); if (usingRandomBackend) { for (int i = 0; i < numBe; ++i) { - candidateBeList.add(backendList.get(beIndex++ % numBe)); + candidateBeList.add(backendList.get(beIndex++ % size)); } } else { candidateBeList.addAll(colocatedBes);