@ -1,6 +1,6 @@
#!/usr/bin/env python3
import bz2
from functools import partial
from functools import cache , partial
import multiprocessing
import capnp
import enum
@ -87,18 +87,21 @@ Source = Callable[[SegmentRange, ReadMode], LogPaths]
InternalUnavailableException = Exception ( " Internal source not available " )
@cache
def default_valid_file ( fn : LogPath ) - > bool :
return fn is not None and file_exists ( fn )
def auto_strategy ( rlog_paths : LogPaths , qlog_paths : LogPaths , interactive : bool , valid_file : ValidFileCallable ) - > LogPaths :
# auto select logs based on availability
if any ( rlog is None or not valid_file ( rlog ) for rlog in rlog_paths ) and all ( qlog is not None and valid_file ( qlog ) for qlog in qlog_paths ) :
missing_rlogs = [ rlog is None or not valid_file ( rlog ) for rlog in rlog_paths ] . count ( True )
if missing_rlogs != 0 :
if interactive :
if input ( " Some rlogs were not found, would you like to fallback to qlogs for those segments? (y/n) " ) . lower ( ) != " y " :
if input ( f " { missing_rlogs } rlogs were not found, would you like to fallback to qlogs for those segments? (y/n) " ) . lower ( ) != " y " :
return rlog_paths
else :
cloudlog . warning ( " Some rlogs were not found, falling back to qlogs for those segments..." )
cloudlog . warning ( f " { missing_rlogs } rlogs were not found, falling back to qlogs for those segments..." )
return [ rlog if valid_file ( rlog ) else ( qlog if valid_file ( qlog ) else None )
for ( rlog , qlog ) in zip ( rlog_paths , qlog_paths , strict = True ) ]