[Asterisk-code-review] res odbc: Use negative connection cache for all connections (asterisk[master])

Martin Tomec asteriskteam at digium.com
Tue Apr 21 11:53:40 CDT 2015


Martin Tomec has uploaded a new change for review.

  https://gerrit.asterisk.org/182

Change subject: res_odbc: Use negative connection cache for all connections
......................................................................

res_odbc: Use negative connection cache for all connections

Reported as a bug. When server is marked as unconectable, we should
not try to conect in any way.

ASTERISK-22708 #comment Fixed

Change-Id: I431cc2e8584ab0b6908b3523d0a0e18c9a527271
---
M res/res_odbc.c
1 file changed, 8 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/82/182/1

diff --git a/res/res_odbc.c b/res/res_odbc.c
index 5f2f2c5..777183c 100644
--- a/res/res_odbc.c
+++ b/res/res_odbc.c
@@ -1246,6 +1246,13 @@
 
 	ast_assert(ao2_ref(class, 0) > 1);
 
+	/* Dont connect while server is marked as unreachable via negative_connection_cache */
+	long int negative_cache_expiration = class->last_negative_connect.tv_sec + class->negative_connection_cache.tv_sec; 
+	if (time(NULL) < negative_cache_expiration) {
+		ast_log(LOG_WARNING, "Not connecting to %s. Negative connection cache for %ld seconds\n", name, negative_cache_expiration - time(NULL));
+		return NULL;
+	}
+
 	if (class->haspool) {
 		/* Recycle connections before building another */
 		obj = ao2_callback(class->obj_container, 0, aoro2_obj_cb, EOR_TX);
@@ -1253,8 +1260,7 @@
 		if (obj) {
 			ast_assert(ao2_ref(obj, 0) > 1);
 		}
-		if (!obj && (ast_atomic_fetchadd_int(&class->count, +1) < class->limit) &&
-				(time(NULL) > class->last_negative_connect.tv_sec + class->negative_connection_cache.tv_sec)) {
+		if (!obj && (ast_atomic_fetchadd_int(&class->count, +1) < class->limit)) {
 			obj = ao2_alloc(sizeof(*obj), odbc_obj_destructor);
 			if (!obj) {
 				class->count--;

-- 
To view, visit https://gerrit.asterisk.org/182
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I431cc2e8584ab0b6908b3523d0a0e18c9a527271
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: Martin Tomec <tomec.martin at gmail.com>



More information about the asterisk-code-review mailing list