From 0aa77ec625f662d2cb38ed907533d716f6f98a75 Mon Sep 17 00:00:00 2001 From: "Ricardo.Cui" Date: Mon, 1 Feb 2021 11:36:35 +0800 Subject: [PATCH] master branch merge --- script/gspylib/common/DbClusterInfo.py | 53 ++++++++++++++++++++--- script/gspylib/component/Kernel/Kernel.py | 3 ++ 2 files changed, 50 insertions(+), 6 deletions(-) diff --git a/script/gspylib/common/DbClusterInfo.py b/script/gspylib/common/DbClusterInfo.py index f59044ac..d1e3e02d 100644 --- a/script/gspylib/common/DbClusterInfo.py +++ b/script/gspylib/common/DbClusterInfo.py @@ -1085,7 +1085,7 @@ class dbNodeInfo(): elif (instRole == INSTANCE_ROLE_DATANODE): dbInst.port = self.__assignNewInstancePort(self.datanodes, instRole, instanceType) - dbInst.haPort = dbInst.port + 1 + dbInst.haPort = dbInst.port + 7 dbInst.ssdDir = ssddir dbInst.syncNum = syncNum self.datanodes.append(dbInst) @@ -1499,8 +1499,13 @@ class dbClusterInfo(): "sync_percent : %s\n" % i_loop[10]) outText = outText + ( - "sync_state : %s\n\n" % + "sync_state : %s\n" % i_loop[11]) + if dnInst.localRole == "Cascade Standby": + outText = outText + ( + "upstream_nodeIp : %s\n" % + i_loop[12]) + outText = outText + ("\n") outText = outText + "------------------------" \ "---------------" \ "--------------------------------\n\n" @@ -1848,10 +1853,45 @@ class dbClusterInfo(): continue for col_loop in output: syncInfo.append(col_loop.split('|')) + elif dnInst.localRole == "Cascade Standby": + subsql = "select state, sender_sent_location, sender_write_location," \ + "sender_flush_location, sender_replay_location," \ + "receiver_received_location, receiver_write_location," \ + "receiver_flush_location, receiver_replay_location," \ + "sync_percent, channel from pg_stat_get_wal_receiver();" + cascadeOutput = "" + if dbNode.name != localHostName: + cmd = "[need_replace_quotes] gsql -m -d postgres -p " \ + "%s -A -t -c \"%s\"" % \ + (dnInst.port, subsql) + (statusMap, cascadeOutput) = sshtool.getSshStatusOutput(cmd, [ + dbNode.name]) + if statusMap[dbNode.name] != 'Success' or cascadeOutput.find( + "failed to connect") >= 0: + continue + else: + output = cascadeOutput.split('\n')[1:-1] + else: + cmd = "gsql -m -d postgres -p %s -A -t -c \"%s\"" % ( + dnInst.port, subsql) + (status, cascadeOutput) = subprocess.getstatusoutput(cmd) + if status != 0 or cascadeOutput.find( + "failed to connect") >= 0: + continue + else: + cascadeOutput = cascadeOutput.split('\n') + if not len(cascadeOutput): + continue + for col_loop in cascadeOutput: + col_loop = col_loop.split('|') + cascadeIps = col_loop[-1].split('<--') + col_loop.insert(0, cascadeIps[0].split(':')[0]) + col_loop.insert(11, "Async") + col_loop[-1] = cascadeIps[-1] + syncInfo.append(col_loop) else: if dnInst.localRole != "Standby" and \ - dnInst.localRole != "Secondary" and \ - dnInst.localRole != "Cascade Standby": + dnInst.localRole != "Secondary": clusterState = "Degraded" if dnInst.state != "Normal": clusterState = "Degraded" @@ -3401,6 +3441,7 @@ class dbClusterInfo(): input : [] output : NA """ + # port range from +1 to +7, here define haPort = dataportBase+7 for dbNode in self.dbNodes: i = 0 for dbInst in dbNode.datanodes: @@ -3408,11 +3449,11 @@ class dbClusterInfo(): dbInst.port = dbNode.masterBasePorts[ INSTANCE_ROLE_DATANODE] + i * \ PORT_STEP_SIZE - dbInst.haPort = dbInst.port + 1 + dbInst.haPort = dbInst.port + 7 peerInsts = self.__getPeerInstance(dbInst) for j in range(len(peerInsts)): peerInsts[j].port = dbInst.port - peerInsts[j].haPort = peerInsts[j].port + 1 + peerInsts[j].haPort = peerInsts[j].port + 7 i += 1 # flush CMSERVER instance port i = 0 diff --git a/script/gspylib/component/Kernel/Kernel.py b/script/gspylib/component/Kernel/Kernel.py index 5d45b31e..27726549 100644 --- a/script/gspylib/component/Kernel/Kernel.py +++ b/script/gspylib/component/Kernel/Kernel.py @@ -26,6 +26,7 @@ import time sys.path.append(sys.path[0] + "/../../../") from gspylib.common.ErrorCode import ErrorCode +from gspylib.common.GaussLog import GaussLog from gspylib.component.BaseComponent import BaseComponent from gspylib.os.gsfile import g_file from gspylib.common.Common import DefaultValue @@ -114,6 +115,8 @@ class Kernel(BaseComponent): if status != 0: raise Exception(ErrorCode.GAUSS_516["GAUSS_51610"] % "instance" + " Error: \n%s." % output) + if output.find("No such process"): + GaussLog.exitWithError(output) def isPidFileExist(self): pidFile = "%s/postmaster.pid" % self.instInfo.datadir -- Gitee