This is an automated email from the ASF dual-hosted git repository.
wenjun pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git
The following commit(s) were added to refs/heads/dev by this push:
new 7266e3fe9c [Fix-17232][master] handle the problem that master nodes
gains the same slot id (#17233)
7266e3fe9c is described below
commit 7266e3fe9cbd741e6a5ee43021c6fcdfb604bf8b
Author: ZhongJinHacker <[email protected]>
AuthorDate: Thu Jun 5 23:41:40 2025 +0800
[Fix-17232][master] handle the problem that master nodes gains the same
slot id (#17233)
---
.../server/master/cluster/MasterSlotManager.java | 4 ++
.../master/cluster/MasterSlotManagerTest.java | 61 ++++++++++++++++++++++
2 files changed, 65 insertions(+)
diff --git
a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/cluster/MasterSlotManager.java
b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/cluster/MasterSlotManager.java
index 67660bd038..3c655f7991 100644
---
a/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/cluster/MasterSlotManager.java
+++
b/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/cluster/MasterSlotManager.java
@@ -20,6 +20,7 @@ package org.apache.dolphinscheduler.server.master.cluster;
import org.apache.dolphinscheduler.server.master.config.MasterConfig;
import java.util.List;
+import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
@@ -60,6 +61,9 @@ public class MasterSlotManager implements
IMasterSlotReBalancer {
@Override
public void doReBalance(List<MasterServerMetadata> normalMasterServers) {
+ normalMasterServers =
+
normalMasterServers.stream().sorted(MasterServerMetadata::compareTo).collect(Collectors.toList());
+
int tmpCurrentSlot = -1;
for (int i = 0; i < normalMasterServers.size(); i++) {
if
(normalMasterServers.get(i).getAddress().equals(masterConfig.getMasterAddress()))
{
diff --git
a/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/cluster/MasterSlotManagerTest.java
b/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/cluster/MasterSlotManagerTest.java
index 0b4f659ebc..c978baf7e9 100644
---
a/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/cluster/MasterSlotManagerTest.java
+++
b/dolphinscheduler-master/src/test/java/org/apache/dolphinscheduler/server/master/cluster/MasterSlotManagerTest.java
@@ -22,6 +22,9 @@ import static com.google.common.truth.Truth.assertThat;
import org.apache.dolphinscheduler.common.enums.ServerStatus;
import org.apache.dolphinscheduler.server.master.config.MasterConfig;
+import java.util.ArrayList;
+import java.util.List;
+
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -104,4 +107,62 @@ class MasterSlotManagerTest {
// After doReBalance, the total master slots should be 2
assertThat(masterSlotManager.getTotalMasterSlots()).isEqualTo(2);
}
+
+ @Test
+ void doReBalanceWithAscendingOrderAddress() {
+ final String IP_ORDER_1 = "127.0.0.1:8001";
+ final String IP_ORDER_2 = "127.0.0.1:8002";
+
+ masterConfig = new MasterConfig();
+ masterConfig.setMasterAddress(IP_ORDER_1);
+ MasterSlotManager tMasterSlotManager = new
MasterSlotManager(masterConfig);
+ MasterServerMetadata normalMasterServerMetadata01 =
MasterServerMetadata.builder()
+ .address(IP_ORDER_1)
+ .serverStatus(ServerStatus.NORMAL)
+ .build();
+
+ MasterServerMetadata normalMasterServerMetadata02 =
MasterServerMetadata.builder()
+ .address(IP_ORDER_2)
+ .serverStatus(ServerStatus.NORMAL)
+ .build();
+
+ List<MasterServerMetadata> normalMasterServers = new ArrayList<>();
+ // asc
+ normalMasterServers.add(normalMasterServerMetadata01);
+ normalMasterServers.add(normalMasterServerMetadata02);
+
+ tMasterSlotManager.doReBalance(normalMasterServers);
+
+ assertThat(tMasterSlotManager.getCurrentMasterSlot()).isEqualTo(0);
+ assertThat(tMasterSlotManager.getTotalMasterSlots()).isEqualTo(2);
+ }
+
+ @Test
+ void getNormalServersInAscendingOrder() {
+ final String IP_ORDER_1 = "127.0.0.1:8001";
+ final String IP_ORDER_2 = "127.0.0.1:8002";
+
+ masterConfig = new MasterConfig();
+ masterConfig.setMasterAddress(IP_ORDER_1);
+ MasterSlotManager tMasterSlotManager = new
MasterSlotManager(masterConfig);
+ MasterServerMetadata normalMasterServerMetadata01 =
MasterServerMetadata.builder()
+ .address(IP_ORDER_1)
+ .serverStatus(ServerStatus.NORMAL)
+ .build();
+
+ MasterServerMetadata normalMasterServerMetadata02 =
MasterServerMetadata.builder()
+ .address(IP_ORDER_2)
+ .serverStatus(ServerStatus.NORMAL)
+ .build();
+
+ List<MasterServerMetadata> normalMasterServers = new ArrayList<>();
+ // desc
+ normalMasterServers.add(normalMasterServerMetadata02);
+ normalMasterServers.add(normalMasterServerMetadata01);
+
+ tMasterSlotManager.doReBalance(normalMasterServers);
+
+ assertThat(tMasterSlotManager.getCurrentMasterSlot()).isEqualTo(0);
+ assertThat(tMasterSlotManager.getTotalMasterSlots()).isEqualTo(2);
+ }
}