Skip to content

Commit

Permalink
presence: remove transaction creation from publ_notify_notifier() and…
Browse files Browse the repository at this point in the history
… mark_presentity_for_delete()

* publ_notify_notifier() and mark_presentity_for_delete() are
  called inside a already created transaction
* adding transaction handle for msg_presentity_clean()

fix kamailio#960
  • Loading branch information
linuxmaniac committed Jan 31, 2017
1 parent 76765a2 commit fc934e5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 48 deletions.
24 changes: 0 additions & 24 deletions modules/presence/notify.c
Expand Up @@ -1348,15 +1348,6 @@ int publ_notify_notifier(str pres_uri, pres_ev_t *event)
result_cols[r_to_tag_col=n_result_cols++] = &str_to_tag_col;
result_cols[r_from_tag_col=n_result_cols++] = &str_from_tag_col;

if (pa_dbf.start_transaction)
{
if (pa_dbf.start_transaction(pa_db, db_table_lock) < 0)
{
LM_ERR("in start_transaction\n");
goto error;
}
}

if(query_fn(pa_db, query_cols, 0, query_vals, result_cols,
n_query_cols, n_result_cols, 0, &result )< 0)
{
Expand Down Expand Up @@ -1385,26 +1376,11 @@ int publ_notify_notifier(str pres_uri, pres_ev_t *event)
set_updated(&subs);
}

if (pa_dbf.end_transaction)
{
if (pa_dbf.end_transaction(pa_db) < 0)
{
LM_ERR("in end_transaction\n");
goto error;
}
}

ret = RES_ROW_N(result);

error:
if (result) pa_dbf.free_result(pa_db, result);

if (pa_dbf.abort_transaction)
{
if (pa_dbf.abort_transaction(pa_db) < 0)
LM_ERR("in abort_transaction\n");
}

return ret;
}

Expand Down
24 changes: 0 additions & 24 deletions modules/presence/presentity.c
Expand Up @@ -1564,15 +1564,6 @@ int mark_presentity_for_delete(presentity_t *pres)

result_cols[0] = &str_body_col;

if (pa_dbf.start_transaction)
{
if (pa_dbf.start_transaction(pa_db, db_table_lock) < 0)
{
LM_ERR("in start_transaction\n");
goto error;
}
}

if (query_fn(pa_db, query_cols, 0, query_vals, result_cols,
n_query_cols, 1, 0, &result) < 0)
{
Expand Down Expand Up @@ -1653,15 +1644,6 @@ int mark_presentity_for_delete(presentity_t *pres)
goto error;
}

if (pa_dbf.end_transaction)
{
if (pa_dbf.end_transaction(pa_db) < 0)
{
LM_ERR("in end_transaction\n");
goto error;
}
}

if (pa_dbf.affected_rows)
ret = pa_dbf.affected_rows(pa_db);
else
Expand All @@ -1673,12 +1655,6 @@ int mark_presentity_for_delete(presentity_t *pres)
if (cur_body) pkg_free(cur_body);
if (result) pa_dbf.free_result(pa_db, result);

if (pa_dbf.abort_transaction)
{
if (pa_dbf.abort_transaction(pa_db) < 0)
LM_ERR("in abort_transaction\n");
}

return ret;
}

Expand Down
26 changes: 26 additions & 0 deletions modules/presence/publish.c
Expand Up @@ -156,9 +156,22 @@ void msg_presentity_clean(unsigned int ticks,void *param)

if (pres_notifier_processes > 0)
{
if (pa_dbf.start_transaction)
{
if (pa_dbf.start_transaction(pa_db, db_table_lock) < 0)
{
LM_ERR("in start_transaction\n");
goto error;
}
}
if ((num_watchers = publ_notify_notifier(uri, pres.event)) < 0)
{
LM_ERR("Updating watcher records\n");
if (pa_dbf.abort_transaction)
{
if (pa_dbf.abort_transaction(pa_db) < 0)
LM_ERR("in abort_transaction\n");
}
goto error;
}

Expand All @@ -167,6 +180,11 @@ void msg_presentity_clean(unsigned int ticks,void *param)
if (mark_presentity_for_delete(&pres) < 0)
{
LM_ERR("Marking presentity\n");
if (pa_dbf.abort_transaction)
{
if (pa_dbf.abort_transaction(pa_db) < 0)
LM_ERR("in abort_transaction\n");
}
goto error;
}
}
Expand All @@ -178,6 +196,14 @@ void msg_presentity_clean(unsigned int ticks,void *param)
goto error;
}
}
if (pa_dbf.end_transaction)
{
if (pa_dbf.end_transaction(pa_db) < 0)
{
LM_ERR("in end_transaction\n");
goto error;
}
}
}
else
{
Expand Down

0 comments on commit fc934e5

Please sign in to comment.