Browse code

presence(k): fallback2db==1 mode updates

- go through all the list of active subcriptions when sync'ing to db, even one db operation throws error
- if fallback2db==1, don't attempt to insert the record back

root authored on 02/10/2010 19:09:09
Showing 2 changed files
... ...
@@ -261,10 +261,12 @@ int insert_shtable(shtable_t htable,unsigned int hash_code, subs_t* subs)
261 261
 	}
262 262
 
263 263
 	new_rec->expires+= (int)time(NULL);
264
-	if(fallback2db!=0)
265
-		new_rec->db_flag= INSERTDB_FLAG;
266
-	else
267
-		new_rec->db_flag= NO_UPDATEDB_FLAG;
264
+	if(fallback2db!=0) {
265
+		if(new_rec->db_flag==0)
266
+			new_rec->db_flag = INSERTDB_FLAG;
267
+	} else {
268
+		new_rec->db_flag = NO_UPDATEDB_FLAG;
269
+	}
268 270
 
269 271
 	lock_get(&htable[hash_code].lock);
270 272
 	
... ...
@@ -1536,12 +1536,10 @@ void update_db_subs(db1_con_t *db,db_func_t dbf, shtable_t hash_table,
1536 1536
 			switch(s->db_flag)
1537 1537
 			{
1538 1538
 				case NO_UPDATEDB_FLAG:
1539
-				{
1540 1539
 					LM_DBG("NO_UPDATEDB_FLAG\n");
1541 1540
 					break;			  
1542
-				}
1541
+
1543 1542
 				case UPDATEDB_FLAG:
1544
-				{
1545 1543
 					LM_DBG("UPDATEDB_FLAG\n");
1546 1544
 
1547 1545
 					query_vals[pres_uri_col].val.str_val= s->pres_uri;
... ...
@@ -1560,14 +1558,12 @@ void update_db_subs(db1_con_t *db,db_func_t dbf, shtable_t hash_table,
1560 1560
 								update_vals, n_query_update, n_update_cols)< 0)
1561 1561
 					{
1562 1562
 						LM_ERR("updating in database\n");
1563
-						if(!no_lock)
1564
-							lock_release(&hash_table[i].lock);	
1565
-						return ;
1563
+					} else {
1564
+						s->db_flag= NO_UPDATEDB_FLAG;	
1566 1565
 					}
1567 1566
 					break;
1568
-				}
1567
+
1569 1568
 				case  INSERTDB_FLAG:
1570
-				{
1571 1569
 					LM_DBG("INSERTDB_FLAG\n");
1572 1570
 
1573 1571
 					query_vals[pres_uri_col].val.str_val= s->pres_uri;
... ...
@@ -1594,15 +1590,11 @@ void update_db_subs(db1_con_t *db,db_func_t dbf, shtable_t hash_table,
1594 1594
 					if(dbf.insert(db,query_cols,query_vals,n_query_cols )<0)
1595 1595
 					{
1596 1596
 						LM_ERR("unsuccessful sql insert\n");
1597
-						if(!no_lock)
1598
-							lock_release(&hash_table[i].lock);
1599
-						return ;
1597
+					} else {
1598
+						s->db_flag= NO_UPDATEDB_FLAG;	
1600 1599
 					}
1601 1600
 					break;										
1602
-				}
1603
-
1604
-			}
1605
-			s->db_flag= NO_UPDATEDB_FLAG;	
1601
+			} /* switch */
1606 1602
 			prev_s= s;
1607 1603
 			s= s->next;
1608 1604
 		}
... ...
@@ -1808,7 +1800,9 @@ int restore_db_subs(void)
1808 1808
 	
1809 1809
 			s.sockinfo_str.s=(char*)row_vals[sockinfo_col].val.string_val;
1810 1810
 			s.sockinfo_str.len= strlen(s.sockinfo_str.s);
1811
-			
1811
+
1812
+			if(fallback2db!=0)
1813
+				s.db_flag = NO_UPDATEDB_FLAG;
1812 1814
 			hash_code= core_hash(&s.pres_uri, &s.event->name, shtable_size);
1813 1815
 			if(insert_shtable(subs_htable, hash_code, &s)< 0)
1814 1816
 			{