@@ -319,42 +319,34 @@ 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-
329- if xrd_exit == '0' : #worked first try
330- logging .debug ("Transfer success using %s" , nearest_cache )
331- payload ['tries' ] = 1
332- payload ['cache' ] = cache
333-
334- else : #pull from origin
335- logging .info ("XrdCP from cache failed on %s, pulling from main redirector" , nearest_cache )
336- cache = main_redirector
337- xrd_exit = timed_transfer (filename = sourceFile , cache = cache , debug = debug , destination = destination )
338-
339- if xrd_exit == '0' :
340- logging .info ("Trunk Success" )
341- status = 'Trunk Sucess'
342- tries = 2
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 (4 , num_available_caches )): # try 4 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 )
331+ xrd_exit = timed_transfer (filename = sourceFile , debug = debug , cache = cache , destination = destination )
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!
343339 else :
344- logging .info ("stashcp failed after 2 xrootd attempts" )
345- status = 'Timeout'
346- tries = 2
340+ logging .debug ("xrdcp from cache failed on %s, pulling from next nearest cache" , cache )
341+ status = "Cache Download Failure"
347342
348- payload ['status' ]= status
349- payload ['xrdexit2' ]= xrd_exit
350- payload ['tries' ]= tries
351- payload ['cache' ] = cache
343+ payload ['status' ]= status
344+ payload ['tries' ]= tries
352345
353- if xrd_exit == '0' :
354- return True
355- else :
356- return False
357- return True
346+ if xrd_exit == '0' :
347+ return True
348+ else :
349+ return False
358350
359351def check_for_xrootd ():
360352 """
@@ -408,11 +400,13 @@ def download_http(source, destination, debug, payload):
408400 download_output = "-O"
409401 final_destination = os .path .join (dest_dir , os .path .basename (source ))
410402
411- # Try 2 nearest caches
412403 success = False
413404 start = end = 0
414405 tried_cache = ""
415- for cache in nearest_cache_list [:2 ]:
406+ tries = 0
407+ # Try the 4 nearest caches
408+ for cache in nearest_cache_list [:min (4 , len (nearest_cache_list ))]:
409+ tries = tries + 1
416410 tried_cache = cache
417411 # Parse the nearest_cache url, make sure it uses http
418412 # Should really use urlparse, but python3 and python2 urlparse imports are
@@ -455,7 +449,7 @@ def download_http(source, destination, debug, payload):
455449 payload ['filesize' ] = filesize
456450
457451 payload ['host' ]= tried_cache
458- payload ['tries' ]= 1
452+ payload ['tries' ]= tries
459453 payload ['cache' ]= tried_cache
460454 if success :
461455 return True
0 commit comments