@@ -790,48 +790,72 @@ def start(self, params=[], wait=True):
790
790
"-w" if wait else '-W' , # --wait or --no-wait
791
791
"start" ] + params # yapf: disable
792
792
793
- log_files0 = self ._collect_log_files ()
794
- assert type (log_files0 ) == dict # noqa: E721
793
+ def LOCAL__start_node ():
794
+ _ , _ , error = execute_utility (_params , self .utils_log_file , verbose = True )
795
+ assert type (error ) == str # noqa: E721
796
+ if error and 'does not exist' in error :
797
+ raise Exception (error )
795
798
796
- nAttempt = 0
797
- timeout = 1
798
- while True :
799
- assert nAttempt >= 0
800
- assert nAttempt < __class__ ._C_MAX_START_ATEMPTS
801
- nAttempt += 1
799
+ def LOCAL__raise_cannot_start_node (from_exception , msg ):
800
+ assert isinstance (from_exception , Exception )
801
+ assert type (msg ) == str # noqa: E721
802
+ files = self ._collect_special_files ()
803
+ raise_from (StartNodeException (msg , files ), from_exception )
804
+
805
+ def LOCAL__raise_cannot_start_node__std (from_exception ):
806
+ assert isinstance (from_exception , Exception )
807
+ LOCAL__raise_cannot_start_node (from_exception , 'Cannot start node' )
808
+
809
+ if not self ._should_free_port :
802
810
try :
803
- exit_status , out , error = execute_utility (_params , self .utils_log_file , verbose = True )
804
- if error and 'does not exist' in error :
805
- raise Exception
811
+ LOCAL__start_node ()
806
812
except Exception as e :
807
- assert nAttempt > 0
808
- assert nAttempt <= __class__ ._C_MAX_START_ATEMPTS
809
- if self ._should_free_port and nAttempt < __class__ ._C_MAX_START_ATEMPTS :
813
+ LOCAL__raise_cannot_start_node__std (e )
814
+ else :
815
+ assert self ._should_free_port
816
+ assert __class__ ._C_MAX_START_ATEMPTS > 1
817
+
818
+ log_files0 = self ._collect_log_files ()
819
+ assert type (log_files0 ) == dict # noqa: E721
820
+
821
+ nAttempt = 0
822
+ timeout = 1
823
+ while True :
824
+ assert nAttempt >= 0
825
+ assert nAttempt < __class__ ._C_MAX_START_ATEMPTS
826
+ nAttempt += 1
827
+ try :
828
+ LOCAL__start_node ()
829
+ except Exception as e :
830
+ assert nAttempt > 0
831
+ assert nAttempt <= __class__ ._C_MAX_START_ATEMPTS
832
+ if nAttempt == __class__ ._C_MAX_START_ATEMPTS :
833
+ logging .error ("Reached maximum retry attempts. Unable to start node." )
834
+ LOCAL__raise_cannot_start_node (e , "Cannot start node after multiple attempts" )
835
+
810
836
log_files1 = self ._collect_log_files ()
811
- if self ._detect_port_conflict (log_files0 , log_files1 ):
812
- log_files0 = log_files1
813
- logging .warning (
814
- "Detected an issue with connecting to port {0}. "
815
- "Trying another port after a {1}-second sleep..." .format (self .port , timeout )
816
- )
817
- time .sleep (timeout )
818
- timeout = min (2 * timeout , 5 )
819
- cur_port = self .port
820
- new_port = utils .reserve_port () # can raise
821
- try :
822
- options = {'port' : str (new_port )}
823
- self .set_auto_conf (options )
824
- except : # noqa: E722
825
- utils .release_port (new_port )
826
- raise
827
- self .port = new_port
828
- utils .release_port (cur_port )
829
- continue
830
-
831
- msg = 'Cannot start node'
832
- files = self ._collect_special_files ()
833
- raise_from (StartNodeException (msg , files ), e )
834
- break
837
+ if not self ._detect_port_conflict (log_files0 , log_files1 ):
838
+ LOCAL__raise_cannot_start_node__std (e )
839
+
840
+ log_files0 = log_files1
841
+ logging .warning (
842
+ "Detected a conflict with using the port {0}. "
843
+ "Trying another port after a {1}-second sleep..." .format (self .port , timeout )
844
+ )
845
+ time .sleep (timeout )
846
+ timeout = min (2 * timeout , 5 )
847
+ cur_port = self .port
848
+ new_port = utils .reserve_port () # can raise
849
+ try :
850
+ options = {'port' : str (new_port )}
851
+ self .set_auto_conf (options )
852
+ except : # noqa: E722
853
+ utils .release_port (new_port )
854
+ raise
855
+ self .port = new_port
856
+ utils .release_port (cur_port )
857
+ continue
858
+ break
835
859
self ._maybe_start_logger ()
836
860
self .is_started = True
837
861
return self
0 commit comments