Browse code

ndb_redis: new param to control the verbosity of some log messages

Daniel-Constantin Mierla authored on 04/07/2022 13:20:30
Showing 2 changed files
... ...
@@ -53,6 +53,7 @@ int redis_disable_time_param=0;
53 53
 int redis_allowed_timeouts_param=-1;
54 54
 int redis_flush_on_reconnect_param=0;
55 55
 int redis_allow_dynamic_nodes_param = 0;
56
+int ndb_redis_debug = L_DBG;
56 57
 
57 58
 static int w_redis_cmd3(struct sip_msg* msg, char* ssrv, char* scmd,
58 59
 		char* sres);
... ...
@@ -134,6 +135,7 @@ static param_export_t params[]={
134 135
 	{"allowed_timeouts", INT_PARAM, &redis_allowed_timeouts_param},
135 136
 	{"flush_on_reconnect", INT_PARAM, &redis_flush_on_reconnect_param},
136 137
 	{"allow_dynamic_nodes", INT_PARAM, &redis_allow_dynamic_nodes_param},
138
+	{"debug", PARAM_INT, &ndb_redis_debug},
137 139
 	{0, 0, 0}
138 140
 };
139 141
 
... ...
@@ -56,6 +56,7 @@ extern int redis_disable_time_param;
56 56
 extern int redis_allowed_timeouts_param;
57 57
 extern int redis_flush_on_reconnect_param;
58 58
 extern int redis_allow_dynamic_nodes_param;
59
+extern int ndb_redis_debug;
59 60
 
60 61
 /* backwards compatibility with hiredis < 0.12 */
61 62
 #if (HIREDIS_MAJOR == 0) && (HIREDIS_MINOR < 12)
... ...
@@ -198,8 +199,8 @@ int redisc_init(void)
198 199
 									}
199 200
 								}
200 201
 							}
201
-							LM_DBG("slave for %s: %s:%d\n", sentinel_group,
202
-									addr, port);
202
+							LOG(ndb_redis_debug, "slave for %s: %s:%d\n",
203
+									sentinel_group, addr, port);
203 204
 						}
204 205
 					}
205 206
 				}
... ...
@@ -207,15 +208,15 @@ int redisc_init(void)
207 208
 		}
208 209
 
209 210
 		if(sock != 0) {
210
-			LM_DBG("Connecting to unix socket: %s\n", unix_sock_path);
211
+			LOG(ndb_redis_debug, "Connecting to unix socket: %s\n", unix_sock_path);
211 212
 			rsrv->ctxRedis = redisConnectUnixWithTimeout(unix_sock_path,
212 213
 					tv_conn);
213 214
 		} else {
214
-			LM_DBG("Connecting to %s:%d\n", addr, port);
215
+			LOG(ndb_redis_debug, "Connecting to %s:%d\n", addr, port);
215 216
 			rsrv->ctxRedis = redisConnectWithTimeout(addr, port, tv_conn);
216 217
 		}
217 218
 
218
-		LM_DBG("rsrv->ctxRedis = %p\n", rsrv->ctxRedis);
219
+		LOG(ndb_redis_debug, "rsrv->ctxRedis = %p\n", rsrv->ctxRedis);
219 220
 
220 221
 		if(!rsrv->ctxRedis) {
221 222
 			LM_ERR("Failed to create REDIS-Context.\n");
... ...
@@ -390,18 +391,21 @@ redisc_server_t *redisc_get_server(str *name)
390 391
 	unsigned int hname;
391 392
 
392 393
 	hname = get_hash1_raw(name->s, name->len);
393
-	LM_DBG("Hash %u (%.*s)\n", hname, name->len, name->s);
394
+	LOG(ndb_redis_debug, "Hash %u (%.*s)\n", hname, name->len, name->s);
394 395
 	rsrv=_redisc_srv_list;
395 396
 	while(rsrv!=NULL)
396 397
 	{
397 398
 		LM_DBG("Entry %u (%.*s)\n", rsrv->hname,
398 399
 				rsrv->sname->len, rsrv->sname->s);
399 400
 		if(rsrv->hname==hname && rsrv->sname->len==name->len
400
-				&& strncmp(rsrv->sname->s, name->s, name->len)==0)
401
+				&& strncmp(rsrv->sname->s, name->s, name->len)==0) {
402
+			LOG(ndb_redis_debug, "Using entry %u (%.*s)\n", rsrv->hname,
403
+				rsrv->sname->len, rsrv->sname->s);
401 404
 			return rsrv;
405
+		}
402 406
 		rsrv=rsrv->next;
403 407
 	}
404
-	LM_DBG("No entry found.\n");
408
+	LOG(ndb_redis_debug, "No entry found.\n");
405 409
 	return NULL;
406 410
 }
407 411
 
... ...
@@ -497,7 +501,7 @@ int redisc_reconnect_server(redisc_server_t *rsrv)
497 501
 						strncpy(addr, res->element[0]->str,
498 502
 								res->element[0]->len + 1);
499 503
 						port = atoi(res->element[1]->str);
500
-						LM_DBG("sentinel replied: %s:%d\n", addr, port);
504
+						LOG(ndb_redis_debug, "sentinel replied: %s:%d\n", addr, port);
501 505
 					}
502 506
 				}
503 507
 				else {
... ...
@@ -520,7 +524,7 @@ int redisc_reconnect_server(redisc_server_t *rsrv)
520 524
 								}
521 525
 							}
522 526
 						}
523
-						LM_DBG("slave for %s: %s:%d\n", sentinel_group,
527
+						LOG(ndb_redis_debug, "slave for %s: %s:%d\n", sentinel_group,
524 528
 								addr, port);
525 529
 					}
526 530
 				}
... ...
@@ -689,7 +693,7 @@ int redisc_create_pipelined_message(redisc_server_t *rsrv)
689 693
 
690 694
 	if (rsrv->ctxRedis->err)
691 695
 	{
692
-		LM_DBG("Reconnecting server because of error %d: \"%s\"",
696
+		LOG(ndb_redis_debug, "Reconnecting server because of error %d: \"%s\"",
693 697
 				rsrv->ctxRedis->err,rsrv->ctxRedis->errstr);
694 698
 		if (redisc_reconnect_server(rsrv))
695 699
 		{
... ...
@@ -868,10 +872,10 @@ int check_cluster_reply(redisReply *reply, redisc_server_t **rsrv)
868 872
 			name.len = snprintf(buffername, sizeof(buffername), "%.*s:%i",
869 873
 					addr.len, addr.s, port);
870 874
 			name.s = buffername;
871
-			LM_DBG("Name of new connection: %.*s\n", name.len, name.s);
875
+			LOG(ndb_redis_debug, "Name of new connection: %.*s\n", name.len, name.s);
872 876
 			rsrv_new = redisc_get_server(&name);
873 877
 			if(rsrv_new) {
874
-				LM_DBG("Reusing Connection\n");
878
+				LOG(ndb_redis_debug, "Reusing connection\n");
875 879
 				*rsrv = rsrv_new;
876 880
 				return 1;
877 881
 			} else if(redis_allow_dynamic_nodes_param) {
... ...
@@ -908,8 +912,8 @@ int check_cluster_reply(redisReply *reply, redisc_server_t **rsrv)
908 912
 						*rsrv = rsrv_new;
909 913
 						/* Need to connect to the new server now */
910 914
 						if(redisc_reconnect_server(rsrv_new) == 0) {
911
-							LM_DBG("Connected to the new server with name: "
912
-								   "%.*s\n",
915
+							LOG(ndb_redis_debug, "Connected to the new server"
916
+									" with name: %.*s\n",
913 917
 									name.len, name.s);
914 918
 							return 1;
915 919
 						} else {
... ...
@@ -1159,13 +1163,14 @@ again:
1159 1163
 	/* null reply, reconnect and try again */
1160 1164
 	if(rsrv->ctxRedis->err)
1161 1165
 	{
1162
-		LM_DBG("Redis error: %s\n", rsrv->ctxRedis->errstr);
1166
+		LOG(ndb_redis_debug, "Redis error: %s\n", rsrv->ctxRedis->errstr);
1163 1167
 	}
1164 1168
 
1165 1169
 	if(res)
1166 1170
 	{
1167 1171
 		if (check_cluster_reply(res, &rsrv)) {
1168 1172
 			freeReplyObject(res);
1173
+			LOG(ndb_redis_debug, "Retrying the command directly\n");
1169 1174
 			goto again;
1170 1175
 		}
1171 1176
 		return res;
... ...
@@ -1173,10 +1178,12 @@ again:
1173 1178
 
1174 1179
 	if(redisc_reconnect_server(rsrv)==0)
1175 1180
 	{
1181
+		LOG(ndb_redis_debug, "Trying to reconnect to server\n");
1176 1182
 		res = redisCommandArgv(rsrv->ctxRedis, argc, argv, argvlen);
1177 1183
 		if (res) {
1178 1184
 			if (check_cluster_reply(res, &rsrv)) {
1179 1185
 				freeReplyObject(res);
1186
+				LOG(ndb_redis_debug, "Retrying the command after reconnect\n");
1180 1187
 				goto again;
1181 1188
 			}
1182 1189
 		}
... ...
@@ -1264,6 +1271,7 @@ int redisc_free_reply(str *name)
1264 1271
 	}
1265 1272
 
1266 1273
 	/* reply entry not found. */
1274
+	LOG(ndb_redis_debug, "reply entry not found: %.*s\n", name->len, name->s);
1267 1275
 	return -1;
1268 1276
 }
1269 1277