p_persistency.c File Reference


Detailed Description

P-CSCF persistency operations.

Author:
Dragos Vingarzan vingarzan -at- fokus dot fraunhofer dot de

Definition in file p_persistency.c.

#include "p_persistency.h"

Go to the source code of this file.

Functions

int p_dump (bin_data *x, char *location, char *prepend_fname, data_type_t dt)
 Dumps P-CSCF data to files or DB.
int bin_dump_to_db (bin_data *x, data_type_t dt)
 Dumps P-CSCF data to DB.
int bin_dump_registrar_to_table (bin_data *x, int snapshot_version, int step_version)
 Dumps P-CSCF registrar to DB.
int bin_dump_dialogs_to_table (bin_data *x, int snapshot_version, int step_version)
 Dumps P-CSCF dialogs to DB.
int bin_dump_subs_to_table (bin_data *x, int snapshot_version, int step_version)
 Dumps P-CSCF subscriptions to DB.
int bin_bulk_dump_to_table (data_type_t dt, int snapshot_version, int step_version, bin_data *x)
 Dumps P-CSCF data to the snapshot table.
int bin_cache_dump_registrar_to_table (int snapshot_version, int step_version)
 Dumps P-CSCF registrar to the snapshot table.
int bin_cache_dump_dialogs_to_table (int snapshot_version, int step_version)
 Dumps P-CSCF dialogs to the snapshot table.
int bin_cache_dump_subs_to_table (int snapshot_version, int step_version)
 Dumps P-CSCF subscriptions to the snapshot table.
int delete_older_snapshots (char *table, char *node_id, data_type_t dt, int current_snapshot)
 Drops older subscriptions/dialogs/registrar snapshots, keeping the 'bin_db_keep_count' most recent.
int p_load (bin_data *x, char *location, char *prepend_fname, data_type_t dt)
 Loads P-CSCF data from files or DB.
int bin_load_from_db (bin_data *x, data_type_t dt)
 Loads P-CSCF data from DB.
int bin_load_registrar_from_table (bin_data *x)
 Loads P-CSCF registrar from DB.
int bin_load_dialogs_from_table (bin_data *x)
 Loads P-CSCF dialogs from DB.
int bin_load_subscriptions_from_table (bin_data *x)
 Loads P-CSCF subscriptions from DB.
int bin_bulk_load_from_table (data_type_t dt, bin_data *x)
 Loads P-CSCF data from the snapshot table.
int bin_cache_load_registrar_from_table ()
 Loads P-CSCF registrar from the snapshot table.
int bin_cache_load_dialogs_from_table ()
 Loads P-CSCF dialogs from the snapshot table.
int bin_cache_load_subscriptions_from_table ()
 Loads P-CSCF subscriptions from the snapshot table.
int db_get_last_snapshot_version (char *table, char *node_id, data_type_t dt, int *version)
 Gets the version of the last snapshot dumped to db.
int set_versions (data_type_t dt, int snapshot_version, int step_version)
 Sets the values of the global variables registrar/dialogs/subs_snapshot_version and registrar/dialogs/subs_step_version.
int make_snapshot_dialogs ()
 Creates a snapshots of the dialogs data and then calls the dumping function.
int load_snapshot_dialogs ()
 Loads the dialogs data from the last snapshot.
void persistency_timer_dialogs (unsigned int ticks, void *param)
 Timer callback for persistency dumps.
int make_snapshot_registrar ()
 Creates a snapshots of the registrar and then calls the dumping function.
int load_snapshot_registrar ()
 Loads the registrar data from the last snapshot.
void persistency_timer_registrar (unsigned int ticks, void *param)
 Timer callback for persistency dumps.
int make_snapshot_subscriptions ()
 Creates a snapshots of the subscriptions and then calls the dumping function.
int load_snapshot_subscriptions ()
 Loads the subscriptions data from the last snapshot.
void persistency_timer_subscriptions (unsigned int ticks, void *param)
 Timer callback for persistency dumps.

Variables

persistency_mode_t pcscf_persistency_mode
 the type of persistency
char * pcscf_persistency_location
 where to dump the persistency data
int p_dialogs_hash_size
 size of the dialog hash table
p_dialog_hash_slotp_dialogs
 the hash table
db_con_t * pcscf_db
 Database connection handle.
db_func_t pcscf_dbf
 Structure with pointers to db functions.
int * registrar_snapshot_version
 the version of the next registrar snapshot on the db
int * registrar_step_version
 the step version within the current registrar snapshot version
int * dialogs_snapshot_version
 the version of the next dialogs snapshot on the db
int * dialogs_step_version
 the step version within the current dialogs snapshot version
int * subs_snapshot_version
 the version of the next subscriptions snapshot on the db
int * subs_step_version
 the step version within the current subscriptions snapshot version
gen_lock_t * db_lock
 lock for db access
char * pcscf_name
 SIP URI of this P-CSCF.
int r_hash_size
 Size of P-CSCF registrar hash table.
r_hash_slotregistrar
 The P-CSCF registrar.
int subscriptions_hash_size
 Size of P-CSCF subscriptions hash table.
r_subscription_hash_slotsubscriptions
 The P-CSCF subscriptions.
int bin_db_keep_count = 1
 how many old snapshots to keep


Function Documentation

int p_dump ( bin_data x,
char *  location,
char *  prepend_fname,
data_type_t  dt 
)

Dumps P-CSCF data to files or DB.

Parameters:
x - binary data to dump. Empty if pcscf_persistency_mode==WITH_DATABASE_CACHE. In this case, each hashtable element is serialized and dumped to DB separately.
location -
prepend_fname -
dt - dump registrar, dialogs or susbcriptions
Returns:
1 on success or 0 on failure

Definition at line 374 of file p_persistency.c.

References bin_dump_to_db(), bin_dump_to_file(), M_NAME, NO_PERSISTENCY, NULL, pcscf_persistency_mode, WITH_DATABASE_BULK, WITH_DATABASE_CACHE, and WITH_FILES.

Referenced by make_snapshot_dialogs(), make_snapshot_registrar(), and make_snapshot_subscriptions().

00374                                                                             {
00375     switch (pcscf_persistency_mode){
00376         case NO_PERSISTENCY:
00377             LOG(L_ERR,"ERR:"M_NAME":p_dump: Snapshot done but persistency was disabled...\n");
00378             return 0;
00379         case WITH_FILES:
00380             return bin_dump_to_file(x,location,prepend_fname);
00381         case WITH_DATABASE_BULK:
00382             return bin_dump_to_db(x, dt);
00383         case WITH_DATABASE_CACHE:
00384             return bin_dump_to_db(NULL, dt); //ignore x, x is empty
00385         default:
00386             LOG(L_ERR,"ERR:"M_NAME":p_dump: Snapshot done but no such mode %d\n",pcscf_persistency_mode);
00387             return 0;
00388     }
00389 }

int bin_dump_to_db ( bin_data x,
data_type_t  dt 
)

Dumps P-CSCF data to DB.

Parameters:
x - binary data to dump. NULL if scscf_persistency_mode==WITH_DATABASE_CACHE. In this case, each hashtable element is serialized and dumped to DB separately.
dt - dump registrar, dialogs or auth
Returns:
1 on success or 0 on failure

Definition at line 398 of file p_persistency.c.

References bin_dump_dialogs_to_table(), bin_dump_registrar_to_table(), bin_dump_subs_to_table(), dialogs_snapshot_version, dialogs_step_version, M_NAME, P_DIALOGS, P_REGISTRAR, P_SUBSCRIPTIONS, registrar_snapshot_version, registrar_step_version, subs_snapshot_version, and subs_step_version.

Referenced by p_dump(), and s_dump().

00398                                                {
00399 
00400     int snapshot_version;
00401     int step_version;
00402     
00403     switch(dt){
00404         case P_REGISTRAR:
00405             snapshot_version=*registrar_snapshot_version;
00406             step_version=*registrar_step_version;
00407             return bin_dump_registrar_to_table(x, snapshot_version, step_version);
00408         case P_DIALOGS:
00409             snapshot_version=*dialogs_snapshot_version;
00410             step_version=*dialogs_step_version;
00411             return bin_dump_dialogs_to_table(x, snapshot_version, step_version);
00412         case P_SUBSCRIPTIONS:
00413             snapshot_version=*subs_snapshot_version;
00414             step_version=*subs_step_version;
00415             return bin_dump_subs_to_table(x, snapshot_version, step_version);
00416         default:
00417             LOG(L_ERR,"ERR:"M_NAME":bin_dump_to_db: No such information to dump %d\n", dt);
00418             return 0;
00419     }
00420 }

int bin_dump_registrar_to_table ( bin_data x,
int  snapshot_version,
int  step_version 
)

Dumps P-CSCF registrar to DB.

Parameters:
x - binary data to dump. NULL if scscf_persistency_mode==WITH_DATABASE_CACHE. In this case, each hashtable element is serialized and dumped to DB separately.
snapshot_version - version of the current snapshot
step_version - the step in the current snapshot
Returns:
1 on success or 0 on failure

Definition at line 430 of file p_persistency.c.

References bin_bulk_dump_to_table(), bin_cache_dump_registrar_to_table(), and P_REGISTRAR.

Referenced by bin_dump_to_db().

00430                                                                                     {
00431     
00432     if(x){//whole hashtable serialized to x
00433         return bin_bulk_dump_to_table(P_REGISTRAR, snapshot_version, step_version, x);
00434     }
00435     else{//serialize and dump each hashtable element separately
00436         return bin_cache_dump_registrar_to_table(snapshot_version, step_version);
00437     }
00438 }

int bin_dump_dialogs_to_table ( bin_data x,
int  snapshot_version,
int  step_version 
)

Dumps P-CSCF dialogs to DB.

Parameters:
x - binary data to dump. NULL if scscf_persistency_mode==WITH_DATABASE_CACHE. In this case, each hashtable element is serialized and dumped to DB separately.
snapshot_version - version of the current snapshot
step_version - the step in the current snapshot
Returns:
1 on success or 0 on failure

Definition at line 448 of file p_persistency.c.

References bin_bulk_dump_to_table(), bin_cache_dump_dialogs_to_table(), and P_DIALOGS.

Referenced by bin_dump_to_db().

00448                                                                                   {
00449     
00450     if(x){//whole hashtable serialized to x
00451         return bin_bulk_dump_to_table(P_DIALOGS, snapshot_version, step_version, x);
00452     }
00453     else{//serialize and dump each hashtable element separately
00454         return bin_cache_dump_dialogs_to_table(snapshot_version, step_version);
00455     }
00456 }

int bin_dump_subs_to_table ( bin_data x,
int  snapshot_version,
int  step_version 
)

Dumps P-CSCF subscriptions to DB.

Parameters:
x - binary data to dump. NULL if pcscf_persistency_mode==WITH_DATABASE_CACHE. In this case, each hashtable element is serialized and dumped to DB separately.
snapshot_version - version of the current snapshot
step_version - the step in the current snapshot
Returns:
1 on success or 0 on failure

Definition at line 466 of file p_persistency.c.

References bin_bulk_dump_to_table(), bin_cache_dump_subs_to_table(), and P_SUBSCRIPTIONS.

Referenced by bin_dump_to_db().

00466                                                                                {
00467     
00468     if(x){//whole hashtable serialized to x
00469         return bin_bulk_dump_to_table(P_SUBSCRIPTIONS, snapshot_version, step_version, x);
00470     }
00471     else{//serialize and dump each hashtable element separately
00472         return bin_cache_dump_subs_to_table(snapshot_version, step_version);
00473     }
00474 }

int bin_bulk_dump_to_table ( data_type_t  dt,
int  snapshot_version,
int  step_version,
bin_data x 
)

Dumps P-CSCF data to the snapshot table.

Parameters:
dt - dump registrar, dialogs or auth
snapshot_version - version of the current snapshot
step_version - the step in the current snapshot
x - binary data to dump (the whole hashtable).
Returns:
1 on success or 0 on failure

Definition at line 484 of file p_persistency.c.

References db_lock, delete_older_snapshots(), _bin_data::len, M_NAME, pcscf_db, pcscf_dbf, pcscf_name, and _bin_data::s.

Referenced by bin_dump_auth_to_table(), bin_dump_dialogs_to_table(), bin_dump_registrar_to_table(), and bin_dump_subs_to_table().

00484                                                                                                {
00485     db_key_t keys[5];
00486     db_val_t vals[5];
00487     int len;
00488 
00489     /* id auto incremented */
00490     keys[0] = "node_id";
00491     keys[1] = "data_type";
00492     keys[2] = "snapshot_version";
00493     keys[3] = "step_version";
00494     /* record_id_1/2/3/4=NULL */
00495     keys[4] = "data";
00496     
00497     vals[0].type = DB_STR;
00498     vals[0].nul = 0;
00499     vals[0].val.str_val.s=pcscf_name;
00500     len = strlen(pcscf_name);
00501     vals[0].val.str_val.len=MIN(len, 64);
00502 
00503     vals[1].type = DB_INT;
00504     vals[1].nul = 0;
00505     vals[1].val.int_val=dt;
00506 
00507     vals[2].type = DB_INT;
00508     vals[2].nul = 0;
00509     vals[2].val.int_val=snapshot_version;
00510     
00511     vals[3].type = DB_INT;
00512     vals[3].nul = 0;
00513     vals[3].val.int_val=step_version;
00514 
00515     str d = {x->s, x->len};
00516     vals[4].type = DB_BLOB;
00517     vals[4].nul = 0;
00518     vals[4].val.blob_val = d;
00519 
00520     //lock
00521     lock_get(db_lock);
00522 
00523     if (pcscf_dbf.use_table(pcscf_db, "snapshot") < 0) {
00524         LOG(L_ERR, "ERR:"M_NAME":bin_bulk_dump_to_table(): Error in use_table\n");
00525         lock_release(db_lock);//unlock
00526         return 0;
00527     }
00528 
00529     if (pcscf_dbf.insert(pcscf_db, keys, vals, 5) < 0) {
00530         LOG(L_ERR, "ERR:"M_NAME":bin_bulk_dump_to_table(): Error while inserting on snapshot table\n");
00531         lock_release(db_lock);//unlock
00532         return 0;
00533     }
00534     
00535     //delete older snapshots
00536     if (delete_older_snapshots("snapshot", pcscf_name, dt, snapshot_version)!=1){
00537         LOG(L_ERR, "ERR:"M_NAME":bin_bulk_dump_to_table(): Error while deleting older snapshots from snapshot table\n");
00538         lock_release(db_lock);//unlock
00539         return 0;
00540     }
00541     
00542     //unlock
00543     lock_release(db_lock);
00544     
00545     return 1;
00546 }

int bin_cache_dump_registrar_to_table ( int  snapshot_version,
int  step_version 
)

Dumps P-CSCF registrar to the snapshot table.

Each r_public is serialized and dumped to one row of the table.

Parameters:
snapshot_version - version of the current snapshot
step_version - the step in the current snapshot
Returns:
1 on success or 0 on failure

Definition at line 555 of file p_persistency.c.

References bin_alloc(), bin_encode_r_contact(), bin_free(), db_lock, delete_older_snapshots(), r_hash_slot::head, _r_contact::host, _bin_data::len, M_NAME, _r_contact::next, P_REGISTRAR, pcscf_db, pcscf_dbf, pcscf_name, _r_contact::port, r_hash_size, r_lock(), r_unlock(), registrar, _bin_data::s, and _r_contact::transport.

Referenced by bin_dump_registrar_to_table().

00555                                                                              {
00556     bin_data x;
00557     r_contact *contact;
00558     int i;
00559     int len;
00560     char aux1[10];
00561     char aux2[10];
00562     
00563     //lock
00564     lock_get(db_lock);
00565 
00566     if (pcscf_dbf.use_table(pcscf_db, "snapshot") < 0) {
00567         LOG(L_ERR, "ERR:"M_NAME":bin_cache_dump_registrar_to_table(): Error in use_table\n");
00568         goto error;
00569     }
00570     
00571     for(i=0;i<r_hash_size;i++){
00572         r_lock(i);
00573         contact = registrar[i].head;
00574         while(contact){
00575             if (!bin_alloc(&x,128)){
00576                 r_unlock(i);
00577                 goto error;
00578             }
00579             if (!bin_encode_r_contact(&x,contact)){
00580                 r_unlock(i);
00581                 goto error;
00582             }
00583             
00584             db_key_t keys[8];
00585             db_val_t vals[8];
00586             
00587             /* id auto incremented */
00588             keys[0] = "node_id";
00589             keys[1] = "data_type";
00590             keys[2] = "snapshot_version";
00591             keys[3] = "step_version";
00592             keys[4] = "record_id_1"; /* host */
00593             keys[5] = "record_id_2"; /* port */
00594             keys[6] = "record_id_3"; /* transport */
00595             /* record_id_4=NULL */
00596             keys[7] = "data";
00597             
00598             vals[0].type = DB_STR;
00599             vals[0].nul = 0;
00600             vals[0].val.str_val.s=pcscf_name;
00601             len = strlen(pcscf_name);
00602             vals[0].val.str_val.len=MIN(len, 64);
00603 
00604             vals[1].type = DB_INT;
00605             vals[1].nul = 0;
00606             vals[1].val.int_val=P_REGISTRAR;
00607 
00608             vals[2].type = DB_INT;
00609             vals[2].nul = 0;
00610             vals[2].val.int_val=snapshot_version;
00611     
00612             vals[3].type = DB_INT;
00613             vals[3].nul = 0;
00614             vals[3].val.int_val=step_version;
00615     
00616             vals[4].type = DB_STR;
00617             vals[4].nul = 0;
00618             vals[4].val.str_val.s=contact->host.s;
00619             vals[4].val.str_val.len=MIN(contact->host.len, 256);
00620             
00621             vals[5].type = DB_STR;
00622             vals[5].nul = 0;
00623             sprintf(aux1, "%d", contact->port);
00624             vals[5].val.str_val.s=aux1;
00625             vals[5].val.str_val.len=strlen(aux1);
00626     
00627             vals[6].type = DB_STR;
00628             vals[6].nul = 0;
00629             sprintf(aux2, "%d", contact->transport);
00630             vals[6].val.str_val.s=aux2;
00631             vals[6].val.str_val.len=strlen(aux2);
00632         
00633             vals[7].type = DB_BLOB;
00634             vals[7].nul = 0;
00635             str data={x.s, x.len};
00636             vals[7].val.blob_val = data;
00637             
00638             if (pcscf_dbf.insert(pcscf_db, keys, vals, 8) < 0) {
00639                 LOG(L_ERR, "ERR:"M_NAME":bin_cache_dump_registrar_to_table(): Error while inserting on snapshot table\n");
00640                 r_unlock(i);
00641                 goto error;
00642             }
00643             bin_free(&x);
00644             
00645             contact = contact->next;
00646         }
00647         r_unlock(i);
00648     }   
00649     
00650     //delete older snapshots
00651     if (delete_older_snapshots("snapshot", pcscf_name, P_REGISTRAR, snapshot_version)!=1){
00652         LOG(L_ERR, "ERR:"M_NAME":bin_cache_dump_registrar_to_table(): Error while deleting older snapshots from snapshot table\n");
00653         goto error;
00654     }
00655     
00656     //unlock
00657     lock_release(db_lock);
00658     
00659     return 1;
00660 
00661 error:
00662     lock_release(db_lock);//unlock
00663     return 0;
00664 }

int bin_cache_dump_dialogs_to_table ( int  snapshot_version,
int  step_version 
)

Dumps P-CSCF dialogs to the snapshot table.

Each dialog is serialized and dumped to one row of the table.

Parameters:
snapshot_version - version of the current snapshot
step_version - the step in the current snapshot
Returns:
1 on success or 0 on failure

Definition at line 673 of file p_persistency.c.

References bin_alloc(), bin_encode_p_dialog(), bin_free(), _p_dialog::call_id, d_lock(), d_unlock(), db_lock, delete_older_snapshots(), p_dialog_hash_slot::head, _p_dialog::host, _bin_data::len, M_NAME, _p_dialog::next, P_DIALOGS, p_dialogs, p_dialogs_hash_size, pcscf_db, pcscf_dbf, pcscf_name, _p_dialog::port, _bin_data::s, and _p_dialog::transport.

Referenced by bin_dump_dialogs_to_table().

00673                                                                            {
00674     bin_data x;
00675     p_dialog *dialog;
00676     int i;
00677     int len;
00678     char aux1[10];
00679     char aux2[10];
00680     
00681     //lock
00682     lock_get(db_lock);
00683 
00684     if (pcscf_dbf.use_table(pcscf_db, "snapshot") < 0) {
00685         LOG(L_ERR, "ERR:"M_NAME":bin_cache_dump_dialogs_to_table(): Error in use_table\n");
00686         goto error;
00687     }
00688     
00689     for(i=0;i<p_dialogs_hash_size;i++){
00690         d_lock(i);
00691         dialog = p_dialogs[i].head;
00692         while(dialog){
00693             if (!bin_alloc(&x,128)){
00694                 d_unlock(i);
00695                 goto error;
00696             }
00697             if (!bin_encode_p_dialog(&x,dialog)){
00698                 d_unlock(i);
00699                 goto error;
00700             }
00701             
00702             db_key_t keys[9];
00703             db_val_t vals[9];
00704             
00705             /* id auto incremented */
00706             keys[0] = "node_id";
00707             keys[1] = "data_type";
00708             keys[2] = "snapshot_version";
00709             keys[3] = "step_version";
00710             keys[4] = "record_id_1"; /* call-id */
00711             keys[5] = "record_id_2"; /* host */
00712             keys[6] = "record_id_3"; /* port */
00713             keys[7] = "record_id_4"; /* transport */
00714             keys[8] = "data";
00715             
00716             vals[0].type = DB_STR;
00717             vals[0].nul = 0;
00718             vals[0].val.str_val.s=pcscf_name;
00719             len = strlen(pcscf_name);
00720             vals[0].val.str_val.len=MIN(len, 64);
00721 
00722             vals[1].type = DB_INT;
00723             vals[1].nul = 0;
00724             vals[1].val.int_val=P_DIALOGS;
00725 
00726             vals[2].type = DB_INT;
00727             vals[2].nul = 0;
00728             vals[2].val.int_val=snapshot_version;
00729     
00730             vals[3].type = DB_INT;
00731             vals[3].nul = 0;
00732             vals[3].val.int_val=step_version;
00733     
00734             vals[4].type = DB_STR;
00735             vals[4].nul = 0;
00736             vals[4].val.str_val.s=dialog->call_id.s;
00737             vals[4].val.str_val.len=MIN(dialog->call_id.len, 256);
00738     
00739             vals[5].type = DB_STR;
00740             vals[5].nul = 0;
00741             vals[5].val.str_val.s=dialog->host.s;
00742             vals[5].val.str_val.len=MIN(dialog->host.len, 256);
00743             
00744             vals[6].type = DB_STR;
00745             vals[6].nul = 0;
00746             sprintf(aux1, "%d", dialog->port);
00747             vals[6].val.str_val.s=aux1;
00748             vals[6].val.str_val.len=strlen(aux1);
00749     
00750             vals[7].type = DB_STR;
00751             vals[7].nul = 0;
00752             sprintf(aux2, "%d", dialog->transport);
00753             vals[7].val.str_val.s=aux2;
00754             vals[7].val.str_val.len=strlen(aux2);
00755     
00756             vals[8].type = DB_BLOB;
00757             vals[8].nul = 0;
00758             str data={x.s, x.len};
00759             vals[8].val.blob_val = data;
00760             
00761             if (pcscf_dbf.insert(pcscf_db, keys, vals, 9) < 0) {
00762                 LOG(L_ERR, "ERR:"M_NAME":bin_cache_dump_dialogs_to_table(): Error while inserting on snapshot table\n");
00763                 d_unlock(i);
00764                 goto error;
00765             }
00766             bin_free(&x);
00767             
00768             dialog = dialog->next;
00769         }
00770         d_unlock(i);
00771     }   
00772     
00773     //delete older snapshots
00774     if (delete_older_snapshots("snapshot", pcscf_name, P_DIALOGS, snapshot_version)!=1){
00775         LOG(L_ERR, "ERR:"M_NAME":bin_cache_dump_dialogs_to_table(): Error while deleting older snapshots from snapshot table\n");
00776         goto error;
00777     }
00778     
00779     //unlock
00780     lock_release(db_lock);
00781     
00782     return 1;
00783 
00784 error:
00785     lock_release(db_lock);//unlock
00786     return 0;
00787 }

int bin_cache_dump_subs_to_table ( int  snapshot_version,
int  step_version 
)

Dumps P-CSCF subscriptions to the snapshot table.

Each subscription is serialized and dumped to one row of the table.

Parameters:
snapshot_version - version of the current snapshot
step_version - the step in the current snapshot
Returns:
1 on success or 0 on failure

Definition at line 796 of file p_persistency.c.

References bin_alloc(), bin_encode_r_subscription(), bin_free(), db_lock, delete_older_snapshots(), r_subscription_hash_slot::head, _bin_data::len, M_NAME, _r_subscription::next, P_SUBSCRIPTIONS, pcscf_db, pcscf_dbf, pcscf_name, _r_subscription::req_uri, _bin_data::s, subs_lock(), subs_unlock(), subscriptions, and subscriptions_hash_size.

Referenced by bin_dump_subs_to_table().

00796                                                                         {
00797     bin_data x;
00798     r_subscription *sub;
00799     int i;
00800     int len;
00801     
00802     //lock
00803     lock_get(db_lock);
00804 
00805     if (pcscf_dbf.use_table(pcscf_db, "snapshot") < 0) {
00806         LOG(L_ERR, "ERR:"M_NAME":bin_cache_dump_subs_to_table(): Error in use_table\n");
00807         goto error;
00808     }
00809     
00810     for(i=0;i<subscriptions_hash_size;i++){
00811         subs_lock(i);
00812         sub = subscriptions[i].head;
00813         while(sub){
00814             if (!bin_alloc(&x,128)){
00815                 subs_unlock(i);
00816                 goto error;
00817             }
00818             if (!bin_encode_r_subscription(&x,sub)){
00819                 subs_unlock(i);
00820                 goto error;
00821             }
00822             
00823             db_key_t keys[6];
00824             db_val_t vals[6];
00825             
00826             /* id auto incremented */
00827             keys[0] = "node_id";
00828             keys[1] = "data_type";
00829             keys[2] = "snapshot_version";
00830             keys[3] = "step_version";
00831             keys[4] = "record_id_1"; /* req_uri */
00832             /* record_id_2/3/4=NULL*/
00833             keys[5] = "data";
00834             
00835             vals[0].type = DB_STR;
00836             vals[0].nul = 0;
00837             vals[0].val.str_val.s=pcscf_name;
00838             len = strlen(pcscf_name);
00839             vals[0].val.str_val.len=MIN(len, 64);
00840 
00841             vals[1].type = DB_INT;
00842             vals[1].nul = 0;
00843             vals[1].val.int_val=P_SUBSCRIPTIONS;
00844 
00845             vals[2].type = DB_INT;
00846             vals[2].nul = 0;
00847             vals[2].val.int_val=snapshot_version;
00848     
00849             vals[3].type = DB_INT;
00850             vals[3].nul = 0;
00851             vals[3].val.int_val=step_version;
00852     
00853             vals[4].type = DB_STR;
00854             vals[4].nul = 0;
00855             vals[4].val.str_val.s=sub->req_uri.s;
00856             vals[4].val.str_val.len=MIN(sub->req_uri.len, 256);
00857     
00858             vals[5].type = DB_BLOB;
00859             vals[5].nul = 0;
00860             str data={x.s, x.len};
00861             vals[5].val.blob_val = data;
00862             
00863             if (pcscf_dbf.insert(pcscf_db, keys, vals, 6) < 0) {
00864                 LOG(L_ERR, "ERR:"M_NAME":bin_cache_dump_subscriptions_to_table(): Error while inserting on snapshot table\n");
00865                 subs_unlock(i);
00866                 goto error;
00867             }
00868             bin_free(&x);
00869             
00870             sub = sub->next;
00871         }
00872         subs_unlock(i);
00873     }   
00874     
00875     //delete older snapshots
00876     if (delete_older_snapshots("snapshot", pcscf_name, P_SUBSCRIPTIONS, snapshot_version)!=1){
00877         LOG(L_ERR, "ERR:"M_NAME":bin_cache_dump_subscriptions_to_table(): Error while deleting older snapshots from snapshot table\n");
00878         goto error;
00879     }
00880     
00881     //unlock
00882     lock_release(db_lock);
00883     
00884     return 1;
00885 
00886 error:
00887     lock_release(db_lock);//unlock
00888     return 0;
00889 }

int delete_older_snapshots ( char *  table,
char *  node_id,
data_type_t  dt,
int  current_snapshot 
)

Drops older subscriptions/dialogs/registrar snapshots, keeping the 'bin_db_keep_count' most recent.

Parameters:
table - where to drop.
node_id - cscf id
dt - which data to drop
current_snapshot_version - version of the current snapshot
Returns:
1 on success or 0 on failure

Definition at line 903 of file p_persistency.c.

References bin_db_keep_count, M_NAME, pcscf_db, and pcscf_dbf.

Referenced by bin_bulk_dump_to_table(), bin_cache_dump_auth_to_table(), bin_cache_dump_dialogs_to_table(), bin_cache_dump_registrar_to_table(), and bin_cache_dump_subs_to_table().

00903                                                                                             {
00904 
00905     db_key_t query_cols[3];
00906     db_op_t  query_ops[3];
00907     db_val_t query_vals[3];
00908     int len;
00909 
00910     query_cols[0] = "snapshot_version";
00911     query_ops[0] = OP_LEQ;
00912     query_vals[0].type = DB_INT;
00913     query_vals[0].nul = 0;
00914     query_vals[0].val.int_val = current_snapshot - bin_db_keep_count;
00915     
00916     query_cols[1] = "node_id";
00917     query_ops[1] = OP_EQ;
00918     query_vals[1].type = DB_STR;
00919     query_vals[1].nul = 0;
00920     len = strlen(node_id);
00921     query_vals[1].val.str_val.s=node_id;
00922     query_vals[1].val.str_val.len=MIN(len, 256);
00923     
00924     query_cols[2] = "data_type";
00925     query_ops[2] = OP_EQ;
00926     query_vals[2].type = DB_INT;
00927     query_vals[2].nul = 0;
00928     query_vals[2].val.int_val = dt;
00929 
00930     if (pcscf_dbf.use_table(pcscf_db, table) < 0) {
00931         LOG(L_ERR, "ERR:"M_NAME":delete_older_snapshots(): Error in use_table\n");
00932         return 0;
00933     }
00934 
00935     if (pcscf_dbf.delete(pcscf_db, query_cols, query_ops, query_vals, 3) < 0) {
00936         LOG(L_ERR, "ERR:"M_NAME":delete_older_snapshots(): Error while deleting older snapshots\n");
00937         return 0;
00938     }
00939     
00940     return 1;
00941 }

int p_load ( bin_data x,
char *  location,
char *  prepend_fname,
data_type_t  dt 
)

Loads P-CSCF data from files or DB.

Parameters:
x - destination of the loaded data. Empty if pcscf_persistency_mode==WITH_DATABASE_CACHE. In this case, each row of the table is loaded and placed on the hashtable now, instead of to be passed to load_snapshot_...() function, which does this work when the whole hashtable was dumped to only one row of the table.
location -
prepend_fname -
dt - load registrar, dialogs or susbcriptions
Returns:
1 on success or 0 on failure

Definition at line 956 of file p_persistency.c.

References bin_load_from_db(), bin_load_from_file(), M_NAME, NO_PERSISTENCY, NULL, pcscf_persistency_mode, WITH_DATABASE_BULK, WITH_DATABASE_CACHE, and WITH_FILES.

Referenced by load_snapshot_dialogs(), load_snapshot_registrar(), and load_snapshot_subscriptions().

00956                                                                             {
00957     switch (pcscf_persistency_mode){
00958         case NO_PERSISTENCY:
00959             LOG(L_ERR,"ERR:"M_NAME":p_load: Persistency support was disabled\n");
00960             return 0;
00961         case WITH_FILES:
00962             return bin_load_from_file(x,location,prepend_fname);        
00963         case WITH_DATABASE_BULK:
00964             return bin_load_from_db(x, dt);
00965         case WITH_DATABASE_CACHE:
00966             return bin_load_from_db(NULL, dt); //ignore x, x is empty
00967         default:
00968             LOG(L_ERR,"ERR:"M_NAME":p_load: Can't resume because no such mode %d\n",pcscf_persistency_mode);
00969             return 0;
00970     }
00971 }

int bin_load_from_db ( bin_data x,
data_type_t  dt 
)

Loads P-CSCF data from DB.

Parameters:
x - Destination of the data.
dt - load registrar, dialogs or auth
Returns:
1 on success or 0 on failure

Definition at line 979 of file p_persistency.c.

References bin_load_dialogs_from_table(), bin_load_registrar_from_table(), bin_load_subscriptions_from_table(), M_NAME, P_DIALOGS, P_REGISTRAR, and P_SUBSCRIPTIONS.

Referenced by p_load(), and s_load().

00979                                                  {
00980     switch(dt){
00981         case P_REGISTRAR:
00982             return bin_load_registrar_from_table(x);
00983         case P_DIALOGS:
00984             return bin_load_dialogs_from_table(x);
00985         case P_SUBSCRIPTIONS:
00986             return bin_load_subscriptions_from_table(x);
00987         default:
00988             LOG(L_ERR,"ERR:"M_NAME":bin_load_from_db: No such information to load %d\n", dt);
00989             return 0;
00990     }
00991 }

int bin_load_registrar_from_table ( bin_data x  ) 

Loads P-CSCF registrar from DB.

Parameters:
x - Destination of the data
Returns:
1 on success or 0 on failure

Definition at line 998 of file p_persistency.c.

References bin_bulk_load_from_table(), bin_cache_load_registrar_from_table(), and P_REGISTRAR.

Referenced by bin_load_from_db().

00998                                               {
00999     if(x){//whole hashtable dumped to db
01000         return bin_bulk_load_from_table(P_REGISTRAR, x);
01001     }
01002     else{//each hashtable element dumped to DB separately
01003         return bin_cache_load_registrar_from_table();
01004     }
01005 }

int bin_load_dialogs_from_table ( bin_data x  ) 

Loads P-CSCF dialogs from DB.

Parameters:
x - Destination of the data
Returns:
1 on success or 0 on failure

Definition at line 1012 of file p_persistency.c.

References bin_bulk_load_from_table(), bin_cache_load_dialogs_from_table(), and P_DIALOGS.

Referenced by bin_load_from_db().

01012                                             {
01013     if(x){//whole hashtable dumped to db
01014         return bin_bulk_load_from_table(P_DIALOGS, x);
01015     }
01016     else{//each hashtable element dumped to DB separately
01017         return bin_cache_load_dialogs_from_table();
01018     }
01019 }

int bin_load_subscriptions_from_table ( bin_data x  ) 

Loads P-CSCF subscriptions from DB.

Parameters:
x - Destination of the data
Returns:
1 on success or 0 on failure

Definition at line 1026 of file p_persistency.c.

References bin_bulk_load_from_table(), bin_cache_load_subscriptions_from_table(), and P_SUBSCRIPTIONS.

Referenced by bin_load_from_db().

01026                                                   {
01027     if(x){//whole hashtable dumped to db
01028         return bin_bulk_load_from_table(P_SUBSCRIPTIONS, x);
01029     }
01030     else{//each hashtable element dumped to DB separately
01031         return bin_cache_load_subscriptions_from_table();
01032     }
01033 }

int bin_bulk_load_from_table ( data_type_t  dt,
bin_data x 
)

Loads P-CSCF data from the snapshot table.

Parameters:
dt - load registrar, dialogs or auth
x - where to load
Returns:
1 on success or 0 on failure

Definition at line 1041 of file p_persistency.c.

References bin_alloc(), bin_expand(), db_get_last_snapshot_version(), db_lock, _bin_data::len, M_NAME,