Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitab28c2e

Browse files
Merge branch '20250228_002--try_shutdown' into D20250227_001--node-pid
2 parentsa4e65bf +09976ae commitab28c2e

File tree

1 file changed

+75
-32
lines changed

1 file changed

+75
-32
lines changed

‎testgres/node.py

Lines changed: 75 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -367,41 +367,84 @@ def version(self):
367367
returnself._pg_version
368368

369369
def_try_shutdown(self,max_attempts,with_force=False):
370+
asserttype(max_attempts)==int# noqa: E721
371+
asserttype(with_force)==bool# noqa: E721
372+
assertmax_attempts>0
373+
370374
attempts=0
375+
376+
# try stopping server N times
377+
whileattempts<max_attempts:
378+
attempts+=1
379+
try:
380+
self.stop()
381+
exceptExecUtilException:
382+
continue# one more time
383+
exceptException:
384+
eprint('cannot stop node {}'.format(self.name))
385+
break
386+
387+
return# OK
388+
389+
# If force stopping is enabled and PID is valid
390+
ifnotwith_force:
391+
returnFalse
392+
371393
node_pid=self.pid
394+
assertnode_pidisnotNone
395+
asserttype(node_pid)==int# noqa: E721
372396

373-
ifnode_pid>0:
374-
# try stopping server N times
375-
whileattempts<max_attempts:
376-
try:
377-
self.stop()
378-
break# OK
379-
exceptExecUtilException:
380-
pass# one more time
381-
exceptException:
382-
eprint('cannot stop node {}'.format(self.name))
383-
break
384-
385-
attempts+=1
386-
387-
# If force stopping is enabled and PID is valid
388-
ifwith_forceandnode_pid!=0:
389-
# If we couldn't stop the node
390-
p_status_output=self.os_ops.exec_command(cmd=f'ps -o pid= -p{node_pid}',shell=True,ignore_errors=True).decode('utf-8')
391-
ifself.status()!=NodeStatus.Stoppedandp_status_outputandstr(node_pid)inp_status_output:
392-
try:
393-
eprint(f'Force stopping node{self.name} with PID{node_pid}')
394-
self.os_ops.kill(node_pid,signal.SIGKILL,expect_error=False)
395-
exceptException:
396-
# The node has already stopped
397-
pass
398-
399-
# Check that node stopped - print only column pid without headers
400-
p_status_output=self.os_ops.exec_command(f'ps -o pid= -p{node_pid}',shell=True,ignore_errors=True).decode('utf-8')
401-
ifp_status_outputandstr(node_pid)inp_status_output:
402-
eprint(f'Failed to stop node{self.name}.')
403-
else:
404-
eprint(f'Node{self.name} has been stopped successfully.')
397+
ifnode_pid==0:
398+
return
399+
400+
# TODO: [2025-02-28] It is really the old ugly code. We have to rewrite it!
401+
402+
ps_command= ['ps','-o','pid=','-p',str(node_pid)]
403+
404+
ps_output=self.os_ops.exec_command(cmd=ps_command,shell=True,ignore_errors=True).decode('utf-8')
405+
asserttype(ps_output)==str# noqa: E721
406+
407+
ifps_output=="":
408+
return
409+
410+
ifps_output!=str(node_pid):
411+
__class__._throw_bugcheck__unexpected_result_of_ps(
412+
ps_output,
413+
ps_command)
414+
415+
try:
416+
eprint('Force stopping node {0} with PID {1}'.format(self.name,node_pid))
417+
self.os_ops.kill(node_pid,signal.SIGKILL,expect_error=False)
418+
exceptException:
419+
# The node has already stopped
420+
pass
421+
422+
# Check that node stopped - print only column pid without headers
423+
ps_output=self.os_ops.exec_command(cmd=ps_command,shell=True,ignore_errors=True).decode('utf-8')
424+
asserttype(ps_output)==str# noqa: E721
425+
426+
ifps_output=="":
427+
eprint('Node {0} has been stopped successfully.'.format(self.name))
428+
return
429+
430+
ifps_output==str(node_pid):
431+
eprint('Failed to stop node {0}.'.format(self.name))
432+
return
433+
434+
__class__._throw_bugcheck__unexpected_result_of_ps(
435+
ps_output,
436+
ps_command)
437+
438+
@staticmethod
439+
def_throw_bugcheck__unexpected_result_of_ps(result,cmd):
440+
asserttype(result)==str# noqa: E721
441+
asserttype(cmd)==list# noqa: E721
442+
errLines= []
443+
errLines.append("[BUG CHECK] Unexpected result of command ps:")
444+
errLines.append(result)
445+
errLines.append("-----")
446+
errLines.append("Command line is {0}".format(cmd))
447+
raiseRuntimeError("\n".join(errLines))
405448

406449
def_assign_master(self,master):
407450
"""NOTE: this is a private method!"""

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp