Skip to content

Commit 45bde5c

Browse files
sawenzelBenedikt Volkel
authored andcommitted
Clean possibly leaked CCDB semaphores at workflow start
Use new feature of O2 to scan for leaked CCDB semaphores related to CCDB caches and clean them up before workflow execution. To this end, expand the __global_init__ mechanism with a "cmd" (not just environment variables) field. The pipeline runner will execute such init command before workflows start. Solves a problem, where second run/pass of workflow running hangs due to previously leaked semaphores. (cherry picked from commit ec4acee)
1 parent 98ab9d1 commit 45bde5c

3 files changed

Lines changed: 36 additions & 7 deletions

File tree

MC/bin/o2_dpg_workflow_runner.py

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -864,11 +864,12 @@ def __init__(self, workflowfile, args, jmax=100):
864864
self.is_productionmode = args.production_mode == True # os.getenv("ALIEN_PROC_ID") != None
865865
self.workflowfile = workflowfile
866866
self.workflowspec = load_json(workflowfile)
867-
self.globalenv = self.extract_global_environment(self.workflowspec) # initialize global environment settings
868-
for e in self.globalenv:
867+
self.globalinit = self.extract_global_environment(self.workflowspec) # initialize global environment settings
868+
for e in self.globalinit['env']:
869869
if os.environ.get(e, None) == None:
870-
actionlogger.info("Applying global environment from init section " + str(e) + " : " + str(self.globalenv[e]))
871-
os.environ[e] = str(self.globalenv[e])
870+
value = self.globalinit['env'][e]
871+
actionlogger.info("Applying global environment from init section " + str(e) + " : " + str(value))
872+
os.environ[e] = str(value)
872873

873874
# only keep those tasks that are necessary to be executed based on user's filters
874875
self.workflowspec = filter_workflow(self.workflowspec, args.target_tasks, args.target_labels)
@@ -968,13 +969,33 @@ def extract_global_environment(self, workflowspec):
968969
"""
969970
init_index = 0 # this has to be the first task in the workflow
970971
globalenv = {}
972+
initcmd = None
971973
if workflowspec['stages'][init_index]['name'] == '__global_init_task__':
972974
env = workflowspec['stages'][init_index].get('env', None)
973975
if env != None:
974976
globalenv = { e : env[e] for e in env }
977+
cmd = workflowspec['stages'][init_index].get('cmd', None)
978+
if cmd != 'NO-COMMAND':
979+
initcmd = cmd
980+
975981
del workflowspec['stages'][init_index]
976982

977-
return globalenv
983+
return {"env" : globalenv, "cmd" : initcmd }
984+
985+
def execute_globalinit_cmd(self, cmd):
986+
actionlogger.info("Executing global setup cmd " + str(cmd))
987+
# perform the global init command (think of cleanup/setup things to be done in any case)
988+
p = subprocess.Popen(['/bin/bash','-c', cmd], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
989+
stdout, stderr = p.communicate()
990+
991+
# Check if the command was successful (return code 0)
992+
if p.returncode == 0:
993+
actionlogger.info(stdout.decode())
994+
else:
995+
# this should be an error
996+
actionlogger.error("Error executing global init function")
997+
return False
998+
return True
978999

9791000
def get_global_task_name(self, name):
9801001
"""
@@ -1611,6 +1632,12 @@ def speedup_ROOT_Init():
16111632
self.produce_script(args.produce_script)
16121633
exit (0)
16131634

1635+
# execute the user-given global init cmd for this workflow
1636+
globalinitcmd = self.globalinit.get("cmd", None)
1637+
if globalinitcmd != None:
1638+
if not self.execute_globalinit_cmd(globalinitcmd):
1639+
exit (1)
1640+
16141641
if args.rerun_from:
16151642
reruntaskfound=False
16161643
for task in self.workflowspec['stages']:

MC/bin/o2dpg_sim_workflow.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,9 @@ def extractVertexArgs(configKeyValuesStr, finalDiamondDict):
342342
globalenv['ALICEO2_CCDB_LOCALCACHE'] = environ.get('ALICEO2_CCDB_LOCALCACHE')
343343
globalenv['IGNORE_VALIDITYCHECK_OF_CCDB_LOCALCACHE'] = '${ALICEO2_CCDB_LOCALCACHE:+"ON"}'
344344

345-
workflow['stages'].append(createGlobalInitTask(globalenv))
345+
globalinittask = createGlobalInitTask(globalenv)
346+
globalinittask['cmd'] = 'o2-ccdb-cleansemaphores -p ${ALICEO2_CCDB_LOCALCACHE}'
347+
workflow['stages'].append(globalinittask)
346348
####
347349

348350
def getDPL_global_options(bigshm=False, ccdbbackend=True):

MC/bin/o2dpg_workflow_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def dump_workflow(workflow, filename, meta=None):
140140
to_dump = deepcopy(workflow)
141141

142142
for s in to_dump:
143-
if s["cmd"] and taskwrapper_string not in s["cmd"]:
143+
if s["cmd"] and s["name"] != '__global_init_task__' and taskwrapper_string not in s["cmd"]:
144144
# insert taskwrapper stuff if not there already, only do it if cmd string is not empty
145145
s['cmd'] = '. ' + taskwrapper_string + ' ' + s['name']+'.log \'' + s['cmd'] + '\''
146146
# remove unnecessary whitespaces for better readibility

0 commit comments

Comments
 (0)