@@ -88,13 +88,17 @@ cluster_node *get_redis_connection(redis_con *con,str *key)
88
88
unsigned short hash_slot ;
89
89
cluster_node * it ;
90
90
91
- if (con -> flags & REDIS_SINGLE_INSTANCE )
91
+ if (con -> flags & REDIS_SINGLE_INSTANCE ) {
92
+ LM_DBG ("Single redis connection, returning %p\n" ,con -> nodes );
92
93
return con -> nodes ;
93
- else {
94
+ } else {
94
95
hash_slot = redisHash (con , key );
95
96
for (it = con -> nodes ;it ;it = it -> next ) {
96
- if (it -> start_slot <= hash_slot && it -> end_slot >= hash_slot )
97
+
98
+ if (it -> start_slot <= hash_slot && it -> end_slot >= hash_slot ) {
99
+ LM_DBG ("Redis cluster connection, matched con %p for slot %u \n" ,it ,hash_slot );
97
100
return it ;
101
+ }
98
102
}
99
103
return NULL ;
100
104
}
@@ -230,6 +234,7 @@ int build_cluster_nodes(redis_con *con,char *info,int size)
230
234
// Cluster data into Array
231
235
if (explode (info ,delimeters ,newret1 )) {
232
236
for (i = 0 ;i <=newret1 [0 ]-> count ;i ++ ) {
237
+ LM_DBG ("Nodes : %s\n" ,newret1 [0 ]-> redisdata [i ]);
233
238
234
239
if ((strstr (newret1 [0 ]-> redisdata [i ],"master" ) && (masters <= count )) || strstr (newret1 [0 ]-> redisdata [i ],"myself,master" )) {
235
240
@@ -243,10 +248,14 @@ int build_cluster_nodes(redis_con *con,char *info,int size)
243
248
244
249
if (strstr (newret1 [0 ]-> redisdata [i ],"myself" ) && strstr (newret2 [0 ]-> redisdata [j ],"myself" )) {
245
250
//myself no ip
246
- ip = con -> id -> host ;
247
- port = con -> id -> port ;
248
- if (i == 0 ) masters -- ;
249
-
251
+ if (ip == NULL ) {
252
+ ip = con -> id -> host ;
253
+ port = con -> id -> port ;
254
+ LM_DBG ("Myself and no IP, set ip to main host %s\n" ,con -> id -> host );
255
+ if (i == 0 ) masters -- ;
256
+ } else
257
+ LM_DBG ("Master already discovered to not be myself, not going to main host \n" );
258
+
250
259
} else {
251
260
//Get the ip and port of other master
252
261
if (strstr (newret2 [0 ]-> redisdata [j ],":" ) && (strlen (newret2 [0 ]-> redisdata [j ]) > 5 )) {
@@ -269,8 +278,6 @@ int build_cluster_nodes(redis_con *con,char *info,int size)
269
278
270
279
} else { block = "row to array" ; goto error ;}
271
280
272
- LM_DBG ("ip port start end %s %hu %hu %hu\n" ,ip ,port ,start_slot ,end_slot );
273
-
274
281
if ( ip == NULL || !(port > 0 ) || (start_slot > end_slot ) || !(end_slot > 0 ) ) {block = ":processing row" ; goto error ;}
275
282
276
283
len = strlen (ip );
@@ -288,6 +295,8 @@ int build_cluster_nodes(redis_con *con,char *info,int size)
288
295
new -> start_slot = start_slot ;
289
296
new -> end_slot = end_slot ;
290
297
298
+ LM_DBG ("Saving connection %p for ip %s port %hu start %hu end %hu\n" ,new ,ip ,port ,start_slot ,end_slot );
299
+
291
300
if (con -> nodes == NULL )
292
301
con -> nodes = new ;
293
302
else {
0 commit comments