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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon May 4 07:46:13 CDT 2015


Matt Jordan has submitted this change and it was merged.

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


res_odbc: Use negative connection cache for all connections

Apply the negative connection cache setting to all connections,
even those that are not pooled. This ensures that the connection
will not be  re-established before the negative connection cache
time is met.

ASTERISK-22708 #close

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

Approvals:
  Matt Jordan: Looks good to me, approved; Verified
  Joshua Colp: Looks good to me, but someone else must approve



diff --git a/res/res_odbc.c b/res/res_odbc.c
index 5f2f2c5..2530a48 100644
--- a/res/res_odbc.c
+++ b/res/res_odbc.c
@@ -1253,8 +1253,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--;
@@ -1412,10 +1411,7 @@
 	}
 
 	if (ast_test_flag(&flags, RES_ODBC_CONNECTED) && !obj->up) {
-		/* Check if this connection qualifies for reconnection, with negative connection cache time */
-		if (time(NULL) > obj->parent->last_negative_connect.tv_sec + obj->parent->negative_connection_cache.tv_sec) {
-			odbc_obj_connect(obj);
-		}
+		odbc_obj_connect(obj);
 	} else if (ast_test_flag(&flags, RES_ODBC_SANITY_CHECK)) {
 		ast_odbc_sanity_check(obj);
 	} else if (obj->parent->idlecheck > 0 && ast_tvdiff_sec(ast_tvnow(), obj->last_used) > obj->parent->idlecheck) {
@@ -1522,6 +1518,7 @@
 	char *tracefile = "/tmp/odbc.trace";
 #endif
 	SQLHDBC con;
+	long int negative_cache_expiration;
 
 	if (obj->up) {
 		odbc_obj_disconnect(obj);
@@ -1531,6 +1528,13 @@
 		ast_log(LOG_NOTICE, "Connecting %s\n", obj->parent->name);
 	}
 
+	/* Dont connect while server is marked as unreachable via negative_connection_cache */
+	negative_cache_expiration = obj->parent->last_negative_connect.tv_sec + obj->parent->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", obj->parent->name, negative_cache_expiration - time(NULL));
+		return ODBC_FAIL;
+	}
+
 	res = SQLAllocHandle(SQL_HANDLE_DBC, obj->parent->env, &con);
 
 	if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I431cc2e8584ab0b6908b3523d0a0e18c9a527271
Gerrit-PatchSet: 7
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: Martin Tomec <tomec.martin at gmail.com>
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
Gerrit-Reviewer: Martin Tomec <tomec.martin at gmail.com>
Gerrit-Reviewer: Matt Jordan <mjordan at digium.com>
Gerrit-Reviewer: Richard Mudgett <rmudgett at digium.com>
Gerrit-Reviewer: Walter Doekes <walter+asterisk at wjd.nu>



More information about the asterisk-commits mailing list