|
|
@ -483,26 +483,9 @@ int grow_avl(OBIDMS_avl_p avl) // TODO Lock when needed
|
|
|
|
size_t new_data_size;
|
|
|
|
size_t new_data_size;
|
|
|
|
size_t header_size;
|
|
|
|
size_t header_size;
|
|
|
|
int avl_file_descriptor;
|
|
|
|
int avl_file_descriptor;
|
|
|
|
char* avl_file_name;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
avl_file_descriptor = avl->avl_fd;
|
|
|
|
avl_file_descriptor = avl->avl_fd;
|
|
|
|
|
|
|
|
|
|
|
|
// // Get the avl file name
|
|
|
|
|
|
|
|
// avl_file_name = build_avl_file_name((avl->header)->avl_name);
|
|
|
|
|
|
|
|
// if (avl_file_name == NULL)
|
|
|
|
|
|
|
|
// return -1;
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// // Open the avl file
|
|
|
|
|
|
|
|
// avl_file_descriptor = openat(avl->dir_fd, avl_file_name, O_RDWR);
|
|
|
|
|
|
|
|
// if (avl_file_descriptor < 0)
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// obi_set_errno(OBI_AVL_ERROR);
|
|
|
|
|
|
|
|
// obidebug(1, "\nError opening an AVL tree file");
|
|
|
|
|
|
|
|
// free(avl_file_name);
|
|
|
|
|
|
|
|
// return -1;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// free(avl_file_name);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Calculate the new file size
|
|
|
|
// Calculate the new file size
|
|
|
|
old_data_size = (avl->header)->avl_size;
|
|
|
|
old_data_size = (avl->header)->avl_size;
|
|
|
|
new_data_size = old_data_size * AVL_GROWTH_FACTOR;
|
|
|
|
new_data_size = old_data_size * AVL_GROWTH_FACTOR;
|
|
|
@ -563,26 +546,9 @@ int grow_avl_data(OBIDMS_avl_p avl) // TODO Lock when needed
|
|
|
|
index_t new_data_size;
|
|
|
|
index_t new_data_size;
|
|
|
|
size_t header_size;
|
|
|
|
size_t header_size;
|
|
|
|
int avl_data_file_descriptor;
|
|
|
|
int avl_data_file_descriptor;
|
|
|
|
char* avl_data_file_name;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
avl_data_file_descriptor = avl->data_fd;
|
|
|
|
avl_data_file_descriptor = avl->data_fd;
|
|
|
|
|
|
|
|
|
|
|
|
// // Get the avl data file name
|
|
|
|
|
|
|
|
// avl_data_file_name = build_avl_data_file_name((avl->header)->avl_name);
|
|
|
|
|
|
|
|
// if (avl_data_file_name == NULL)
|
|
|
|
|
|
|
|
// return -1;
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// // Open the avl data file
|
|
|
|
|
|
|
|
// avl_data_file_descriptor = openat(avl->dir_fd, avl_data_file_name, O_RDWR);
|
|
|
|
|
|
|
|
// if (avl_data_file_descriptor < 0)
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// obi_set_errno(OBI_AVL_ERROR);
|
|
|
|
|
|
|
|
// obidebug(1, "\nError opening an AVL tree data file");
|
|
|
|
|
|
|
|
// free(avl_data_file_name);
|
|
|
|
|
|
|
|
// return -1;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// free(avl_data_file_name);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Calculate the new file size
|
|
|
|
// Calculate the new file size
|
|
|
|
old_data_size = ((avl->data)->header)->data_size_max;
|
|
|
|
old_data_size = ((avl->data)->header)->data_size_max;
|
|
|
|
new_data_size = old_data_size * AVL_GROWTH_FACTOR;
|
|
|
|
new_data_size = old_data_size * AVL_GROWTH_FACTOR;
|
|
|
@ -1014,8 +980,20 @@ OBIDMS_avl_group_p obi_create_avl_group(OBIDMS_p dms, const char* avl_name)
|
|
|
|
avl_group = (OBIDMS_avl_group_p) malloc(sizeof(OBIDMS_avl_group_t));
|
|
|
|
avl_group = (OBIDMS_avl_group_p) malloc(sizeof(OBIDMS_avl_group_t));
|
|
|
|
|
|
|
|
|
|
|
|
// Create 1st avl
|
|
|
|
// Create 1st avl
|
|
|
|
asprintf(&avl_name_with_idx,"%s_%u", avl_name, 0);
|
|
|
|
avl_name_with_idx = malloc((strlen(avl_name) + 3)*sizeof(char));
|
|
|
|
|
|
|
|
if (sprintf(avl_name_with_idx, "%s_%u", avl_name, 0) < 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
obi_set_errno(OBI_AVL_ERROR);
|
|
|
|
|
|
|
|
obidebug(1, "\nError building an AVL tree file name");
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
}
|
|
|
|
(avl_group->sub_avls)[0] = obi_create_avl(dms, avl_name_with_idx);
|
|
|
|
(avl_group->sub_avls)[0] = obi_create_avl(dms, avl_name_with_idx);
|
|
|
|
|
|
|
|
if ((avl_group->sub_avls)[0] == NULL)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
obidebug(1, "\nError creating the first AVL of an AVL group");
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
avl_group->current_avl_idx = 0;
|
|
|
|
avl_group->current_avl_idx = 0;
|
|
|
|
strcpy(avl_group->avl_name, avl_name);
|
|
|
|
strcpy(avl_group->avl_name, avl_name);
|
|
|
|
|
|
|
|
|
|
|
@ -1039,7 +1017,7 @@ int remap_an_avl(OBIDMS_avl_p avl)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
(avl->data)->data = mmap(NULL,
|
|
|
|
(avl->data)->data = mmap(NULL,
|
|
|
|
((avl->data)->header)->data_size_max,
|
|
|
|
((avl->data)->header)->data_size_max,
|
|
|
|
PROT_READ | PROT_WRITE,
|
|
|
|
PROT_READ,
|
|
|
|
MAP_SHARED,
|
|
|
|
MAP_SHARED,
|
|
|
|
avl->data_fd,
|
|
|
|
avl->data_fd,
|
|
|
|
((avl->data)->header)->header_size);
|
|
|
|
((avl->data)->header)->header_size);
|
|
|
@ -1048,7 +1026,7 @@ int remap_an_avl(OBIDMS_avl_p avl)
|
|
|
|
|
|
|
|
|
|
|
|
avl->tree = mmap(NULL,
|
|
|
|
avl->tree = mmap(NULL,
|
|
|
|
((avl->header)->nb_items_max) * sizeof(AVL_node_t),
|
|
|
|
((avl->header)->nb_items_max) * sizeof(AVL_node_t),
|
|
|
|
PROT_READ | PROT_WRITE,
|
|
|
|
PROT_READ,
|
|
|
|
MAP_SHARED,
|
|
|
|
MAP_SHARED,
|
|
|
|
avl->avl_fd,
|
|
|
|
avl->avl_fd,
|
|
|
|
(avl->header)->header_size);
|
|
|
|
(avl->header)->header_size);
|
|
|
@ -1062,13 +1040,28 @@ int remap_an_avl(OBIDMS_avl_p avl)
|
|
|
|
int obi_add_new_avl_in_group(OBIDMS_avl_group_p avl_group) // TODO check for errors
|
|
|
|
int obi_add_new_avl_in_group(OBIDMS_avl_group_p avl_group) // TODO check for errors
|
|
|
|
{
|
|
|
|
{
|
|
|
|
char* avl_name_with_idx;
|
|
|
|
char* avl_name_with_idx;
|
|
|
|
|
|
|
|
int avl_idx_length;
|
|
|
|
|
|
|
|
|
|
|
|
// unmap older
|
|
|
|
// unmap older
|
|
|
|
unmap_an_avl((avl_group->sub_avls)[avl_group->current_avl_idx]);
|
|
|
|
unmap_an_avl((avl_group->sub_avls)[avl_group->current_avl_idx]);
|
|
|
|
|
|
|
|
|
|
|
|
(avl_group->current_avl_idx)++;
|
|
|
|
(avl_group->current_avl_idx)++;
|
|
|
|
asprintf(&avl_name_with_idx,"%s_%u", avl_group->avl_name, avl_group->current_avl_idx);
|
|
|
|
avl_idx_length = ((avl_group->current_avl_idx) == 0 ? 1 : (int)(log10(avl_group->current_avl_idx)+1));
|
|
|
|
|
|
|
|
avl_name_with_idx = malloc((strlen(avl_group->avl_name) + avl_idx_length + 2)*sizeof(char));
|
|
|
|
|
|
|
|
if (sprintf(avl_name_with_idx, "%s_%u", avl_group->avl_name, avl_group->current_avl_idx) < 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
obi_set_errno(OBI_AVL_ERROR);
|
|
|
|
|
|
|
|
obidebug(1, "\nError building an AVL tree file name");
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//fprintf(stderr, "\nindex length = %d, file name = %s\n", avl_idx_length, avl_name_with_idx);
|
|
|
|
|
|
|
|
|
|
|
|
(avl_group->sub_avls)[avl_group->current_avl_idx] = obi_create_avl(avl_group->dms, avl_name_with_idx);
|
|
|
|
(avl_group->sub_avls)[avl_group->current_avl_idx] = obi_create_avl(avl_group->dms, avl_name_with_idx);
|
|
|
|
|
|
|
|
if ((avl_group->sub_avls)[avl_group->current_avl_idx] == NULL)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
obidebug(1, "\nError creating a new AVL tree in a group");
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|