diff --git a/modules/usrloc/dlist.c b/modules/usrloc/dlist.c index 76aa6c8cdcf..1a95cc64286 100644 --- a/modules/usrloc/dlist.c +++ b/modules/usrloc/dlist.c @@ -46,6 +46,12 @@ /*! \brief Global list of all registered domains */ dlist_t* root = 0; +unsigned int _ul_max_partition = 0; + +void ul_set_max_partition(unsigned int m) +{ + _ul_max_partition = m; +} /*! * \brief Find domain with the given name @@ -102,11 +108,11 @@ static inline int get_all_db_ucontacts(void *buf, int len, unsigned int flags, int i; void *cp; int shortage, needed; - db_key_t keys1[2]; /* where */ - db_val_t vals1[2]; - db_op_t ops[2]; + db_key_t keys1[3]; /* where */ + db_val_t vals1[3]; + db_op_t ops1[3]; db_key_t keys2[6]; /* select */ - int n[2] = {1,6}; /* number of dynamic values used on key1/key2 */ + int n[2] = {2,6}; /* number of dynamic values used on key1/key2 */ cp = buf; shortage = 0; @@ -132,14 +138,23 @@ static inline int get_all_db_ucontacts(void *buf, int len, unsigned int flags, /* where fields */ keys1[0] = &expires_col; - ops[0] = OP_GT; + ops1[0] = OP_GT; vals1[0].type = DB1_STR; vals1[0].nul = 0; vals1[0].val.str_val = now; + keys1[1] = &partition_col; + ops1[1] = OP_EQ; + vals1[1].type = DB1_INT; + vals1[1].nul = 0; + if(_ul_max_partition>0) + vals1[1].val.int_val = part_idx; + else + vals1[1].val.int_val = 0; + if (flags & nat_bflag) { keys1[n[0]] = &keepalive_col; - ops[n[0]] = OP_EQ; + ops1[n[0]] = OP_EQ; vals1[n[0]].type = DB1_INT; vals1[n[0]].nul = 0; vals1[n[0]].val.int_val = 1; @@ -153,7 +168,7 @@ static inline int get_all_db_ucontacts(void *buf, int len, unsigned int flags, LM_ERR("sql use_table failed\n"); return -1; } - if (ul_dbf.query(ul_dbh, keys1,ops, vals1, keys2, + if (ul_dbf.query(ul_dbh, keys1, ops1, vals1, keys2, n[0], n[1], NULL, &res) <0 ) { LM_ERR("query error\n"); return -1; diff --git a/modules/usrloc/dlist.h b/modules/usrloc/dlist.h index e95a9171255..9b8b84c91e6 100644 --- a/modules/usrloc/dlist.h +++ b/modules/usrloc/dlist.h @@ -140,4 +140,9 @@ unsigned long get_number_of_users(void); int find_domain(str* _d, udomain_t** _p); +/*! + * \brief Set the value for max partition + */ +void ul_set_max_partition(unsigned int m); + #endif diff --git a/modules/usrloc/ucontact.c b/modules/usrloc/ucontact.c index b1ba8d922e0..8bd8c391b90 100644 --- a/modules/usrloc/ucontact.c +++ b/modules/usrloc/ucontact.c @@ -458,6 +458,9 @@ int st_flush_ucontact(ucontact_t* _c) /* ============== Database related functions ================ */ +extern unsigned int _ul_max_partition; +static unsigned int _ul_partition_counter = 0; + /*! * \brief Insert contact into the database * \param _c inserted contact @@ -466,8 +469,8 @@ int st_flush_ucontact(ucontact_t* _c) int db_insert_ucontact(ucontact_t* _c) { char* dom; - db_key_t keys[21]; - db_val_t vals[21]; + db_key_t keys[22]; + db_val_t vals[22]; int nr_cols; if (_c->flags & FL_MEM) { @@ -642,6 +645,18 @@ int db_insert_ucontact(ucontact_t* _c) vals[nr_cols].val.int_val = (int)_c->keepalive; nr_cols++; + keys[nr_cols] = &partition_col; + vals[nr_cols].type = DB1_INT; + vals[nr_cols].nul = 0; + if(_ul_max_partition>0) { + vals[nr_cols].val.int_val = ((_ul_partition_counter++) + my_pid()) + % _ul_max_partition; + } else { + vals[nr_cols].val.int_val = 0; + } + nr_cols++; + + if (use_domain) { keys[nr_cols] = &domain_col; vals[nr_cols].type = DB1_STR; diff --git a/modules/usrloc/ul_mod.c b/modules/usrloc/ul_mod.c index c5e95f87c09..1ad69e37289 100644 --- a/modules/usrloc/ul_mod.c +++ b/modules/usrloc/ul_mod.c @@ -81,6 +81,7 @@ MODULE_VERSION #define SRV_ID_COL "server_id" #define CON_ID_COL "connection_id" #define KEEPALIVE_COL "keepalive" +#define PARTITION_COL "partition" #define ULATTRS_USER_COL "username" #define ULATTRS_DOMAIN_COL "domain" @@ -143,6 +144,7 @@ str last_mod_col = str_init(LAST_MOD_COL); /*!< Name of column containing the str srv_id_col = str_init(SRV_ID_COL); /*!< Name of column containing the server id value */ str con_id_col = str_init(CON_ID_COL); /*!< Name of column containing the connection id value */ str keepalive_col = str_init(KEEPALIVE_COL); /*!< Name of column containing the keepalive value */ +str partition_col = str_init(PARTITION_COL); /*!< Name of column containing the partition value */ str ulattrs_user_col = str_init(ULATTRS_USER_COL); /*!< Name of column containing username */ str ulattrs_domain_col = str_init(ULATTRS_DOMAIN_COL); /*!< Name of column containing domain */ diff --git a/modules/usrloc/ul_mod.h b/modules/usrloc/ul_mod.h index bbec4279b3a..7dd28c7ac3a 100644 --- a/modules/usrloc/ul_mod.h +++ b/modules/usrloc/ul_mod.h @@ -61,6 +61,7 @@ extern str reg_id_col; extern str srv_id_col; extern str con_id_col; extern str keepalive_col; +extern str partition_col; extern str last_mod_col; extern str ulattrs_user_col; diff --git a/modules/usrloc/usrloc.c b/modules/usrloc/usrloc.c index b350fc157da..0ac3d73047e 100644 --- a/modules/usrloc/usrloc.c +++ b/modules/usrloc/usrloc.c @@ -74,6 +74,7 @@ int bind_usrloc(usrloc_api_t* api) api->set_keepalive_timeout = ul_set_keepalive_timeout; api->refresh_keepalive = ul_refresh_keepalive; + api->set_max_partition = ul_set_max_partition; api->use_domain = use_domain; api->db_mode = db_mode; diff --git a/modules/usrloc/usrloc.h b/modules/usrloc/usrloc.h index 8a4e9fc12c1..5688e8cfded 100644 --- a/modules/usrloc/usrloc.h +++ b/modules/usrloc/usrloc.h @@ -194,6 +194,9 @@ int ul_set_keepalive_timeout(int _to); typedef int (*ul_refresh_keepalive_t)(unsigned int _aorhash, str *_ruid); int ul_refresh_keepalive(unsigned int _aorhash, str *_ruid); + +typedef void (*ul_set_max_partition_t)(unsigned int m); + /*! usrloc API export structure */ typedef struct usrloc_api { int use_domain; /*! use_domain module parameter */ @@ -226,6 +229,7 @@ typedef struct usrloc_api { ul_set_keepalive_timeout_t set_keepalive_timeout; ul_refresh_keepalive_t refresh_keepalive; + ul_set_max_partition_t set_max_partition; } usrloc_api_t;