Skip to content

Commit

Permalink
dialog: load dialogs on child init
Browse files Browse the repository at this point in the history
  • Loading branch information
razvancrainea committed Jul 1, 2019
1 parent 42f65b1 commit 3ddae43
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
8 changes: 8 additions & 0 deletions modules/dialog/dialog.c
Expand Up @@ -911,6 +911,10 @@ static int mod_init(void)



static void rpc_load_dlg_db(int sender, void *param)
{
load_dlg_db(dlg_hash_size);
}

static int child_init(int rank)
{
Expand All @@ -928,6 +932,10 @@ static int child_init(int rank)
LM_ERR("failed to connect to database (rank=%d)\n",rank);
return -1;
}
if (rank == 1 && ipc_dispatch_rpc(rpc_load_dlg_db, NULL) < 0) {
LM_CRIT("failed to RPC the dialogs loading\n");
return -1;
}
}

if (cdb_url.s && cdb_url.len && init_cachedb() < 0) {
Expand Down
22 changes: 11 additions & 11 deletions modules/dialog/dlg_db_handler.c
Expand Up @@ -191,6 +191,9 @@ int init_dlg_db(const str *db_url, int dlg_hash_size , int db_update_period)
return -1;
}

dialog_dbf.close(dialog_db_handle);
dialog_db_handle = 0;

if (dlg_db_mode == DB_MODE_DELAYED) {
if (register_timer("dlg-dbupdate",dialog_update_db,
(void*)(unsigned long)1 /*do locking*/,
Expand All @@ -200,19 +203,16 @@ int init_dlg_db(const str *db_url, int dlg_hash_size , int db_update_period)
}
}

return 0;
}

void load_dlg_db(int dlg_hash_size)
{
if( (load_dialog_info_from_db(dlg_hash_size) ) !=0 ){
if (dlg_db_mode==DB_MODE_SHUTDOWN && remove_all_dialogs_from_db()!=0)
LM_WARN("failed to properly remove all the dialogs form DB\n");
} else
LM_ERR("unable to load the dialog data\n");
return -1;
}

if (dlg_db_mode==DB_MODE_SHUTDOWN && remove_all_dialogs_from_db()!=0) {
LM_WARN("failed to properly remove all the dialogs form DB\n");
}

dialog_dbf.close(dialog_db_handle);
dialog_db_handle = 0;

return 0;
}


Expand Down
1 change: 1 addition & 0 deletions modules/dialog/dlg_db_handler.h
Expand Up @@ -104,6 +104,7 @@ extern int db_flush_vp;

#define should_remove_dlg_db() (dlg_db_mode==DB_MODE_REALTIME)

void load_dlg_db(int dlg_hash_size);
int init_dlg_db(const str *db_url, int dlg_hash_size, int db_update_period);
int dlg_connect_db(const str *db_url);
void destroy_dlg_db();
Expand Down

0 comments on commit 3ddae43

Please sign in to comment.