Skip to content

Commit 452dc41

Browse files
vladpaiuliviuchircu
authored andcommitted
cachedb_redis: Fix Cluster Master-Slave detection; Add dbg logs
1 parent 4d1e577 commit 452dc41

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

modules/cachedb_redis/cachedb_redis_dbase.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ int redis_connect(redis_con *con)
273273
/* cluster instance mode */
274274
con->flags |= REDIS_CLUSTER_INSTANCE;
275275
con->slots_assigned = 0;
276-
LM_DBG("cluster instance mode\n");
276+
LM_DBG("cluster instance mode on %p\n",con);
277277
if (build_cluster_nodes(con,rpl->str,rpl->len) < 0) {
278278
LM_ERR("failed to parse Redis cluster info\n");
279279
freeReplyObject(rpl);

modules/cachedb_redis/cachedb_redis_utils.c

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,17 @@ cluster_node *get_redis_connection(redis_con *con,str *key)
8888
unsigned short hash_slot;
8989
cluster_node *it;
9090

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);
9293
return con->nodes;
93-
else {
94+
} else {
9495
hash_slot = redisHash(con, key);
9596
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);
97100
return it;
101+
}
98102
}
99103
return NULL;
100104
}
@@ -230,6 +234,7 @@ int build_cluster_nodes(redis_con *con,char *info,int size)
230234
// Cluster data into Array
231235
if (explode(info,delimeters,newret1)) {
232236
for (i=0;i<=newret1[0]->count;i++) {
237+
LM_DBG("Nodes : %s\n",newret1[0]->redisdata[i]);
233238

234239
if ((strstr(newret1[0]->redisdata[i],"master") && (masters <= count)) || strstr(newret1[0]->redisdata[i],"myself,master")) {
235240

@@ -243,10 +248,14 @@ int build_cluster_nodes(redis_con *con,char *info,int size)
243248

244249
if (strstr(newret1[0]->redisdata[i],"myself") && strstr(newret2[0]->redisdata[j],"myself")) {
245250
//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+
250259
} else {
251260
//Get the ip and port of other master
252261
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)
269278

270279
} else { block = "row to array"; goto error;}
271280

272-
LM_DBG("ip port start end %s %hu %hu %hu\n",ip,port,start_slot,end_slot);
273-
274281
if ( ip == NULL || !(port > 0) || (start_slot > end_slot) || !(end_slot > 0) ) {block = ":processing row"; goto error;}
275282

276283
len = strlen(ip);
@@ -288,6 +295,8 @@ int build_cluster_nodes(redis_con *con,char *info,int size)
288295
new->start_slot = start_slot;
289296
new->end_slot = end_slot;
290297

298+
LM_DBG("Saving connection %p for ip %s port %hu start %hu end %hu\n",new,ip,port,start_slot,end_slot);
299+
291300
if (con->nodes == NULL)
292301
con->nodes = new;
293302
else {

0 commit comments

Comments
 (0)