]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
fix some sql order issues
authorAnthony Minessale <anthm@freeswitch.org>
Sat, 17 Nov 2012 02:09:38 +0000 (20:09 -0600)
committerAnthony Minessale <anthm@freeswitch.org>
Sat, 17 Nov 2012 02:09:43 +0000 (20:09 -0600)
src/mod/endpoints/mod_sofia/mod_sofia.h
src/mod/endpoints/mod_sofia/sofia.c
src/mod/endpoints/mod_sofia/sofia_glue.c
src/mod/endpoints/mod_sofia/sofia_presence.c
src/mod/endpoints/mod_sofia/sofia_reg.c
src/switch_core_sqldb.c

index 909516d63eff997be214ff7fe9a3778586be12a7..5240553caaea94c9800ffff0c1ff80cfdc215c9b 100644 (file)
@@ -1015,6 +1015,7 @@ void sofia_glue_execute_sql(sofia_profile_t *profile, char **sqlp, switch_bool_t
 void sofia_glue_actually_execute_sql(sofia_profile_t *profile, char *sql, switch_mutex_t *mutex);
 void sofia_glue_actually_execute_sql_trans(sofia_profile_t *profile, char *sql, switch_mutex_t *mutex);
 void sofia_glue_execute_sql_now(sofia_profile_t *profile, char **sqlp, switch_bool_t sql_already_dynamic);
+void sofia_glue_execute_sql_soon(sofia_profile_t *profile, char **sqlp, switch_bool_t sql_already_dynamic);
 void sofia_reg_check_expire(sofia_profile_t *profile, time_t now, int reboot);
 void sofia_reg_check_gateway(sofia_profile_t *profile, time_t now);
 void sofia_sub_check_gateway(sofia_profile_t *profile, time_t now);
index c7b221da0beaf9652c493e1e5fef9ad948bc95f9..b4d3e894a3513163395b12108f73a4ad74ad9b50 100644 (file)
@@ -2530,7 +2530,7 @@ void *SWITCH_THREAD_FUNC sofia_profile_thread_run(switch_thread_t *thread, void
        switch_snprintf(qname, sizeof(qname), "sofia:%s", profile->name);
        switch_sql_queue_manager_init_name(qname,
                                                                           &profile->qm,
-                                                                          1,
+                                                                          2,
                                                                           profile->odbc_dsn ? profile->odbc_dsn : profile->dbname,
                                                                           SWITCH_MAX_TRANS,
                                                                           profile->pre_trans_execute,
index 74096a3173ab06e77fb78e872fd96cacc30956dd..37caeba651b7f5d77d76abd70c13675233f6a5c1 100644 (file)
@@ -6373,7 +6373,7 @@ void sofia_glue_execute_sql(sofia_profile_t *profile, char **sqlp, switch_bool_t
        switch_assert(sqlp && *sqlp);
        sql = *sqlp;    
 
-       switch_sql_queue_manager_push(profile->qm, sql, 0, !sql_already_dynamic);
+       switch_sql_queue_manager_push(profile->qm, sql, 1, !sql_already_dynamic);
 
        if (sql_already_dynamic) {
                *sqlp = NULL;
@@ -6395,6 +6395,20 @@ void sofia_glue_execute_sql_now(sofia_profile_t *profile, char **sqlp, switch_bo
        }
 }
 
+void sofia_glue_execute_sql_soon(sofia_profile_t *profile, char **sqlp, switch_bool_t sql_already_dynamic)
+{
+       char *sql;
+
+       switch_assert(sqlp && *sqlp);
+       sql = *sqlp;    
+
+       switch_sql_queue_manager_push(profile->qm, sql, 0, !sql_already_dynamic);
+
+       if (sql_already_dynamic) {
+               *sqlp = NULL;
+       }
+}
+
 
 switch_cache_db_handle_t *_sofia_glue_get_db_handle(sofia_profile_t *profile, const char *file, const char *func, int line)
 {
index ed514e5960eb172dd8ca2981df383558fa3b7f1e..e11d96ff76a4d6c4bb716d67ff115bf543014cf9 100644 (file)
@@ -1350,7 +1350,7 @@ static switch_event_t *actual_sofia_presence_event_handler(switch_event_t *event
                                }
 
                                if (zstr(call_id)) {
-                                       
+
                                        sql = switch_mprintf("update sip_subscriptions set version=version+1 where hostname='%q' and profile_name='%q' and "
                                                                                 "sip_subscriptions.event != 'line-seize' "
                                                                                 "and sip_subscriptions.proto='%q' and (event='%q' or event='%q') and sub_to_user='%q' and "
@@ -1366,8 +1366,8 @@ static switch_event_t *actual_sofia_presence_event_handler(switch_event_t *event
                                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "PRES SQL %s\n", sql);
                                        }
 
-                                       sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
-                                       
+                                       sofia_glue_execute_sql_soon(profile, &sql, SWITCH_TRUE);
+
 
                                
                                        sql = switch_mprintf("select distinct sip_subscriptions.proto,sip_subscriptions.sip_user,sip_subscriptions.sip_host,"
@@ -1376,7 +1376,7 @@ static switch_event_t *actual_sofia_presence_event_handler(switch_event_t *event
                                                                                 "sip_subscriptions.full_via,sip_subscriptions.expires,sip_subscriptions.user_agent,"
                                                                                 "sip_subscriptions.accept,sip_subscriptions.profile_name"
                                                                                 ",'%q','%q','%q',sip_presence.status,sip_presence.rpid,sip_presence.open_closed,'%q','%q',"
-                                                                                "sip_subscriptions.version, '%q',sip_subscriptions.orig_proto,sip_subscriptions.full_to,"
+                                                                                "sip_subscriptions.version+1, '%q',sip_subscriptions.orig_proto,sip_subscriptions.full_to,"
                                                                                 "sip_subscriptions.network_ip, sip_subscriptions.network_port "
                                                                                 "from sip_subscriptions "
                                                                                 "left join sip_presence on "
@@ -1395,6 +1395,7 @@ static switch_event_t *actual_sofia_presence_event_handler(switch_event_t *event
                                                                                 event_type, alt_event_type, euser, host, profile->sipip, 
                                                                                 profile->extsipip ? profile->extsipip : "N/A", host);
                                } else {
+
                                        sql = switch_mprintf("update sip_subscriptions set version=version+1 where sip_subscriptions.event != 'line-seize' and "
                                                                                 "hostname='%q' and profile_name = '%q' and sip_subscriptions.call_id='%q'",
                                                                                 mod_sofia_globals.hostname, profile->name, call_id);
@@ -1404,7 +1405,7 @@ static switch_event_t *actual_sofia_presence_event_handler(switch_event_t *event
                                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "PRES SQL %s\n", sql);
                                        }
 
-                                       sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
+                                       sofia_glue_execute_sql_soon(profile, &sql, SWITCH_TRUE);
 
 
                                        sql = switch_mprintf("select distinct sip_subscriptions.proto,sip_subscriptions.sip_user,sip_subscriptions.sip_host,"
@@ -1413,7 +1414,7 @@ static switch_event_t *actual_sofia_presence_event_handler(switch_event_t *event
                                                                                 "sip_subscriptions.full_via,sip_subscriptions.expires,sip_subscriptions.user_agent,"
                                                                                 "sip_subscriptions.accept,sip_subscriptions.profile_name"
                                                                                 ",'%q','%q','%q',sip_presence.status,sip_presence.rpid,sip_presence.open_closed,'%q','%q',"
-                                                                                "sip_subscriptions.version, '%q',sip_subscriptions.orig_proto,sip_subscriptions.full_to,"
+                                                                                "sip_subscriptions.version+1, '%q',sip_subscriptions.orig_proto,sip_subscriptions.full_to,"
                                                                                 "sip_subscriptions.network_ip, sip_subscriptions.network_port "
                                                                                 "from sip_subscriptions "
                                                                                 "left join sip_presence on "
index 4efa9fabe6c53cc2d4be0b62092226f2c8ea2762..79b49c1b6b48bdb3635cde6626801ce4d06459c0 100644 (file)
@@ -2353,6 +2353,8 @@ auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile,
        if (zstr(np)) {
                nonce_cb_t cb = { 0 };
                long nc_long = 0;
+               int sanity = 0;
+
                first = 1;
 
                if (nc) {
@@ -2366,7 +2368,14 @@ auth_res_t sofia_reg_parse_auth(sofia_profile_t *profile,
                cb.nplen = nplen;
 
                switch_assert(sql != NULL);
-               sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sofia_reg_nonce_callback, &cb);
+
+               do {
+                       if (sanity) {
+                               switch_yield(100000 * sanity);
+                       }
+                       sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, sofia_reg_nonce_callback, &cb);
+               } while(nc_long < 2 && ++sanity < 10 && zstr(np));
+
                free(sql);
 
                //if (!sofia_glue_execute_sql2str(profile, profile->ireg_mutex, sql, np, nplen)) {
index 17a3f3b0f8f04b9944a22ceaa9c18d39c6b69477..7d1e6c8716fb2ba50e5f02512e1e27680af5cd99 100644 (file)
@@ -835,7 +835,7 @@ SWITCH_DECLARE(switch_status_t) switch_cache_db_persistant_execute_trans_full(sw
                switch(dbh->type) {
                case SCDB_TYPE_CORE_DB:
                        {
-                               switch_cache_db_execute_sql_real(dbh, "BEGIN", &errmsg);
+                               switch_cache_db_execute_sql_real(dbh, "BEGIN EXCLUSIVE", &errmsg);
                        }
                        break;
                case SCDB_TYPE_ODBC:
@@ -1497,7 +1497,7 @@ static uint32_t do_trans(switch_sql_queue_manager_t *qm)
        switch(qm->event_db->type) {
        case SCDB_TYPE_CORE_DB:
                {
-                       switch_cache_db_execute_sql_real(qm->event_db, "BEGIN", &errmsg);
+                       switch_cache_db_execute_sql_real(qm->event_db, "BEGIN EXCLUSIVE", &errmsg);
                }
                break;
        case SCDB_TYPE_ODBC:
@@ -2979,7 +2979,7 @@ switch_status_t switch_core_sqldb_start(switch_memory_pool_t *pool, switch_bool_
                        switch(sql_manager.dbh->type) {
                        case SCDB_TYPE_CORE_DB:
                                {
-                                       switch_cache_db_execute_sql_real(sql_manager.dbh, "BEGIN", &err);
+                                       switch_cache_db_execute_sql_real(sql_manager.dbh, "BEGIN EXCLUSIVE", &err);
                                }
                                break;
                        case SCDB_TYPE_ODBC: