Skip to content

Commit

Permalink
htable: track when records were successfully loaded from database
Browse files Browse the repository at this point in the history
- write back only in such case
  • Loading branch information
miconda committed Apr 13, 2022
1 parent d542cb8 commit b1fa63b
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/modules/htable/ht_api.c
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/modules/htable/ht_api.h
Expand Up @@ -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];
Expand Down
2 changes: 2 additions & 0 deletions src/modules/htable/ht_db.c
Expand Up @@ -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++) {
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions src/modules/htable/htable.c
Expand Up @@ -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++)
{
Expand Down

0 comments on commit b1fa63b

Please sign in to comment.