Skip to content

Commit f47ee67

Browse files
committed
Try 3 caches for xrootd, then fail
1 parent f7df5a4 commit f47ee67

1 file changed

Lines changed: 17 additions & 41 deletions

File tree

stashcp/__init__.py

Lines changed: 17 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -319,52 +319,28 @@ def download_xrootd(sourceFile, destination, debug, payload):
319319
if not nearest_cache:
320320
logging.error("No cache found")
321321
return False
322-
cache = nearest_cache
323-
logging.debug("Using Cache %s", nearest_cache)
324322

325-
xrd_exit = timed_transfer(filename=sourceFile, debug=debug, cache=cache, destination=destination)
326-
327-
payload['xrdexit1']=xrd_exit
328-
tries = 1
329-
payload['cache1'] = cache
330-
331-
if xrd_exit=='0': #worked first try
332-
logging.debug("Transfer success using %s", nearest_cache)
333-
status = "First Cache Success"
334-
payload['cache'] = cache
335-
336-
if xrd_exit != '0' and len(nearest_cache_list) >= 2: # pull from second nearest cache
337-
cache = nearest_cache_list[1]
338-
logging.info("XrdCP from cache failed on %s, pulling from second nearest cache %s", nearest_cache, cache)
323+
# Try 3 times to download from the 3 nearest caches
324+
num_available_caches = len(nearest_cache_list)
325+
tries = 0
326+
xrd_exit = ""
327+
for cache_idx in range(min(3, num_available_caches)): # try 3 caches, or how ever many caches are in the list
328+
tries = cache_idx+1
329+
cache = nearest_cache_list[cache_idx]
330+
logging.debug("Using Cache %s", cache)
339331
xrd_exit = timed_transfer(filename=sourceFile, debug=debug, cache=cache, destination=destination)
340-
payload['xrdexit2']=xrd_exit
341-
payload['cache2'] = cache
342-
343-
if xrd_exit=='0':
344-
logging.info("Second Cache Success")
345-
status = 'Second Cache Success'
346-
payload['cache'] = cache
347-
tries=2
348-
349-
if xrd_exit != '0': # pull from the origin
350-
logging.info("XrdCP from cache failed on %s, pulling from main redirector", cache)
351-
cache = main_redirector
352-
xrd_exit=timed_transfer(filename=sourceFile, cache=cache, debug=debug, destination=destination)
353-
payload['xrdexit3']=xrd_exit
354-
payload['cache3'] = cache
355-
356-
if xrd_exit=='0':
357-
logging.info("Trunk Success")
358-
status = 'Trunk Sucess'
359-
payload['cache'] = cache
360-
tries=3
332+
payload['cache' + str(tries)] = cache
333+
payload['xrdexit' + str(tries)] = xrd_exit
334+
335+
if xrd_exit=='0': # Transfer worked
336+
logging.debug("Transfer success using %s", cache)
337+
status = "Cache Success"
338+
break # Break out of the for loop, transfer worked!
361339
else:
362-
logging.info("stashcp failed after 3 xrootd attempts")
363-
status = 'Timeout'
364-
tries = 3
340+
logging.debug("xrdcp from cache failed on %s, pulling from next nearest cache", cache)
341+
status = "Cache Download Failure"
365342

366343
payload['status']=status
367-
368344
payload['tries']=tries
369345

370346
if xrd_exit == '0':

0 commit comments

Comments
 (0)