This is an automated email from the ASF dual-hosted git repository. haonan pushed a commit to branch fix_nodeUrls_shuffle_error in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit c926946a85bbd7f9c6110707ec43424420e9c433 Author: HTHou <[email protected]> AuthorDate: Tue Aug 12 15:39:09 2025 +0800 Fix nodeUrls shuffle error --- .../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 be5f3eefcbb..f9a00e8b8c5 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 @@ -433,7 +433,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; @@ -450,7 +450,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 { @@ -578,6 +578,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 1ea2fcf6f86..e4d2dbbb41d 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 @@ -105,6 +105,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")
