This is an automated email from the ASF dual-hosted git repository.
haonan pushed a commit to branch dev/1.3
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/dev/1.3 by this push:
new 08b31501fbf [To dev/1.3] Fix nodeUrls shuffle error (#16167)
08b31501fbf is described below
commit 08b31501fbfff3320454510783ebfa4404e63e9a
Author: Haonan <[email protected]>
AuthorDate: Wed Aug 13 19:00:55 2025 +0800
[To dev/1.3] Fix nodeUrls shuffle error (#16167)
---
.../src/main/java/org/apache/iotdb/session/Session.java | 14 ++++++++++++--
.../test/java/org/apache/iotdb/session/SessionTest.java | 12 ++++++++++++
2 files changed, 24 insertions(+), 2 deletions(-)
diff --git
a/iotdb-client/session/src/main/java/org/apache/iotdb/session/Session.java
b/iotdb-client/session/src/main/java/org/apache/iotdb/session/Session.java
index 61625d1c59e..d554c4c57a6 100644
--- a/iotdb-client/session/src/main/java/org/apache/iotdb/session/Session.java
+++ b/iotdb-client/session/src/main/java/org/apache/iotdb/session/Session.java
@@ -412,7 +412,7 @@ public class Session implements ISession {
if (nodeUrls.isEmpty()) {
throw new IllegalArgumentException("nodeUrls shouldn't be empty.");
}
- Collections.shuffle(nodeUrls);
+ nodeUrls = shuffleNodeUrls(nodeUrls);
this.nodeUrls = nodeUrls;
this.username = username;
this.password = password;
@@ -429,7 +429,7 @@ public class Session implements ISession {
if (builder.nodeUrls.isEmpty()) {
throw new IllegalArgumentException("nodeUrls shouldn't be empty.");
}
- Collections.shuffle(builder.nodeUrls);
+ builder.nodeUrls = shuffleNodeUrls(builder.nodeUrls);
this.nodeUrls = builder.nodeUrls;
this.enableQueryRedirection = true;
} else {
@@ -550,6 +550,16 @@ public class Session implements ISession {
});
}
+ private static List<String> shuffleNodeUrls(List<String> endPoints) {
+ try {
+ Collections.shuffle(endPoints);
+ } catch (UnsupportedOperationException e) {
+ endPoints = new ArrayList<>(endPoints);
+ Collections.shuffle(endPoints);
+ }
+ return endPoints;
+ }
+
private List<TEndPoint> getNodeUrls() {
if (defaultEndPoint != null) {
return Collections.singletonList(defaultEndPoint);
diff --git
a/iotdb-client/session/src/test/java/org/apache/iotdb/session/SessionTest.java
b/iotdb-client/session/src/test/java/org/apache/iotdb/session/SessionTest.java
index 4ecd3f436bb..7a377aeb90d 100644
---
a/iotdb-client/session/src/test/java/org/apache/iotdb/session/SessionTest.java
+++
b/iotdb-client/session/src/test/java/org/apache/iotdb/session/SessionTest.java
@@ -104,6 +104,18 @@ public class SessionTest {
.username("username")
.password("pwd")
.build();
+ session1 =
+ new Session.Builder()
+ .nodeUrls(Collections.nCopies(2, "host:port"))
+ .username("username")
+ .password("pwd")
+ .build();
+ session1 =
+ new Session.Builder()
+ .nodeUrls(Collections.unmodifiableList(Arrays.asList("host:port1",
"host:port2")))
+ .username("username")
+ .password("pwd")
+ .build();
session1 =
new Session.Builder()
.host("host")