DMS are now locked when used by a command. Added checks and changed

cleaning mechanisms.
This commit is contained in:
Celine Mercier
2019-09-20 20:37:19 +02:00
parent eb6c59dc1e
commit 783a1343c4
14 changed files with 378 additions and 28 deletions

View File

@ -554,6 +554,7 @@ static int create_dms_infos_file(int dms_file_descriptor, const char* dms_name)
infos->little_endian = obi_is_little_endian();
infos->file_size = file_size;
infos->used_size = 0;
infos->working = false;
infos->comments[0] = '\0';
// Unmap the infos file
@ -652,6 +653,52 @@ static int dms_count_in_list(OBIDMS_p dms)
*
**********************************************************************/
int obi_dms_is_clean(OBIDMS_p dms)
{
int ret_val1;
int ret_val2;
ret_val1 = obi_dms_has_unfinished_views(dms);
if (ret_val1 < 0)
return -1;
ret_val2 = obi_dms_has_unfinished_columns(dms);
if (ret_val2 < 0)
return -1;
return !(ret_val1 || ret_val2);
}
int obi_clean_dms(const char* dms_path)
{
OBIDMS_p dms;
dms = obi_open_dms(dms_path, true);
if (dms == NULL)
{
obidebug(1, "\nError opening a DMS before cleaning unfinished views and columns");
return -1;
}
// Currently done in obi_open_dms
// // Clean unfinished views
// if (obi_clean_unfinished_views(dms) < 0)
// {
// obidebug(1, "\nError cleaning unfinished views");
// return -1;
// }
//
// // Clean unfinished columns
// if (obi_clean_unfinished_columns(dms) < 0)
// {
// obidebug(1, "\nError cleaning unfinished columns");
// return -1;
// }
return 0;
}
int obi_dms_exists(const char* dms_path)
{
struct stat buffer;
@ -750,7 +797,7 @@ OBIDMS_p obi_create_dms(const char* dms_path)
return NULL;
// Open DMS
dms = obi_open_dms(dms_path);
dms = obi_open_dms(dms_path, false);
if (dms == NULL)
{
obidebug(1, "\nProblem opening a DMS");
@ -775,11 +822,12 @@ OBIDMS_p obi_create_dms(const char* dms_path)
}
OBIDMS_p obi_open_dms(const char* dms_path)
OBIDMS_p obi_open_dms(const char* dms_path, bool cleaning)
{
OBIDMS_p dms;
char* relative_dms_path;
char* absolute_dms_path;
int clean_dms;
dms = NULL;
@ -868,6 +916,26 @@ OBIDMS_p obi_open_dms(const char* dms_path)
return NULL;
}
// Reset the working variable to false if cleaning the DMS
if (cleaning)
(dms->infos)->working = false;
// Check that the DMS is not already working (being used by a process)
if ((dms->infos)->working)
{
obidebug(1, "\n\nERROR:\nThe DMS '%s' contains unfinished views or columns. Either another command is currently running, "
"in which case you have to wait for it to finish, or a previous command was interrupted, "
"in which case you can run 'obi clean_dms [your_dms]' to clean the DMS.\n", dms->dms_name);
obi_set_errno(OBIDMS_WORKING);
unmap_infos_file(dms);
closedir(dms->directory);
free(dms);
return NULL;
}
// Set the working variable to true
(dms->infos)->working = true;
// Open the indexer directory
dms->indexer_directory = opendir_in_dms(dms, INDEXER_DIR_NAME);
if (dms->indexer_directory == NULL)
@ -948,6 +1016,23 @@ OBIDMS_p obi_open_dms(const char* dms_path)
return NULL;
}
// // Check for unfinished views and columns
// clean_dms = obi_dms_is_clean(dms);
// if (clean_dms < 0)
// {
// obi_set_errno(OBIDMS_UNKNOWN_ERROR);
// obidebug(1, "\nError checking if a DMS has unfinished views or columns when opening it");
// unmap_infos_file(dms);
// closedir(dms->indexer_directory);
// closedir(dms->tax_directory);
// closedir(dms->view_directory);
// closedir(dms->directory);
// free(dms);
// return NULL;
// }
// if (! clean_dms)
// obi_set_errno(OBIDMS_NOT_CLEAN);
// Clean unfinished views
if (obi_clean_unfinished_views(dms) < 0)
{
@ -1012,7 +1097,7 @@ OBIDMS_p obi_test_open_dms(const char* dms_name)
case 0:
return NULL;
case 1:
return obi_open_dms(dms_name);
return obi_open_dms(dms_name, false);
};
obidebug(1, "\nError checking if an OBIDMS directory exists");
@ -1031,7 +1116,7 @@ OBIDMS_p obi_dms(const char* dms_name)
case 0:
return obi_create_dms(dms_name);
case 1:
return obi_open_dms(dms_name);
return obi_open_dms(dms_name, false);
};
obidebug(1, "\nError checking if an OBIDMS directory exists");
@ -1062,14 +1147,6 @@ int obi_close_dms(OBIDMS_p dms, bool force)
if (dms != NULL)
{
// Unmap information file
if (unmap_infos_file(dms) < 0)
{
obidebug(1, "\nError unmaping a DMS information file while closing a DMS");
free(dms);
return -1;
}
// Close all columns
while ((dms->opened_columns)->nb_opened_columns > 0)
obi_close_column(*((dms->opened_columns)->columns));
@ -1096,6 +1173,18 @@ int obi_close_dms(OBIDMS_p dms, bool force)
free(dms);
return -1;
}
// Set the working variable as false
(dms->infos)->working = false;
// Unmap information file
if (unmap_infos_file(dms) < 0)
{
obidebug(1, "\nError unmaping a DMS information file while closing a DMS");
free(dms);
return -1;
}
if (closedir(dms->directory) < 0)
{
obi_set_errno(OBIDMS_MEMORY_ERROR);
@ -1338,7 +1427,7 @@ obiversion_t obi_import_column(const char* dms_path_1, const char* dms_path_2, c
char* complete_avl_name;
Obi_indexer_p avl_group;
dms_1 = obi_open_dms(dms_path_1);
dms_1 = obi_open_dms(dms_path_1, false);
if (dms_1 == NULL)
{
obidebug(1, "\nError opening a DMS to import a column from it");
@ -1538,7 +1627,7 @@ int obi_import_view(const char* dms_path_1, const char* dms_path_2, const char*
OBIDMS_column_header_p header = NULL;
OBIDMS_column_header_p header_2 = NULL;
dms_1 = obi_open_dms(dms_path_1);
dms_1 = obi_open_dms(dms_path_1, false);
if (dms_1 == NULL)
{
obidebug(1, "\nError opening a DMS to import a view from it");