Selaa lähdekoodia

presence: Fully implement table locking for updating the presentity table

- Implement table locking for all routes through update_presentity in order
  to avoid a number of different race conditions which resulted in
  extraneous data being put into the presentity table.
Phil Lavin 9 vuotta sitten
vanhempi
commit
1c0242fecb
1 muutettua tiedostoa jossa 36 lisäystä ja 14 poistoa
  1. 36 14
      modules/presence/presentity.c

+ 36 - 14
modules/presence/presentity.c

@@ -426,6 +426,15 @@ int update_presentity(struct sip_msg* msg, presentity_t* presentity, str* body,
 				goto error;
 			}
 
+			if (pa_dbf.start_transaction)
+			{
+				if (pa_dbf.start_transaction(pa_db, db_table_lock) < 0)
+				{
+					LM_ERR("in start_transaction\n");
+					goto error;
+				}
+			}
+
 			LM_DBG("inserting %d cols into table\n",n_query_cols);
 				
 			if (pa_dbf.insert(pa_db, query_cols, query_vals, n_query_cols) < 0) 
@@ -468,22 +477,8 @@ int update_presentity(struct sip_msg* msg, presentity_t* presentity, str* body,
 			if (pa_dbf.replace(pa_db, query_cols, query_vals, n_query_cols, 4, 0) < 0) 
 			{
 				LM_ERR("replacing record in database\n");
-				if (pa_dbf.abort_transaction)
-				{
-					if (pa_dbf.abort_transaction(pa_db) < 0)
-						LM_ERR("in abort_transaction\n");
-				}
 				goto error;
 			}
-
-			if (pa_dbf.end_transaction)
-			{
-				if (pa_dbf.end_transaction(pa_db) < 0)
-				{
-					LM_ERR("in end_transaction\n");
-					goto error;
-				}
-			}
 		}
 
 		if( publ_send200ok(msg, presentity->expires, presentity->etag)< 0)
@@ -503,6 +498,15 @@ int update_presentity(struct sip_msg* msg, presentity_t* presentity, str* body,
 			goto error;
 		}
 
+		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(EVENT_DIALOG_SLA(presentity->event->evp))
 		{
 
@@ -837,6 +841,15 @@ done:
 	if(pres_uri.s)
 		pkg_free(pres_uri.s);
 
+	if (pa_dbf.end_transaction)
+	{
+		if (pa_dbf.end_transaction(pa_db) < 0)
+		{
+			LM_ERR("in end_transaction\n");
+			goto error;
+		}
+	}
+
 	return 0;
 
 send_412:
@@ -867,6 +880,15 @@ error:
 	if(pres_uri.s)
 		pkg_free(pres_uri.s);
 
+	if (pa_dbf.abort_transaction)
+	{
+		if (pa_dbf.abort_transaction(pa_db) < 0)
+		{
+			LM_ERR("in abort_transaction\n");
+			goto error;
+		}
+	}
+
 	return ret;
 }