[sr-dev] git:master:b1fa63b1: htable: track when records were successfully loaded from database

Daniel-Constantin Mierla miconda at gmail.com
Wed Apr 13 17:05:58 CEST 2022


Module: kamailio
Branch: master
Commit: b1fa63b1547fc5af6cc1e97db42ea76db1bf927b
URL: https://github.com/kamailio/kamailio/commit/b1fa63b1547fc5af6cc1e97db42ea76db1bf927b

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2022-04-13T13:11:30+02:00

htable: track when records were successfully loaded from database

- write back only in such case

---

Modified: src/modules/htable/ht_api.c
Modified: src/modules/htable/ht_api.h
Modified: src/modules/htable/ht_db.c
Modified: src/modules/htable/htable.c

---

Diff:  https://github.com/kamailio/kamailio/commit/b1fa63b1547fc5af6cc1e97db42ea76db1bf927b.diff
Patch: https://github.com/kamailio/kamailio/commit/b1fa63b1547fc5af6cc1e97db42ea76db1bf927b.patch

---

diff --git a/src/modules/htable/ht_api.c b/src/modules/htable/ht_api.c
index 00023e7153..f212600e21 100644
--- a/src/modules/htable/ht_api.c
+++ b/src/modules/htable/ht_api.c
@@ -1099,7 +1099,7 @@ int ht_db_sync_tables(void)
 	ht = _ht_root;
 	while(ht)
 	{
-		if(ht->dbtable.len>0 && ht->dbmode!=0 && ht->ncols==0)
+		if(ht->dbtable.len>0 && ht->dbmode!=0 && ht->dbload!=0 && ht->ncols==0)
 		{
 			LM_DBG("sync db table [%.*s] from ht [%.*s]\n",
 					ht->dbtable.len, ht->dbtable.s,
diff --git a/src/modules/htable/ht_api.h b/src/modules/htable/ht_api.h
index 4cee835325..b3d0436ea3 100644
--- a/src/modules/htable/ht_api.h
+++ b/src/modules/htable/ht_api.h
@@ -63,6 +63,7 @@ typedef struct _ht
 	unsigned int htexpire;
 	str dbtable;
 	int dbmode;
+	int dbload;
 	int ncols;
 	str scols[HT_MAX_COLS];
 	char pack[4];
diff --git a/src/modules/htable/ht_db.c b/src/modules/htable/ht_db.c
index 5cdecb1814..5b9a5942ed 100644
--- a/src/modules/htable/ht_db.c
+++ b/src/modules/htable/ht_db.c
@@ -211,6 +211,7 @@ int ht_db_load_table(ht_t *ht, str *dbtable, int mode)
 		LM_ERR("failed to use_table\n");
 		return -1;
 	}
+	ht->dbload = 0;
 	if(ht->ncols>0) {
 		db_ord = &ht->scols[0];
 		for(c=0; c<ht->ncols; c++) {
@@ -527,6 +528,7 @@ int ht_db_load_table(ht_t *ht, str *dbtable, int mode)
 
 	ht_dbf.free_result(ht_db_con, db_res);
 	LM_DBG("loaded %d values in hash table\n", cnt);
+	ht->dbload = 1;
 
 	return 0;
 error:
diff --git a/src/modules/htable/htable.c b/src/modules/htable/htable.c
index f7a9cb389a..fea9786298 100644
--- a/src/modules/htable/htable.c
+++ b/src/modules/htable/htable.c
@@ -2053,6 +2053,8 @@ static void htable_rpc_reload(rpc_t* rpc, void* c)
 		ht_slot_unlock(ht, i);
 		nht.entries[i].first = first;
 	}
+	ht->dbload = 1;
+
 	/* free old entries */
 	for(i=0; i<nht.htsize; i++)
 	{




More information about the sr-dev mailing list