Made the handling of listing and unlisting opened columns and indexers
functions in the obidms files.
This commit is contained in:
125
src/obiavl.c
125
src/obiavl.c
@ -969,7 +969,7 @@ int add_new_avl_in_group(OBIDMS_avl_group_p avl_group)
|
||||
(avl_group->current_avl_idx)++;
|
||||
|
||||
// Create the new AVL
|
||||
(avl_group->sub_avls)[avl_group->current_avl_idx] = obi_create_avl(avl_group->dms, avl_group->avl_name, avl_group->current_avl_idx);
|
||||
(avl_group->sub_avls)[avl_group->current_avl_idx] = obi_create_avl(avl_group->dms, avl_group->name, avl_group->current_avl_idx);
|
||||
if ((avl_group->sub_avls)[avl_group->current_avl_idx] == NULL)
|
||||
{
|
||||
obidebug(1, "\nError creating a new AVL tree in a group");
|
||||
@ -1611,11 +1611,6 @@ OBIDMS_avl_p obi_create_avl(OBIDMS_p dms, const char* avl_name, int avl_idx)
|
||||
// Bloom filter
|
||||
bloom_init(&((avl->header)->bloom_filter), MAX_NODE_COUNT_PER_AVL);
|
||||
|
||||
// Add in the list of opened AVL trees
|
||||
*(((dms->opened_indexers)->indexers)+((dms->opened_indexers)->nb_opened_indexers)) = avl;
|
||||
((dms->opened_indexers)->nb_opened_indexers)++;
|
||||
avl->counter = 1;
|
||||
|
||||
if (avl_idx >= 0)
|
||||
free(complete_avl_name);
|
||||
|
||||
@ -1636,7 +1631,6 @@ OBIDMS_avl_p obi_open_avl(OBIDMS_p dms, const char* avl_name, int avl_idx)
|
||||
int avl_dir_file_descriptor;
|
||||
OBIDMS_avl_data_p avl_data;
|
||||
OBIDMS_avl_p avl;
|
||||
size_t i;
|
||||
|
||||
// Get complete name of AVL if index
|
||||
if (avl_idx >= 0)
|
||||
@ -1657,18 +1651,6 @@ OBIDMS_avl_p obi_open_avl(OBIDMS_p dms, const char* avl_name, int avl_idx)
|
||||
strcpy(complete_avl_name, avl_name);
|
||||
}
|
||||
|
||||
// Check if the AVL tree is already in the list of opened AVL trees
|
||||
for (i=0; i < ((dms->opened_indexers)->nb_opened_indexers); i++)
|
||||
{
|
||||
if (!strcmp(((*(((dms->opened_indexers)->indexers)+i))->header)->avl_name, complete_avl_name))
|
||||
{ // Found the AVL tree already opened
|
||||
((*(((dms->opened_indexers)->indexers)+i))->counter)++;
|
||||
if (avl_idx >= 0)
|
||||
free(complete_avl_name);
|
||||
return *(((dms->opened_indexers)->indexers)+i);
|
||||
}
|
||||
}
|
||||
|
||||
// Open the AVL directory
|
||||
avl_dir_name = get_full_path_of_avl_dir(dms, avl_name);
|
||||
if (avl_dir_name == NULL)
|
||||
@ -1877,11 +1859,6 @@ OBIDMS_avl_p obi_open_avl(OBIDMS_p dms, const char* avl_name, int avl_idx)
|
||||
avl->dir_fd = avl_dir_file_descriptor;
|
||||
avl->avl_fd = avl_file_descriptor;
|
||||
|
||||
// Add in the list of opened AVL trees
|
||||
*(((dms->opened_indexers)->indexers)+((dms->opened_indexers)->nb_opened_indexers)) = avl;
|
||||
((dms->opened_indexers)->nb_opened_indexers)++;
|
||||
avl->counter = 1;
|
||||
|
||||
if (avl_idx >= 0)
|
||||
free(complete_avl_name);
|
||||
|
||||
@ -1929,10 +1906,16 @@ OBIDMS_avl_group_p obi_create_avl_group(OBIDMS_p dms, const char* avl_name)
|
||||
}
|
||||
|
||||
avl_group->current_avl_idx = 0;
|
||||
strcpy(avl_group->avl_name, avl_name);
|
||||
strcpy(avl_group->name, avl_name);
|
||||
|
||||
avl_group->dms = dms;
|
||||
|
||||
// Add in the list of open indexers
|
||||
obi_dms_list_indexer(dms, avl_group);
|
||||
|
||||
// Set counter to 1
|
||||
avl_group->counter = 1;
|
||||
|
||||
return avl_group;
|
||||
}
|
||||
|
||||
@ -1944,7 +1927,14 @@ OBIDMS_avl_group_p obi_open_avl_group(OBIDMS_p dms, const char* avl_name)
|
||||
int avl_count;
|
||||
int i;
|
||||
|
||||
// TODO check that the group isn't already open
|
||||
// Check if the group isn't already open
|
||||
avl_group = obi_dms_get_indexer_from_list(dms, avl_name);
|
||||
if (avl_group != NULL) // Found it
|
||||
{
|
||||
// Increment counter
|
||||
(avl_group->counter)++;
|
||||
return avl_group;
|
||||
}
|
||||
|
||||
avl_group = (OBIDMS_avl_group_p) malloc(sizeof(OBIDMS_avl_group_t));
|
||||
if (avl_group == NULL)
|
||||
@ -1973,10 +1963,16 @@ OBIDMS_avl_group_p obi_open_avl_group(OBIDMS_p dms, const char* avl_name)
|
||||
return NULL;
|
||||
}
|
||||
avl_group->current_avl_idx = avl_count-1; // TODO latest. discuss
|
||||
strcpy(avl_group->avl_name, avl_name);
|
||||
strcpy(avl_group->name, avl_name);
|
||||
|
||||
avl_group->dms = dms;
|
||||
|
||||
// Add in the list of open indexers
|
||||
obi_dms_list_indexer(dms, avl_group);
|
||||
|
||||
// Set counter to 1
|
||||
avl_group->counter = 1;
|
||||
|
||||
return avl_group;
|
||||
}
|
||||
|
||||
@ -1984,51 +1980,29 @@ OBIDMS_avl_group_p obi_open_avl_group(OBIDMS_p dms, const char* avl_name)
|
||||
int obi_close_avl(OBIDMS_avl_p avl)
|
||||
{
|
||||
int ret_val = 0;
|
||||
size_t i;
|
||||
Opened_indexers_list_p indexers_list;
|
||||
OBIDMS_p dms;
|
||||
|
||||
dms = avl->dms;
|
||||
ret_val = close_avl_data(avl->data);
|
||||
|
||||
indexers_list = dms->opened_indexers;
|
||||
ret_val = truncate_avl_to_size_used(avl);
|
||||
|
||||
(avl->counter)--;
|
||||
|
||||
if (avl->counter == 0)
|
||||
if (munmap(avl->tree, (((avl->header)->nb_items_max) * sizeof(AVL_node_t))) < 0)
|
||||
{
|
||||
// Delete from the list of opened avls
|
||||
for (i=0; i < (indexers_list->nb_opened_indexers); i++)
|
||||
{
|
||||
if (!strcmp(((*((indexers_list->indexers)+i))->header)->avl_name, (avl->header)->avl_name))
|
||||
{ // Found the avl. Rearrange list
|
||||
(indexers_list->nb_opened_indexers)--;
|
||||
(indexers_list->indexers)[i] = (indexers_list->indexers)[indexers_list->nb_opened_indexers];
|
||||
}
|
||||
}
|
||||
|
||||
ret_val = close_avl_data(avl->data);
|
||||
|
||||
ret_val = truncate_avl_to_size_used(avl);
|
||||
|
||||
if (munmap(avl->tree, (((avl->header)->nb_items_max) * sizeof(AVL_node_t))) < 0)
|
||||
{
|
||||
obi_set_errno(OBI_AVL_ERROR);
|
||||
obidebug(1, "\nError munmapping the tree of an AVL tree file");
|
||||
ret_val = -1;
|
||||
}
|
||||
|
||||
if (munmap(avl->header, (avl->header)->header_size) < 0)
|
||||
{
|
||||
obi_set_errno(OBI_AVL_ERROR);
|
||||
obidebug(1, "\nError munmapping the header of an AVL tree file");
|
||||
ret_val = -1;
|
||||
}
|
||||
|
||||
close(avl->avl_fd);
|
||||
|
||||
free(avl);
|
||||
obi_set_errno(OBI_AVL_ERROR);
|
||||
obidebug(1, "\nError munmapping the tree of an AVL tree file");
|
||||
ret_val = -1;
|
||||
}
|
||||
|
||||
if (munmap(avl->header, (avl->header)->header_size) < 0)
|
||||
{
|
||||
obi_set_errno(OBI_AVL_ERROR);
|
||||
obidebug(1, "\nError munmapping the header of an AVL tree file");
|
||||
ret_val = -1;
|
||||
}
|
||||
|
||||
close(avl->avl_fd);
|
||||
|
||||
free(avl);
|
||||
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
@ -2040,10 +2014,21 @@ int obi_close_avl_group(OBIDMS_avl_group_p avl_group)
|
||||
|
||||
ret_val = 0;
|
||||
|
||||
for (i=0; i < (avl_group->current_avl_idx); i++)
|
||||
if (obi_close_avl((avl_group->sub_avls)[i]) < 0)
|
||||
ret_val = -1;
|
||||
free(avl_group);
|
||||
(avl_group->counter)--;
|
||||
|
||||
if (avl_group->counter == 0)
|
||||
{
|
||||
// Delete from the list of opened indexers
|
||||
ret_val = obi_dms_unlist_indexer(avl_group->dms, avl_group);
|
||||
|
||||
// Close each AVL of the group
|
||||
for (i=0; i < (avl_group->current_avl_idx); i++)
|
||||
if (obi_close_avl((avl_group->sub_avls)[i]) < 0)
|
||||
ret_val = -1;
|
||||
|
||||
free(avl_group);
|
||||
}
|
||||
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user