Added global-db-lock setting in mod_sofia

This commit is contained in:
sharmilas2704 2022-07-29 23:59:46 +05:30
parent 6bed9e163f
commit 80cce9c69b
4 changed files with 48 additions and 16 deletions

View File

@ -5,6 +5,7 @@
<!-- <param name="abort-on-empty-external-ip" value="true"/> -->
<!-- <param name="auto-restart" value="false"/> -->
<param name="debug-presence" value="0"/>
<!-- <param name="global-db-lock" value="0"/>-->
<!-- <param name="capture-server" value="udp:homer.domain.com:5060"/> -->
<!--

View File

@ -416,6 +416,7 @@ struct mod_sofia_globals {
const char *stir_shaken_vs_ca_dir;
int stir_shaken_vs_cert_path_check;
int stir_shaken_vs_require_date;
int global_db_lock;
};
extern struct mod_sofia_globals mod_sofia_globals;

View File

@ -4502,6 +4502,7 @@ switch_status_t config_sofia(sofia_config_t reload, char *profile_name)
mod_sofia_globals.auto_restart = SWITCH_TRUE;
mod_sofia_globals.reg_deny_binding_fetch_and_no_lookup = SWITCH_FALSE; /* handle backwards compatilibity - by default use new behavior */
mod_sofia_globals.rewrite_multicasted_fs_path = SWITCH_FALSE;
mod_sofia_globals.global_db_lock = SWITCH_TRUE;
if ((settings = switch_xml_child(cfg, "global_settings"))) {
for (param = switch_xml_child(settings, "param"); param; param = param->next) {
@ -4517,6 +4518,9 @@ switch_status_t config_sofia(sofia_config_t reload, char *profile_name)
mod_sofia_globals.debug_presence = atoi(val);
} else if (!strcasecmp(var, "debug-sla")) {
mod_sofia_globals.debug_sla = atoi(val);
} else if (!strcasecmp(var, "global-db-lock")) {
mod_sofia_globals.global_db_lock = switch_true(val);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "sofia global_db_lock : %d \n", mod_sofia_globals.global_db_lock);
} else if (!strcasecmp(var, "max-reg-threads") && val) {
int x = atoi(val);

View File

@ -2806,16 +2806,22 @@ void sofia_glue_actually_execute_sql_trans(sofia_profile_t *profile, char *sql,
{
switch_cache_db_handle_t *dbh = NULL;
if (mod_sofia_globals.global_db_lock) {
if (mutex) {
switch_mutex_lock(mutex);
}
}
if (!(dbh = sofia_glue_get_db_handle(profile))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB\n");
if (mod_sofia_globals.global_db_lock) {
return;
} else {
goto end;
}
}
switch_cache_db_persistant_execute_trans_full(dbh, sql, 1,
profile->pre_trans_execute,
@ -2828,35 +2834,43 @@ void sofia_glue_actually_execute_sql_trans(sofia_profile_t *profile, char *sql,
end:
if (mod_sofia_globals.global_db_lock) {
if (mutex) {
switch_mutex_unlock(mutex);
}
}
}
void sofia_glue_actually_execute_sql(sofia_profile_t *profile, char *sql, switch_mutex_t *mutex)
{
switch_cache_db_handle_t *dbh = NULL;
char *err = NULL;
if (mod_sofia_globals.global_db_lock) {
if (mutex) {
switch_mutex_lock(mutex);
}
}
if (!(dbh = sofia_glue_get_db_handle(profile))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB\n");
if (mod_sofia_globals.global_db_lock) {
if (mutex) {
switch_mutex_unlock(mutex);
}
}
return;
}
switch_cache_db_execute_sql(dbh, sql, &err);
if (mod_sofia_globals.global_db_lock) {
if (mutex) {
switch_mutex_unlock(mutex);
}
}
if (err) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR: [%s]\n%s\n", err, sql);
@ -2873,25 +2887,31 @@ switch_bool_t sofia_glue_execute_sql_callback(sofia_profile_t *profile,
char *errmsg = NULL;
switch_cache_db_handle_t *dbh = NULL;
if (mod_sofia_globals.global_db_lock) {
if (mutex) {
switch_mutex_lock(mutex);
}
}
if (!(dbh = sofia_glue_get_db_handle(profile))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB\n");
if (mod_sofia_globals.global_db_lock) {
if (mutex) {
switch_mutex_unlock(mutex);
}
}
return ret;
}
switch_cache_db_execute_sql_callback(dbh, sql, callback, pdata, &errmsg);
if (mod_sofia_globals.global_db_lock) {
if (mutex) {
switch_mutex_unlock(mutex);
}
}
if (errmsg) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR: [%s] %s\n", sql, errmsg);
@ -2909,25 +2929,31 @@ char *sofia_glue_execute_sql2str(sofia_profile_t *profile, switch_mutex_t *mutex
char *err = NULL;
switch_cache_db_handle_t *dbh = NULL;
if (mod_sofia_globals.global_db_lock) {
if (mutex) {
switch_mutex_lock(mutex);
}
}
if (!(dbh = sofia_glue_get_db_handle(profile))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB\n");
if (mod_sofia_globals.global_db_lock) {
if (mutex) {
switch_mutex_unlock(mutex);
}
}
return NULL;
}
ret = switch_cache_db_execute_sql2str(dbh, sql, resbuf, len, &err);
if (mod_sofia_globals.global_db_lock) {
if (mutex) {
switch_mutex_unlock(mutex);
}
}
if (err) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR: [%s]\n%s\n", err, sql);