[asterisk-commits] tilghman: branch tilghman/realtime_failover r179060 - in /team/tilghman/realt...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Fri Feb 27 13:17:23 CST 2009
Author: tilghman
Date: Fri Feb 27 13:17:19 2009
New Revision: 179060
URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=179060
Log:
1) Fix an infinite loop in config.
2) Fix how the ODBC realtime backend requests handles.
3) Add debugging and fix the timing mechanism to not wrap times.
Modified:
team/tilghman/realtime_failover/main/config.c
team/tilghman/realtime_failover/res/res_config_odbc.c
team/tilghman/realtime_failover/res/res_odbc.c
Modified: team/tilghman/realtime_failover/main/config.c
URL: http://svn.digium.com/svn-view/asterisk/team/tilghman/realtime_failover/main/config.c?view=diff&rev=179060&r1=179059&r2=179060
==============================================================================
--- team/tilghman/realtime_failover/main/config.c (original)
+++ team/tilghman/realtime_failover/main/config.c Fri Feb 27 13:17:19 2009
@@ -2035,8 +2035,6 @@
char table[256];
struct ast_config_engine *loader = &text_file_engine;
struct ast_config *result;
- struct ast_config_engine *eng;
- int final = 0, i;
/* The config file itself bumps include_level by 1 */
if (cfg->max_include_level > 0 && cfg->include_level == cfg->max_include_level + 1) {
@@ -2046,29 +2044,27 @@
cfg->include_level++;
- for (i = 1; !final; i++) {
- if (strcmp(filename, extconfig_conf) && strcmp(filename, "asterisk.conf") && config_engine_list) {
-
- eng = find_engine(filename, i, db, sizeof(db), table, sizeof(table));
-
- if (eng && eng->load_func) {
+ if (strcmp(filename, extconfig_conf) && strcmp(filename, "asterisk.conf") && config_engine_list) {
+ struct ast_config_engine *eng;
+
+ eng = find_engine(filename, 1, db, sizeof(db), table, sizeof(table));
+
+
+ if (eng && eng->load_func) {
+ loader = eng;
+ } else {
+ eng = find_engine("global", 1, db, sizeof(db), table, sizeof(table));
+ if (eng && eng->load_func)
loader = eng;
- } else if (strcmp(filename, "global")) {
- return ast_config_internal_load("global", cfg, flags, suggested_include_file, who_asked);
- }
- } else {
- final = 1;
- }
-
- result = loader->load_func(db, table, filename, cfg, flags, suggested_include_file, who_asked);
-
- if (result && result != CONFIG_STATUS_FILEINVALID && result != CONFIG_STATUS_FILEUNCHANGED) {
- final = 1;
- result->include_level--;
- } else if (result != CONFIG_STATUS_FILEINVALID) {
- cfg->include_level--;
- }
- }
+ }
+ }
+
+ result = loader->load_func(db, table, filename, cfg, flags, suggested_include_file, who_asked);
+
+ if (result && result != CONFIG_STATUS_FILEINVALID && result != CONFIG_STATUS_FILEUNCHANGED)
+ result->include_level--;
+ else if (result != CONFIG_STATUS_FILEINVALID)
+ cfg->include_level--;
return result;
}
Modified: team/tilghman/realtime_failover/res/res_config_odbc.c
URL: http://svn.digium.com/svn-view/asterisk/team/tilghman/realtime_failover/res/res_config_odbc.c?view=diff&rev=179060&r1=179059&r2=179060
==============================================================================
--- team/tilghman/realtime_failover/res/res_config_odbc.c (original)
+++ team/tilghman/realtime_failover/res/res_config_odbc.c Fri Feb 27 13:17:19 2009
@@ -131,6 +131,7 @@
SQLLEN indicator;
va_list aq;
struct custom_prepare_struct cps = { .sql = sql };
+ struct ast_flags connected_flag = { RES_ODBC_CONNECTED };
va_copy(cps.ap, ap);
va_copy(aq, ap);
@@ -138,7 +139,7 @@
if (!table)
return NULL;
- obj = ast_odbc_request_obj(database, RES_ODBC_CONNECTED);
+ obj = ast_odbc_request_obj2(database, connected_flag);
if (!obj) {
ast_log(LOG_ERROR, "No database handle available with the name of '%s' (check res_odbc.conf)\n", database);
@@ -271,6 +272,7 @@
struct ast_variable *var=NULL;
struct ast_config *cfg=NULL;
struct ast_category *cat=NULL;
+ struct ast_flags connected_flag = { RES_ODBC_CONNECTED };
SQLULEN colsize;
SQLSMALLINT colcount=0;
SQLSMALLINT datatype;
@@ -286,7 +288,7 @@
if (!table)
return NULL;
- obj = ast_odbc_request_obj(database, RES_ODBC_CONNECTED);
+ obj = ast_odbc_request_obj2(database, connected_flag);
if (!obj)
return NULL;
@@ -413,6 +415,7 @@
struct custom_prepare_struct cps = { .sql = sql, .extra = lookup };
struct odbc_cache_tables *tableptr = ast_odbc_find_table(database, table);
struct odbc_cache_columns *column;
+ struct ast_flags connected_flag = { RES_ODBC_CONNECTED };
va_copy(cps.ap, ap);
va_copy(aq, ap);
@@ -422,7 +425,7 @@
return -1;
}
- obj = ast_odbc_request_obj(database, RES_ODBC_CONNECTED);
+ obj = ast_odbc_request_obj2(database, connected_flag);
if (!obj) {
ast_odbc_release_table(tableptr);
return -1;
@@ -642,6 +645,7 @@
int res;
va_list aq;
struct custom_prepare_struct cps = { .sql = sql, .extra = NULL };
+ struct ast_flags connected_flag = { RES_ODBC_CONNECTED };
va_copy(cps.ap, ap);
va_copy(aq, ap);
@@ -649,7 +653,7 @@
if (!table)
return -1;
- obj = ast_odbc_request_obj(database, RES_ODBC_CONNECTED);
+ obj = ast_odbc_request_obj2(database, connected_flag);
if (!obj)
return -1;
@@ -716,6 +720,7 @@
int res;
va_list aq;
struct custom_prepare_struct cps = { .sql = sql, .extra = lookup };
+ struct ast_flags connected_flag = { RES_ODBC_CONNECTED };
va_copy(cps.ap, ap);
va_copy(aq, ap);
@@ -723,7 +728,7 @@
if (!table)
return -1;
- obj = ast_odbc_request_obj(database, RES_ODBC_CONNECTED);
+ obj = ast_odbc_request_obj2(database, connected_flag);
if (!obj)
return -1;
@@ -809,13 +814,14 @@
char last[128] = "";
struct config_odbc_obj q;
struct ast_flags loader_flags = { 0 };
+ struct ast_flags connected_flag = { RES_ODBC_CONNECTED };
memset(&q, 0, sizeof(q));
if (!file || !strcmp (file, "res_config_odbc.conf"))
return NULL; /* cant configure myself with myself ! */
- obj = ast_odbc_request_obj(database, RES_ODBC_CONNECTED);
+ obj = ast_odbc_request_obj2(database, connected_flag);
if (!obj)
return NULL;
Modified: team/tilghman/realtime_failover/res/res_odbc.c
URL: http://svn.digium.com/svn-view/asterisk/team/tilghman/realtime_failover/res/res_odbc.c?view=diff&rev=179060&r1=179059&r2=179060
==============================================================================
--- team/tilghman/realtime_failover/res/res_odbc.c (original)
+++ team/tilghman/realtime_failover/res/res_odbc.c Fri Feb 27 13:17:19 2009
@@ -934,7 +934,13 @@
while ((class = ao2_iterator_next(&aoi))) {
if ((a->argc == 2) || (a->argc == 3 && !strcmp(a->argv[2], "all")) || (!strcmp(a->argv[2], class->name))) {
int count = 0;
+ char timestr[80];
+ struct ast_tm tm;
+
+ ast_localtime(&class->last_negative_connect, &tm, NULL);
+ ast_strftime(timestr, sizeof(timestr), "%Y-%m-%d %T", &tm);
ast_cli(a->fd, " Name: %s\n DSN: %s\n", class->name, class->dsn);
+ ast_cli(a->fd, " Last connection attempt: %s\n", timestr);
if (class->haspool) {
struct ao2_iterator aoi2 = ao2_iterator_init(class->obj_container, 0);
@@ -1183,6 +1189,7 @@
unsigned char state[10], diagnostic[256];
if (!(class = ao2_callback(class_container, 0, aoro2_class_cb, (char *) name))) {
+ ast_debug(1, "Class not found!\n");
return NULL;
}
@@ -1196,11 +1203,12 @@
ast_assert(ao2_ref(obj, 0) > 1);
}
if (!obj && (class->count < class->limit) &&
- ast_tvdiff_ms(ast_tvnow(), ast_tvadd(class->last_negative_connect, class->negative_connection_cache)) > 0) {
+ (time(NULL) > class->last_negative_connect.tv_sec + class->negative_connection_cache.tv_sec)) {
obj = ao2_alloc(sizeof(*obj), odbc_obj_destructor);
if (!obj) {
class->count--;
ao2_ref(class, -1);
+ ast_debug(3, "Unable to allocate object\n");
return NULL;
}
ast_assert(ao2_ref(obj, 0) == 1);
@@ -1241,9 +1249,11 @@
} else if (ast_test_flag(&flags, RES_ODBC_INDEPENDENT_CONNECTION)) {
/* Non-pooled connections -- but must use a separate connection handle */
if (!(obj = ao2_callback(class->obj_container, 0, aoro2_obj_cb, USE_TX))) {
+ ast_debug(1, "Object not found\n");
obj = ao2_alloc(sizeof(*obj), odbc_obj_destructor);
if (!obj) {
ao2_ref(class, -1);
+ ast_debug(3, "Unable to allocate object\n");
return NULL;
}
ast_mutex_init(&obj->lock);
@@ -1284,6 +1294,7 @@
if (!(obj = ao2_alloc(sizeof(*obj), odbc_obj_destructor))) {
ast_assert(ao2_ref(class, 0) > 1);
ao2_ref(class, -1);
+ ast_debug(3, "Unable to allocate object\n");
return NULL;
}
ast_mutex_init(&obj->lock);
@@ -1328,7 +1339,7 @@
if (obj && ast_test_flag(&flags, RES_ODBC_CONNECTED) && !obj->up) {
/* Check if this connection qualifies for reconnection, with negative connection cache time */
- if (ast_tvdiff_ms(ast_tvnow(), ast_tvadd(class->last_negative_connect, class->negative_connection_cache)) > 0) {
+ if (time(NULL) > class->last_negative_connect.tv_sec + class->negative_connection_cache.tv_sec) {
odbc_obj_connect(obj);
}
} else if (obj && ast_test_flag(&flags, RES_ODBC_SANITY_CHECK)) {
More information about the asterisk-commits
mailing list