remap every 100000 values

This commit is contained in:
Celine Mercier
2016-03-14 17:03:24 +01:00
parent 86071d30c9
commit eaf5fd940a
3 changed files with 80 additions and 37 deletions

View File

@ -477,23 +477,25 @@ 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; // char* avl_file_name;
// Get the avl file name // // Get the avl file name
avl_file_name = build_avl_file_name((avl->header)->avl_name); // avl_file_name = build_avl_file_name((avl->header)->avl_name);
if (avl_file_name == NULL) // if (avl_file_name == NULL)
return -1; // 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);
// Open the avl file avl_file_descriptor = avl->avl_fd;
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;
@ -542,7 +544,7 @@ int grow_avl(OBIDMS_avl_p avl) // TODO Lock when needed
// Set the new avl size // Set the new avl size
(avl->header)->avl_size = new_data_size; (avl->header)->avl_size = new_data_size;
close(avl_file_descriptor); //close(avl_file_descriptor);
return 0; return 0;
} }
@ -555,23 +557,25 @@ 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; // char* avl_data_file_name;
//
// // 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);
// Get the avl data file name avl_data_file_descriptor = avl->data_fd;
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;
@ -620,7 +624,7 @@ int grow_avl_data(OBIDMS_avl_p avl) // TODO Lock when needed
// Initialize new data to 0 // Initialize new data to 0
memset(((avl->data)->data)+old_data_size, 0, new_data_size - old_data_size); memset(((avl->data)->data)+old_data_size, 0, new_data_size - old_data_size);
close(avl_data_file_descriptor); //close(avl_data_file_descriptor);
return 0; return 0;
} }
@ -1090,7 +1094,7 @@ OBIDMS_avl_p obi_create_avl(OBIDMS_p dms, const char* avl_name)
// Initialize all bits to 0 // Initialize all bits to 0
memset(avl_data->data, 0, (avl_data->header)->data_size_max); memset(avl_data->data, 0, (avl_data->header)->data_size_max);
close(avl_data_file_descriptor); //close(avl_data_file_descriptor);
// Create the AVL tree file // Create the AVL tree file
@ -1190,7 +1194,10 @@ OBIDMS_avl_p obi_create_avl(OBIDMS_p dms, const char* avl_name)
(avl->header)->creation_date = time(NULL); (avl->header)->creation_date = time(NULL);
strcpy((avl->header)->avl_name, avl_name); strcpy((avl->header)->avl_name, avl_name);
close(avl_file_descriptor); //close(avl_file_descriptor);
avl->avl_fd = avl_file_descriptor;
avl->data_fd = avl_data_file_descriptor;
// Add in the list of opened AVL trees // Add in the list of opened AVL trees
*(((dms->opened_avls)->avls)+((dms->opened_avls)->nb_opened_avls)) = avl; *(((dms->opened_avls)->avls)+((dms->opened_avls)->nb_opened_avls)) = avl;
@ -1297,7 +1304,7 @@ OBIDMS_avl_p obi_open_avl(OBIDMS_p dms, const char* avl_name)
return NULL; return NULL;
} }
close(avl_data_file_descriptor); //close(avl_data_file_descriptor);
// Open the AVL tree file // Open the AVL tree file
@ -1383,7 +1390,9 @@ OBIDMS_avl_p obi_open_avl(OBIDMS_p dms, const char* avl_name)
avl->directory = dms->avl_directory; avl->directory = dms->avl_directory;
avl->dir_fd = avl_dir_file_descriptor; avl->dir_fd = avl_dir_file_descriptor;
close(avl_file_descriptor); //close(avl_file_descriptor);
avl->avl_fd = avl_file_descriptor;
avl->data_fd = avl_data_file_descriptor;
// Add in the list of opened AVL trees // Add in the list of opened AVL trees
*(((dms->opened_avls)->avls)+((dms->opened_avls)->nb_opened_avls)) = avl; *(((dms->opened_avls)->avls)+((dms->opened_avls)->nb_opened_avls)) = avl;
@ -1435,6 +1444,9 @@ int obi_close_avl(OBIDMS_avl_p avl)
ret_val = -1; ret_val = -1;
} }
close(avl->avl_fd);
close(avl->data_fd);
free(avl); free(avl);
} }

View File

@ -130,6 +130,12 @@ typedef struct OBIDMS_avl {
int dir_fd; /**< The file descriptor of the directory entry int dir_fd; /**< The file descriptor of the directory entry
* usable to refer and scan the AVL tree directory. * usable to refer and scan the AVL tree directory.
*/ */
int avl_fd; /**< The file descriptor of the file
* to refer and scan the AVL tree.
*/
int data_fd; /**< The file descriptor of the file
* to refer and scan the data referred to by the AVL tree.
*/
size_t counter; /**< Indicates by how many threads/programs (TODO) the AVL tree is used. size_t counter; /**< Indicates by how many threads/programs (TODO) the AVL tree is used.
*/ */
} OBIDMS_avl_t, *OBIDMS_avl_p; } OBIDMS_avl_t, *OBIDMS_avl_p;

View File

@ -12,6 +12,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <sys/mman.h>
#include "obidmscolumn.h" #include "obidmscolumn.h"
#include "obiview.h" #include "obiview.h"
@ -60,6 +61,30 @@ int obi_column_set_obistr_with_elt_idx(OBIDMS_column_p column, index_t line_nb,
if (value_b == NULL) if (value_b == NULL)
return -1; return -1;
if (!(line_nb%100000))
{
//fprintf(stderr, "\nbleeeh");
// Unmap and remap the AVL
if (munmap((column->avl)->tree, ((((column->avl)->header)->nb_items_max) * sizeof(AVL_node_t))) < 0)
return -1;
if (munmap(((column->avl)->data)->data, (((column->avl)->data)->header)->data_size_max) < 0)
return -1;
(column->avl)->tree = mmap(NULL,
(((column->avl)->header)->nb_items_max) * sizeof(AVL_node_t), // TODO store avl_size_max
PROT_READ | PROT_WRITE,
MAP_SHARED,
(column->avl)->avl_fd,
((column->avl)->header)->header_size
);
((column->avl)->data)->data = mmap(NULL,
(((column->avl)->data)->header)->data_size_max,
PROT_READ | PROT_WRITE,
MAP_SHARED,
(column->avl)->data_fd,
(((column->avl)->data)->header)->header_size
);
}
// Add in the AVL tree // Add in the AVL tree
idx = obi_avl_add(column->avl, value_b); idx = obi_avl_add(column->avl, value_b);
if (idx == -1) if (idx == -1)