FS-3105 try this patch

This commit is contained in:
Anthony Minessale 2011-03-01 10:52:12 -06:00
parent b041edc858
commit 2044a749cf
1 changed files with 36 additions and 55 deletions

View File

@ -431,13 +431,13 @@ static switch_status_t switch_cache_db_execute_sql_real(switch_cache_db_handle_t
switch_status_t status = SWITCH_STATUS_FALSE; switch_status_t status = SWITCH_STATUS_FALSE;
char *errmsg = NULL; char *errmsg = NULL;
char *tmp = NULL; char *tmp = NULL;
switch_mutex_t *io_mutex = dbh->io_mutex;
if (dbh->io_mutex) { if (io_mutex) switch_mutex_lock(io_mutex);
switch_mutex_lock(dbh->io_mutex);
}
if (err) if (err) {
*err = NULL; *err = NULL;
}
switch (dbh->type) { switch (dbh->type) {
case SCDB_TYPE_ODBC: case SCDB_TYPE_ODBC:
@ -469,9 +469,7 @@ static switch_status_t switch_cache_db_execute_sql_real(switch_cache_db_handle_t
} }
if (dbh->io_mutex) { if (io_mutex) switch_mutex_unlock(io_mutex);
switch_mutex_unlock(dbh->io_mutex);
}
return status; return status;
} }
@ -556,10 +554,9 @@ static switch_status_t switch_cache_db_execute_sql_chunked(switch_cache_db_handl
SWITCH_DECLARE(switch_status_t) switch_cache_db_execute_sql(switch_cache_db_handle_t *dbh, char *sql, char **err) SWITCH_DECLARE(switch_status_t) switch_cache_db_execute_sql(switch_cache_db_handle_t *dbh, char *sql, char **err)
{ {
switch_status_t status = SWITCH_STATUS_FALSE; switch_status_t status = SWITCH_STATUS_FALSE;
switch_mutex_t *io_mutex = dbh->io_mutex;
if (dbh->io_mutex) { if (io_mutex) switch_mutex_lock(io_mutex);
switch_mutex_lock(dbh->io_mutex);
}
switch (dbh->type) { switch (dbh->type) {
default: default:
@ -569,9 +566,7 @@ SWITCH_DECLARE(switch_status_t) switch_cache_db_execute_sql(switch_cache_db_hand
break; break;
} }
if (dbh->io_mutex) { if (io_mutex) switch_mutex_unlock(io_mutex);
switch_mutex_unlock(dbh->io_mutex);
}
return status; return status;
@ -599,11 +594,9 @@ SWITCH_DECLARE(int) switch_cache_db_affected_rows(switch_cache_db_handle_t *dbh)
SWITCH_DECLARE(char *) switch_cache_db_execute_sql2str(switch_cache_db_handle_t *dbh, char *sql, char *str, size_t len, char **err) SWITCH_DECLARE(char *) switch_cache_db_execute_sql2str(switch_cache_db_handle_t *dbh, char *sql, char *str, size_t len, char **err)
{ {
switch_status_t status = SWITCH_STATUS_FALSE; switch_status_t status = SWITCH_STATUS_FALSE;
switch_mutex_t *io_mutex = dbh->io_mutex;
if (io_mutex) switch_mutex_lock(io_mutex);
if (dbh->io_mutex) {
switch_mutex_lock(dbh->io_mutex);
}
switch (dbh->type) { switch (dbh->type) {
case SCDB_TYPE_CORE_DB: case SCDB_TYPE_CORE_DB:
@ -612,7 +605,7 @@ SWITCH_DECLARE(char *) switch_cache_db_execute_sql2str(switch_cache_db_handle_t
if (switch_core_db_prepare(dbh->native_handle.core_db_dbh, sql, -1, &stmt, 0)) { if (switch_core_db_prepare(dbh->native_handle.core_db_dbh, sql, -1, &stmt, 0)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Statement Error [%s]!\n", sql); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Statement Error [%s]!\n", sql);
return NULL; goto end;
} else { } else {
int running = 1; int running = 1;
int colcount; int colcount;
@ -652,9 +645,7 @@ SWITCH_DECLARE(char *) switch_cache_db_execute_sql2str(switch_cache_db_handle_t
end: end:
if (dbh->io_mutex) { if (io_mutex) switch_mutex_unlock(io_mutex);
switch_mutex_unlock(dbh->io_mutex);
}
return status == SWITCH_STATUS_SUCCESS ? str : NULL; return status == SWITCH_STATUS_SUCCESS ? str : NULL;
@ -665,18 +656,20 @@ SWITCH_DECLARE(switch_status_t) switch_cache_db_persistant_execute(switch_cache_
char *errmsg = NULL; char *errmsg = NULL;
switch_status_t status = SWITCH_STATUS_FALSE; switch_status_t status = SWITCH_STATUS_FALSE;
uint8_t forever = 0; uint8_t forever = 0;
switch_mutex_t *io_mutex = dbh->io_mutex;
if (!retries) { if (!retries) {
forever = 1; forever = 1;
retries = 1000; retries = 1000;
} }
if (dbh->io_mutex) {
switch_mutex_lock(dbh->io_mutex);
}
while (retries > 0) { while (retries > 0) {
if (io_mutex) switch_mutex_lock(io_mutex);
switch_cache_db_execute_sql_real(dbh, sql, &errmsg); switch_cache_db_execute_sql_real(dbh, sql, &errmsg);
if (io_mutex) switch_mutex_unlock(io_mutex);
if (errmsg) { if (errmsg) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR [%s]\n", errmsg); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR [%s]\n", errmsg);
switch_safe_free(errmsg); switch_safe_free(errmsg);
@ -692,10 +685,6 @@ SWITCH_DECLARE(switch_status_t) switch_cache_db_persistant_execute(switch_cache_
} }
} }
if (dbh->io_mutex) {
switch_mutex_unlock(dbh->io_mutex);
}
return status; return status;
} }
@ -707,15 +696,14 @@ SWITCH_DECLARE(switch_status_t) switch_cache_db_persistant_execute_trans(switch_
uint8_t forever = 0; uint8_t forever = 0;
unsigned begin_retries = 100; unsigned begin_retries = 100;
uint8_t again = 0; uint8_t again = 0;
switch_mutex_t *io_mutex = dbh->io_mutex;
if (!retries) { if (!retries) {
forever = 1; forever = 1;
retries = 1000; retries = 1000;
} }
if (dbh->io_mutex) { if (io_mutex) switch_mutex_lock(io_mutex);
switch_mutex_lock(dbh->io_mutex);
}
again: again:
@ -726,6 +714,7 @@ SWITCH_DECLARE(switch_status_t) switch_cache_db_persistant_execute_trans(switch_
switch_cache_db_execute_sql_real(dbh, "BEGIN", &errmsg); switch_cache_db_execute_sql_real(dbh, "BEGIN", &errmsg);
} else { } else {
switch_odbc_status_t result; switch_odbc_status_t result;
if ((result = switch_odbc_SQLSetAutoCommitAttr(dbh->native_handle.odbc_dbh, 0)) != SWITCH_ODBC_SUCCESS) { if ((result = switch_odbc_SQLSetAutoCommitAttr(dbh->native_handle.odbc_dbh, 0)) != SWITCH_ODBC_SUCCESS) {
char tmp[100]; char tmp[100];
switch_snprintf(tmp, sizeof(tmp), "%s-%i", "Unable to Set AutoCommit Off", result); switch_snprintf(tmp, sizeof(tmp), "%s-%i", "Unable to Set AutoCommit Off", result);
@ -759,17 +748,17 @@ SWITCH_DECLARE(switch_status_t) switch_cache_db_persistant_execute_trans(switch_
if (begin_retries == 0) { if (begin_retries == 0) {
goto done; goto done;
} }
} else {
break; continue;
} }
break;
} }
while (retries > 0) { while (retries > 0) {
switch_cache_db_execute_sql(dbh, sql, &errmsg); switch_cache_db_execute_sql(dbh, sql, &errmsg);
if (errmsg) { if (errmsg) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR [%s]\n", errmsg); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR [%s]\n", errmsg);
free(errmsg); free(errmsg);
@ -795,10 +784,7 @@ SWITCH_DECLARE(switch_status_t) switch_cache_db_persistant_execute_trans(switch_
switch_odbc_SQLSetAutoCommitAttr(dbh->native_handle.odbc_dbh, 1); switch_odbc_SQLSetAutoCommitAttr(dbh->native_handle.odbc_dbh, 1);
} }
if (dbh->io_mutex) { if (io_mutex) switch_mutex_unlock(io_mutex);
switch_mutex_unlock(dbh->io_mutex);
}
return status; return status;
} }
@ -808,14 +794,14 @@ SWITCH_DECLARE(switch_status_t) switch_cache_db_execute_sql_callback(switch_cach
{ {
switch_status_t status = SWITCH_STATUS_FALSE; switch_status_t status = SWITCH_STATUS_FALSE;
char *errmsg = NULL; char *errmsg = NULL;
switch_mutex_t *io_mutex = dbh->io_mutex;
if (err) if (err) {
*err = NULL; *err = NULL;
if (dbh->io_mutex) {
switch_mutex_lock(dbh->io_mutex);
} }
if (io_mutex) switch_mutex_lock(io_mutex);
switch (dbh->type) { switch (dbh->type) {
case SCDB_TYPE_ODBC: case SCDB_TYPE_ODBC:
@ -836,9 +822,7 @@ SWITCH_DECLARE(switch_status_t) switch_cache_db_execute_sql_callback(switch_cach
break; break;
} }
if (dbh->io_mutex) { if (io_mutex) switch_mutex_unlock(io_mutex);
switch_mutex_unlock(dbh->io_mutex);
}
return status; return status;
} }
@ -848,15 +832,14 @@ SWITCH_DECLARE(switch_bool_t) switch_cache_db_test_reactive(switch_cache_db_hand
{ {
char *errmsg; char *errmsg;
switch_bool_t r = SWITCH_TRUE; switch_bool_t r = SWITCH_TRUE;
switch_mutex_t *io_mutex = dbh->io_mutex;
if (!switch_test_flag((&runtime), SCF_AUTO_SCHEMAS)) { if (!switch_test_flag((&runtime), SCF_AUTO_SCHEMAS)) {
switch_cache_db_execute_sql(dbh, (char *)test_sql, NULL); switch_cache_db_execute_sql(dbh, (char *)test_sql, NULL);
return SWITCH_TRUE; return SWITCH_TRUE;
} }
if (dbh->io_mutex) { if (io_mutex) switch_mutex_lock(io_mutex);
switch_mutex_lock(dbh->io_mutex);
}
switch (dbh->type) { switch (dbh->type) {
case SCDB_TYPE_ODBC: case SCDB_TYPE_ODBC:
@ -901,9 +884,7 @@ SWITCH_DECLARE(switch_bool_t) switch_cache_db_test_reactive(switch_cache_db_hand
} }
if (dbh->io_mutex) { if (io_mutex) switch_mutex_unlock(io_mutex);
switch_mutex_unlock(dbh->io_mutex);
}
return r; return r;
} }