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

Martin Tomec asteriskteam at digium.com
Tue Apr 21 12:10:51 CDT 2015


Martin Tomec has uploaded a new change for review.

  https://gerrit.asterisk.org/184

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/84/184/1

diff --git a/res/res_odbc.c b/res/res_odbc.c
index 259467a..950c916 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/184
To unsubscribe, visit https://gerrit.asterisk.org/settings

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



More information about the asterisk-code-review mailing list