Indexers are now cloned if needed to modify them after they've been

closed. Obligatory indexers' names now follow the same pattern as other
indexers (columnname_version). Closes #46 and #49.
This commit is contained in:
Celine Mercier
2016-05-18 13:23:48 +02:00
parent 8ae7644945
commit 6a8df069ad
9 changed files with 165 additions and 41 deletions

View File

@ -923,7 +923,7 @@ int remap_an_avl(OBIDMS_avl_p avl)
int add_new_avl_in_group(OBIDMS_avl_group_p avl_group)
{
// Check that maximum number of AVLs in a group was not reached
if (avl_group->current_avl_idx == (MAX_NB_OF_AVLS_IN_GROUP-1))
if (avl_group->last_avl_idx == (MAX_NB_OF_AVLS_IN_GROUP - 1))
{
obi_set_errno(OBI_AVL_ERROR);
obidebug(1, "\nError: Trying to add new AVL in AVL group but maximum number of AVLs in a group reached");
@ -931,15 +931,15 @@ int add_new_avl_in_group(OBIDMS_avl_group_p avl_group)
}
// Unmap the previous AVL
if (unmap_an_avl((avl_group->sub_avls)[avl_group->current_avl_idx]) < 0)
if (unmap_an_avl((avl_group->sub_avls)[avl_group->last_avl_idx]) < 0)
return -1;
// Increment current AVL index
(avl_group->current_avl_idx)++;
(avl_group->last_avl_idx)++;
// Create the new AVL
(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)
(avl_group->sub_avls)[avl_group->last_avl_idx] = obi_create_avl(avl_group->dms, avl_group->name, avl_group->last_avl_idx);
if ((avl_group->sub_avls)[avl_group->last_avl_idx] == NULL)
{
obidebug(1, "\nError creating a new AVL tree in a group");
return -1;
@ -1823,7 +1823,7 @@ OBIDMS_avl_group_p obi_create_avl_group(OBIDMS_p dms, const char* avl_name)
return NULL;
}
avl_group->current_avl_idx = 0;
avl_group->last_avl_idx = 0;
strcpy(avl_group->name, avl_name);
avl_group->dms = dms;
@ -1845,7 +1845,7 @@ OBIDMS_avl_group_p obi_open_avl_group(OBIDMS_p dms, const char* avl_name)
{
OBIDMS_avl_group_p avl_group;
char* avl_dir_name;
int avl_count;
int last_avl_idx;
int i;
// Check if the group isn't already open
@ -1869,21 +1869,21 @@ OBIDMS_avl_group_p obi_open_avl_group(OBIDMS_p dms, const char* avl_name)
avl_dir_name = get_full_path_of_avl_dir(dms, avl_name);
if (avl_dir_name == NULL)
return NULL;
avl_count = count_dir(avl_dir_name) / 2;
if (avl_count < 0)
last_avl_idx = count_dir(avl_dir_name) / 2;
if (last_avl_idx < 0)
{
obidebug(1, "\nError counting the AVLs in an AVL directory: %s", avl_name);
return NULL;
}
// Open the AVLs
for (i=0; i<avl_count; i++)
for (i=0; i<last_avl_idx; i++)
{
(avl_group->sub_avls)[i] = obi_open_avl(dms, avl_name, i);
if ((avl_group->sub_avls)[i] == NULL)
return NULL;
}
avl_group->current_avl_idx = avl_count-1; // TODO latest. discuss
avl_group->last_avl_idx = last_avl_idx-1; // TODO latest. discuss
strcpy(avl_group->name, avl_name);
avl_group->dms = dms;
@ -1901,6 +1901,56 @@ OBIDMS_avl_group_p obi_open_avl_group(OBIDMS_p dms, const char* avl_name)
}
void obi_clone_avl(OBIDMS_avl_p avl, OBIDMS_avl_p new_avl)
{
// Clone AVL tree
memcpy(new_avl->tree, avl->tree, (avl->header)->avl_size);
(new_avl->header)->avl_size = (avl->header)->avl_size;
(new_avl->header)->nb_items = (avl->header)->nb_items;
(new_avl->header)->root_idx = (avl->header)->root_idx;
(new_avl->header)->bloom_filter = (avl->header)->bloom_filter;
// Clone AVL data
memcpy((new_avl->data)->data, (avl->data)->data, ((avl->data)->header)->data_size_used);
((new_avl->data)->header)->data_size_used = ((avl->data)->header)->data_size_used;
((new_avl->data)->header)->data_size_max = ((avl->data)->header)->data_size_max;
((new_avl->data)->header)->nb_items = ((avl->data)->header)->nb_items;
}
OBIDMS_avl_group_p obi_clone_avl_group(OBIDMS_avl_group_p avl_group, const char* new_avl_name)
{
OBIDMS_avl_group_p new_avl_group;
int i;
// Create the new AVL group
new_avl_group = obi_create_avl_group(avl_group->dms, new_avl_name);
// Copy the data from each old AVL to the new ones
for (i=0; i<=(avl_group->last_avl_idx); i++)
{
if (i > 0) // Don't need to create the 1st AVL
{
if (add_new_avl_in_group(new_avl_group) < 0)
{
obi_close_avl_group(new_avl_group);
return NULL;
}
}
obi_clone_avl((avl_group->sub_avls)[i], (new_avl_group->sub_avls)[i]);
}
// Close old AVL group
if (obi_close_avl_group(avl_group) < 0)
{
obi_close_avl_group(new_avl_group);
return NULL;
}
return new_avl_group;
}
int obi_close_avl(OBIDMS_avl_p avl)
{
int ret_val = 0;
@ -1946,7 +1996,7 @@ int obi_close_avl_group(OBIDMS_avl_group_p avl_group)
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++)
for (i=0; i < (avl_group->last_avl_idx); i++)
if (obi_close_avl((avl_group->sub_avls)[i]) < 0)
ret_val = -1;
@ -2157,18 +2207,18 @@ index_t obi_avl_group_add(OBIDMS_avl_group_p avl_group, Obi_blob_p value)
index_t index_with_avl;
int i;
if (maybe_in_avl((avl_group->sub_avls)[avl_group->current_avl_idx], value))
if (maybe_in_avl((avl_group->sub_avls)[avl_group->last_avl_idx], value))
{
index_in_avl = (int32_t) obi_avl_find((avl_group->sub_avls)[avl_group->current_avl_idx], value);
index_in_avl = (int32_t) obi_avl_find((avl_group->sub_avls)[avl_group->last_avl_idx], value);
if (index_in_avl >= 0)
{
index_with_avl = avl_group->current_avl_idx;
index_with_avl = avl_group->last_avl_idx;
index_with_avl = index_with_avl << 32;
index_with_avl = index_with_avl + index_in_avl;
return index_with_avl;
}
}
for (i=0; i < (avl_group->current_avl_idx); i++)
for (i=0; i < (avl_group->last_avl_idx); i++)
{
if (maybe_in_avl((avl_group->sub_avls)[i], value))
{
@ -2192,24 +2242,23 @@ index_t obi_avl_group_add(OBIDMS_avl_group_p avl_group, Obi_blob_p value)
// Check if the AVL group is writable
if (!(avl_group->writable))
{
obi_set_errno(OBI_AVL_ERROR);
obidebug(1, "\nTrying to add a value in an AVL group that is read-only.");
obi_set_errno(OBI_READ_ONLY_INDEXER_ERROR);
return -1;
}
// Check if need to make new AVL
if (((((avl_group->sub_avls)[avl_group->current_avl_idx])->header)->nb_items == MAX_NODE_COUNT_PER_AVL) || (((((avl_group->sub_avls)[avl_group->current_avl_idx])->data)->header)->data_size_used >= MAX_DATA_SIZE_PER_AVL))
if (((((avl_group->sub_avls)[avl_group->last_avl_idx])->header)->nb_items == MAX_NODE_COUNT_PER_AVL) || (((((avl_group->sub_avls)[avl_group->last_avl_idx])->data)->header)->data_size_used >= MAX_DATA_SIZE_PER_AVL))
{
if (add_new_avl_in_group(avl_group) < 0)
return -1;
}
// Add in the current AVL
bloom_add(&((((avl_group->sub_avls)[avl_group->current_avl_idx])->header)->bloom_filter), value, obi_blob_sizeof(value));
index_in_avl = (int32_t) obi_avl_add((avl_group->sub_avls)[avl_group->current_avl_idx], value);
bloom_add(&((((avl_group->sub_avls)[avl_group->last_avl_idx])->header)->bloom_filter), value, obi_blob_sizeof(value));
index_in_avl = (int32_t) obi_avl_add((avl_group->sub_avls)[avl_group->last_avl_idx], value);
// Build the index containing the AVL index
index_with_avl = avl_group->current_avl_idx;
index_with_avl = avl_group->last_avl_idx;
index_with_avl = index_with_avl << 32;
index_with_avl = index_with_avl + index_in_avl;