@@ -116,8 +116,9 @@ def find_target_node_and_empty_node(
116
116
117
117
# Get all node IDs from CLUSTER NODES section
118
118
all_nodes = set ()
119
- nodes_with_shards = set ()
120
- master_nodes = set ()
119
+ nodes_with_any_shards = set () # Nodes with shards from ANY database
120
+ nodes_with_target_db_shards = set () # Nodes with shards from target database
121
+ master_nodes = set () # Master nodes for target database only
121
122
122
123
for line in lines :
123
124
line = line .strip ()
@@ -146,21 +147,29 @@ def find_target_node_and_empty_node(
146
147
# Parse shard line: db:1 m-standard redis:1 node:2 master 0-8191 1.4MB OK
147
148
parts = line .split ()
148
149
if len (parts ) >= 5 :
150
+ db_id = parts [0 ] # db:1, db:2, etc.
149
151
node_id = parts [3 ] # node:2
150
152
shard_role = parts [4 ] # master/slave - this is what matters
151
153
152
- nodes_with_shards .add (node_id )
153
- if shard_role == "master" :
154
- master_nodes .add (node_id )
154
+ # Track ALL nodes with shards (for finding truly empty nodes)
155
+ nodes_with_any_shards .add (node_id )
156
+
157
+ # Only track master nodes for the specific database we're testing
158
+ bdb_id = endpoint_config .get ("bdb_id" )
159
+ if db_id == f"db:{ bdb_id } " :
160
+ nodes_with_target_db_shards .add (node_id )
161
+ if shard_role == "master" :
162
+ master_nodes .add (node_id )
155
163
elif line .startswith ("ENDPOINTS:" ) or not line :
156
164
shards_section_started = False
157
165
158
- # Find empty node (node with no shards)
159
- empty_nodes = all_nodes - nodes_with_shards
166
+ # Find empty node (node with no shards from ANY database )
167
+ empty_nodes = all_nodes - nodes_with_any_shards
160
168
161
169
logging .debug (f"All nodes: { all_nodes } " )
162
- logging .debug (f"Nodes with shards: { nodes_with_shards } " )
163
- logging .debug (f"Master nodes: { master_nodes } " )
170
+ logging .debug (f"Nodes with shards from any database: { nodes_with_any_shards } " )
171
+ logging .debug (f"Nodes with target database shards: { nodes_with_target_db_shards } " )
172
+ logging .debug (f"Master nodes (target database only): { master_nodes } " )
164
173
logging .debug (f"Empty nodes: { empty_nodes } " )
165
174
166
175
if not empty_nodes :
0 commit comments