Skip to content

Commit

Permalink
No more empty sets in the cached data. mi_reload per partition now po…
Browse files Browse the repository at this point in the history
…ssible
  • Loading branch information
andrei-datcu committed Jul 9, 2014
1 parent 114d570 commit 7a58426
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
15 changes: 11 additions & 4 deletions modules/dispatcher/dispatch.c
Expand Up @@ -181,9 +181,6 @@ int add_dest2list(int id, str uri, struct socket_info *sock, int state,
}

memset(sp, 0, sizeof(ds_set_t));
sp->next = d_data->sets;
d_data->sets = sp;
d_data->sets_no++;
sp->id = id;
}

Expand Down Expand Up @@ -274,6 +271,11 @@ int add_dest2list(int id, str uri, struct socket_info *sock, int state,
}
sp->nr++;


sp->next = d_data->sets;
d_data->sets = sp;
d_data->sets_no++;

LM_DBG("dest [%d/%d] <%.*s> successfully loaded\n", sp->id, sp->nr, dp->uri.len, dp->uri.s);

return 0;
Expand All @@ -285,6 +287,10 @@ int add_dest2list(int id, str uri, struct socket_info *sock, int state,
shm_free(dp->uri.s);
shm_free(dp);
}

if (sp != NULL)
shm_free(sp);

return -1;
}

Expand Down Expand Up @@ -771,7 +777,7 @@ static ds_data_t* ds_load_data(ds_partition_t *partition)
}

if (cnt==0) {
LM_WARN("No record loaded from db, running on empty set\n");
LM_WARN("No record loaded from db, running on empty sets\n");
} else {
if(reindex_dests( d_data )!=0) {
LM_ERR("error on reindex\n");
Expand All @@ -787,6 +793,7 @@ static ds_data_t* ds_load_data(ds_partition_t *partition)
ds_destroy_data_set( d_data );
return NULL;
error2:
ds_destroy_data_set( d_data );
partition->dbf.free_result(*partition->db_handle, res);
return NULL;
}
Expand Down
15 changes: 14 additions & 1 deletion modules/dispatcher/dispatcher.c
Expand Up @@ -903,7 +903,7 @@ static void destroy(void)
free_int_list(_list_ ## _exp_start, _list_ ## _exp_end);\
_list_ ## _exp_start = NULL; \
}\
} while (0);
} while (0)

/**
*
Expand Down Expand Up @@ -1259,9 +1259,22 @@ static struct mi_root* ds_mi_list(struct mi_root* cmd_tree, void* param)
#define MI_ERR_RELOAD_LEN (sizeof(MI_ERR_RELOAD)-1)
#define MI_NOT_SUPPORTED "DB mode not configured"
#define MI_NOT_SUPPORTED_LEN (sizeof(MI_NOT_SUPPORTED)-1)
#define MI_UNK_PARTITION "ERROR Unknown partition"
#define MI_UNK_PARTITION_LEN (sizeof(MI_UNK_PARTITION) - 1)

static struct mi_root* ds_mi_reload(struct mi_root* cmd_tree, void* param)
{
struct mi_node* node = cmd_tree->node.kids;
if(node != NULL){
ds_partition_t *partition = find_partition_by_name(&node->value);
if (partition == NULL)
return init_mi_tree(500, MI_UNK_PARTITION, MI_UNK_PARTITION_LEN);
if (ds_reload_db(partition) < 0)
return init_mi_tree(500, MI_ERR_RELOAD, MI_ERR_RELOAD_LEN);
else
return init_mi_tree(200, MI_OK_S, MI_OK_LEN);
}

ds_partition_t *part_it;
for (part_it = partitions; part_it; part_it = part_it->next)
if (ds_reload_db(part_it)<0)
Expand Down

0 comments on commit 7a58426

Please sign in to comment.