From 33d849b56211d4a826d01f23f6c0752ed0bb8288 Mon Sep 17 00:00:00 2001 From: dbeltran Date: Wed, 28 Feb 2024 11:57:36 +0100 Subject: [PATCH 1/3] Changes in save/load --- autosubmit/job/job_list.py | 3 +++ autosubmit/job/job_list_persistence.py | 16 ++++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/autosubmit/job/job_list.py b/autosubmit/job/job_list.py index 505ce8dd2..d0c66ca1b 100644 --- a/autosubmit/job/job_list.py +++ b/autosubmit/job/job_list.py @@ -193,6 +193,7 @@ class JobList(object): :type monitor: bool """ if force: + Log.debug("Resetting the workflow graph to a zero state") if os.path.exists(os.path.join(self._persistence_path, self._persistence_file + ".pkl")): os.remove(os.path.join(self._persistence_path, self._persistence_file + ".pkl")) if os.path.exists(os.path.join(self._persistence_path, self._persistence_file + "_backup.pkl")): @@ -233,6 +234,8 @@ class JobList(object): # Force to use the last known job_list when autosubmit monitor is running. self._dic_jobs.last_experiment_data = as_conf.last_experiment_data else: + if monitor: + raise AutosubmitCritical("The workflow graph was not found. Please run autosubmit create first. If the graph exists, try again.",7013) # Remove the previous pkl, if it exists. if not new: Log.info( diff --git a/autosubmit/job/job_list_persistence.py b/autosubmit/job/job_list_persistence.py index 592fcc196..04448fabb 100644 --- a/autosubmit/job/job_list_persistence.py +++ b/autosubmit/job/job_list_persistence.py @@ -19,7 +19,7 @@ import os import pickle from sys import setrecursionlimit - +import shutil from autosubmit.database.db_manager import DbManager from log.log import Log @@ -67,8 +67,12 @@ class JobListPersistencePkl(JobListPersistence): """ path = os.path.join(persistence_path, persistence_file + '.pkl') if os.path.exists(path): - with open(path, 'rb') as fd: + # copy the path to a tmp file randomseed to avoid corruption + path_tmp = f'{path}.tmp_{os.urandom(8).hex()}' + shutil.copy(path, path_tmp) + with open(path_tmp, 'rb') as fd: graph = pickle.load(fd) + os.remove(path_tmp) for u in ( node for node in graph ): # Set after the dependencies are set graph.nodes[u]["job"].children = set() @@ -90,12 +94,16 @@ class JobListPersistencePkl(JobListPersistence): :param persistence_path: str """ - path = os.path.join(persistence_path, persistence_file + '.pkl') + + path = os.path.join(persistence_path, persistence_file + '.pkl' + '.tmp') + if os.path.exists(path): + os.remove(path) setrecursionlimit(500000000) Log.debug("Saving JobList: " + path) with open(path, 'wb') as fd: pickle.dump(graph, fd, pickle.HIGHEST_PROTOCOL) - Log.debug('Job list saved') + os.rename(path, path[:-4]) + Log.debug(f'JobList saved in {path[:-4]}') class JobListPersistenceDb(JobListPersistence): -- GitLab From 1f54c55decf87cc74a185fc9806caac2fe5f4ed6 Mon Sep 17 00:00:00 2001 From: dbeltran Date: Wed, 28 Feb 2024 12:31:28 +0100 Subject: [PATCH 2/3] changed to not create instead of monitor --- autosubmit/autosubmit.py | 2 +- autosubmit/job/job_list.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/autosubmit/autosubmit.py b/autosubmit/autosubmit.py index 08c1da8a5..8653285dc 100644 --- a/autosubmit/autosubmit.py +++ b/autosubmit/autosubmit.py @@ -4697,7 +4697,7 @@ class Autosubmit: job_list.generate(as_conf,date_list, member_list, num_chunks, chunk_ini, parameters, date_format, as_conf.get_retrials(), as_conf.get_default_job_type(), - wrapper_jobs, run_only_members=run_only_members, force=force) + wrapper_jobs, run_only_members=run_only_members, force=force, create=True) if str(rerun).lower() == "true": job_list.rerun(as_conf.get_rerun_jobs(),as_conf) diff --git a/autosubmit/job/job_list.py b/autosubmit/job/job_list.py index d0c66ca1b..43abc144e 100644 --- a/autosubmit/job/job_list.py +++ b/autosubmit/job/job_list.py @@ -160,7 +160,7 @@ class JobList(object): def generate(self, as_conf, date_list, member_list, num_chunks, chunk_ini, parameters, date_format, default_retrials, default_job_type, wrapper_jobs=dict(), new=True, run_only_members=[], show_log=True, monitor=False, - force=False): + force=False, create = False): """ Creates all jobs needed for the current workflow. :param as_conf: AutosubmitConfig object @@ -234,8 +234,8 @@ class JobList(object): # Force to use the last known job_list when autosubmit monitor is running. self._dic_jobs.last_experiment_data = as_conf.last_experiment_data else: - if monitor: - raise AutosubmitCritical("The workflow graph was not found. Please run autosubmit create first. If the graph exists, try again.",7013) + if not create: + raise AutosubmitCritical("Autosubmit couldn't load the workflow graph. Please run autosubmit create first. If the pkl file exists, try again.",7013) # Remove the previous pkl, if it exists. if not new: Log.info( -- GitLab From 8103f694a4280cdaf7793f4a8d98177c3edc1c00 Mon Sep 17 00:00:00 2001 From: dbeltran Date: Wed, 28 Feb 2024 12:38:22 +0100 Subject: [PATCH 3/3] Added replace instead of rename --- autosubmit/job/job_list.py | 2 +- autosubmit/job/job_list_persistence.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/autosubmit/job/job_list.py b/autosubmit/job/job_list.py index 43abc144e..eca3aa9ca 100644 --- a/autosubmit/job/job_list.py +++ b/autosubmit/job/job_list.py @@ -235,7 +235,7 @@ class JobList(object): self._dic_jobs.last_experiment_data = as_conf.last_experiment_data else: if not create: - raise AutosubmitCritical("Autosubmit couldn't load the workflow graph. Please run autosubmit create first. If the pkl file exists, try again.",7013) + raise AutosubmitCritical("Autosubmit couldn't load the workflow graph. Please run autosubmit create first. If the pkl file exists and was generated with Autosubmit v4.1+, try again.",7013) # Remove the previous pkl, if it exists. if not new: Log.info( diff --git a/autosubmit/job/job_list_persistence.py b/autosubmit/job/job_list_persistence.py index 04448fabb..bb884ba43 100644 --- a/autosubmit/job/job_list_persistence.py +++ b/autosubmit/job/job_list_persistence.py @@ -102,7 +102,7 @@ class JobListPersistencePkl(JobListPersistence): Log.debug("Saving JobList: " + path) with open(path, 'wb') as fd: pickle.dump(graph, fd, pickle.HIGHEST_PROTOCOL) - os.rename(path, path[:-4]) + os.replace(path, path[:-4]) Log.debug(f'JobList saved in {path[:-4]}') -- GitLab