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

Commit09976ae

Browse files
PostgresNode::_try_shutdown is rewrited (normalization)
1 parent3cc1627 commit09976ae

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
@@ -338,41 +338,84 @@ def version(self):
338338
returnself._pg_version
339339

340340
def_try_shutdown(self,max_attempts,with_force=False):
341+
asserttype(max_attempts)==int# noqa: E721
342+
asserttype(with_force)==bool# noqa: E721
343+
assertmax_attempts>0
344+
341345
attempts=0
346+
347+
# try stopping server N times
348+
whileattempts<max_attempts:
349+
attempts+=1
350+
try:
351+
self.stop()
352+
exceptExecUtilException:
353+
continue# one more time
354+
exceptException:
355+
eprint('cannot stop node {}'.format(self.name))
356+
break
357+
358+
return# OK
359+
360+
# If force stopping is enabled and PID is valid
361+
ifnotwith_force:
362+
returnFalse
363+
342364
node_pid=self.pid
365+
assertnode_pidisnotNone
366+
asserttype(node_pid)==int# noqa: E721
343367

344-
ifnode_pid>0:
345-
# try stopping server N times
346-
whileattempts<max_attempts:
347-
try:
348-
self.stop()
349-
break# OK
350-
exceptExecUtilException:
351-
pass# one more time
352-
exceptException:
353-
eprint('cannot stop node {}'.format(self.name))
354-
break
355-
356-
attempts+=1
357-
358-
# If force stopping is enabled and PID is valid
359-
ifwith_forceandnode_pid!=0:
360-
# If we couldn't stop the node
361-
p_status_output=self.os_ops.exec_command(cmd=f'ps -o pid= -p{node_pid}',shell=True,ignore_errors=True).decode('utf-8')
362-
ifself.status()!=NodeStatus.Stoppedandp_status_outputandstr(node_pid)inp_status_output:
363-
try:
364-
eprint(f'Force stopping node{self.name} with PID{node_pid}')
365-
self.os_ops.kill(node_pid,signal.SIGKILL,expect_error=False)
366-
exceptException:
367-
# The node has already stopped
368-
pass
369-
370-
# Check that node stopped - print only column pid without headers
371-
p_status_output=self.os_ops.exec_command(f'ps -o pid= -p{node_pid}',shell=True,ignore_errors=True).decode('utf-8')
372-
ifp_status_outputandstr(node_pid)inp_status_output:
373-
eprint(f'Failed to stop node{self.name}.')
374-
else:
375-
eprint(f'Node{self.name} has been stopped successfully.')
368+
ifnode_pid==0:
369+
return
370+
371+
# TODO: [2025-02-28] It is really the old ugly code. We have to rewrite it!
372+
373+
ps_command= ['ps','-o','pid=','-p',str(node_pid)]
374+
375+
ps_output=self.os_ops.exec_command(cmd=ps_command,shell=True,ignore_errors=True).decode('utf-8')
376+
asserttype(ps_output)==str# noqa: E721
377+
378+
ifps_output=="":
379+
return
380+
381+
ifps_output!=str(node_pid):
382+
__class__._throw_bugcheck__unexpected_result_of_ps(
383+
ps_output,
384+
ps_command)
385+
386+
try:
387+
eprint('Force stopping node {0} with PID {1}'.format(self.name,node_pid))
388+
self.os_ops.kill(node_pid,signal.SIGKILL,expect_error=False)
389+
exceptException:
390+
# The node has already stopped
391+
pass
392+
393+
# Check that node stopped - print only column pid without headers
394+
ps_output=self.os_ops.exec_command(cmd=ps_command,shell=True,ignore_errors=True).decode('utf-8')
395+
asserttype(ps_output)==str# noqa: E721
396+
397+
ifps_output=="":
398+
eprint('Node {0} has been stopped successfully.'.format(self.name))
399+
return
400+
401+
ifps_output==str(node_pid):
402+
eprint('Failed to stop node {0}.'.format(self.name))
403+
return
404+
405+
__class__._throw_bugcheck__unexpected_result_of_ps(
406+
ps_output,
407+
ps_command)
408+
409+
@staticmethod
410+
def_throw_bugcheck__unexpected_result_of_ps(result,cmd):
411+
asserttype(result)==str# noqa: E721
412+
asserttype(cmd)==list# noqa: E721
413+
errLines= []
414+
errLines.append("[BUG CHECK] Unexpected result of command ps:")
415+
errLines.append(result)
416+
errLines.append("-----")
417+
errLines.append("Command line is {0}".format(cmd))
418+
raiseRuntimeError("\n".join(errLines))
376419

377420
def_assign_master(self,master):
378421
"""NOTE: this is a private method!"""

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp