When enlarging a column, the function doesn't try anymore to keep the
mapped region at the same pointer (never works), and unmap/remap instead.
This commit is contained in:
@ -962,7 +962,7 @@ int obi_truncate_column_to_lines_used(OBIDMS_column_p column) // TODO is it nece
|
|||||||
|
|
||||||
// Compute the new line count = the number of lines used rounded to the nearest greater multiple of page size greater than 0
|
// Compute the new line count = the number of lines used rounded to the nearest greater multiple of page size greater than 0
|
||||||
multiple = ceil((double) (ONE_IF_ZERO((column->header)->lines_used) * (column->header)->nb_elements_per_line * obi_sizeof((column->header)->data_type)) / (double) getpagesize());
|
multiple = ceil((double) (ONE_IF_ZERO((column->header)->lines_used) * (column->header)->nb_elements_per_line * obi_sizeof((column->header)->data_type)) / (double) getpagesize());
|
||||||
new_line_count = floor((((int) multiple) * getpagesize()) / ((column->header)->nb_elements_per_line * obi_sizeof((column->header)->data_type))); // TODO is it safe to cast like this?
|
new_line_count = floor((((int) multiple) * getpagesize()) / ((column->header)->nb_elements_per_line * obi_sizeof((column->header)->data_type)));
|
||||||
|
|
||||||
// Check that it is actually greater than the current number of lines allocated in the file, otherwise no need to truncate
|
// Check that it is actually greater than the current number of lines allocated in the file, otherwise no need to truncate
|
||||||
if ((column->header)->line_count == new_line_count)
|
if ((column->header)->line_count == new_line_count)
|
||||||
@ -1090,18 +1090,23 @@ int obi_enlarge_column(OBIDMS_column_p column)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remap the data: try enlarging mapped region (TODO this actually never works on my mac without the MAP_FIXED flag which overwrites everything)
|
// Unmap and remap the data
|
||||||
// TODO : makes separate function even if it's only used here?
|
if (munmap(column->data, old_data_size) < 0)
|
||||||
//obidebug(2, "\ntry enlarging mapped region: old size = %ld, new size = %ld, size = %ld", old_data_size, new_data_size, new_data_size - old_data_size);
|
{
|
||||||
new_data = mmap(column->data,
|
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||||
new_data_size - old_data_size,
|
obidebug(1, "\nError munmapping the data of a column before enlarging");
|
||||||
PROT_READ | PROT_WRITE,
|
close(column_file_descriptor);
|
||||||
MAP_SHARED,
|
return -1;
|
||||||
column_file_descriptor,
|
}
|
||||||
old_data_size
|
|
||||||
);
|
|
||||||
|
|
||||||
if (new_data == MAP_FAILED)
|
column->data = mmap(NULL,
|
||||||
|
new_data_size,
|
||||||
|
PROT_READ | PROT_WRITE,
|
||||||
|
MAP_SHARED,
|
||||||
|
column_file_descriptor,
|
||||||
|
header_size
|
||||||
|
);
|
||||||
|
if (column->data == MAP_FAILED)
|
||||||
{
|
{
|
||||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||||
obidebug(1, "\nError re-mmapping the data of a column after enlarging the file");
|
obidebug(1, "\nError re-mmapping the data of a column after enlarging the file");
|
||||||
@ -1109,35 +1114,6 @@ int obi_enlarge_column(OBIDMS_column_p column)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If remap failed: Unmap and map the data again
|
|
||||||
if (new_data != (column->data)) // TODO check that this works without exception
|
|
||||||
{
|
|
||||||
//obidebug(2, "\nEnlarging mapped region failed: Unmap and map the data again, %x != %x", column->data, new_data);
|
|
||||||
if (munmap(column->data, old_data_size) < 0)
|
|
||||||
{
|
|
||||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
|
||||||
obidebug(1, "\nError munmapping the data of a column before enlarging");
|
|
||||||
close(column_file_descriptor);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
column->data = mmap(NULL,
|
|
||||||
new_data_size,
|
|
||||||
PROT_READ | PROT_WRITE,
|
|
||||||
MAP_SHARED,
|
|
||||||
column_file_descriptor,
|
|
||||||
header_size
|
|
||||||
);
|
|
||||||
|
|
||||||
if (column->data == MAP_FAILED)
|
|
||||||
{
|
|
||||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
|
||||||
obidebug(1, "\nError re-mmapping the data of a column after enlarging the file");
|
|
||||||
close(column_file_descriptor);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set new line count and new data size
|
// Set new line count and new data size
|
||||||
(column->header)->line_count = new_line_count;
|
(column->header)->line_count = new_line_count;
|
||||||
(column->header)->data_size = new_data_size;
|
(column->header)->data_size = new_data_size;
|
||||||
|
Reference in New Issue
Block a user