WEIGHT load balancer applies stale weights when read data sources are swapped

Author: thswlsqlsCreated Sep 29, 2026Updated Sep 29, 2026

Bug Report

Which version of ShardingSphere did you use?

master @ 28ee19118f9

Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?

Both (cluster mode)

Expected behavior

WEIGHT distributes reads by the configured weights of the available read data sources.

Actual behavior

When the available set changes to a different set of the same size, the previous set's weights are applied by position. With read_ds_0=1, read_ds_1=1, read_ds_2=8, routing [read_ds_0, read_ds_2] then [read_ds_0, read_ds_1] silently sends about 89% of reads to read_ds_1 instead of 50% until the list size changes again.

Reason analyze (If you can)

WeightLoadBalanceAlgorithm.getTargetName() reuses the cached cumulative weights per group whenever the cached array length equals availableTargetNames.size(). #21602 invalidated the cache only when the size changes; target names are not compared.

Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.

  1. Cluster mode, readwrite-splitting group with three read data sources and WEIGHT.
  2. Disable read_ds_1, run a read query.
  3. Enable read_ds_1 and disable read_ds_2 with no read on that group in between.
  4. read_ds_1 now receives read_ds_2's weight.

Example codes for reproduce this issue (such as a github link).

N/A