Skip to content

Commit ace5385

Browse files
jnihalavamingli
authored andcommitted
Replace netstat with ss (code cleanup)
netstat has been replaced with ss earlier but some of the variable names and commented out codes were left as it is. This commit cleans up the old mentions of netstat and changes the variable names to avoid any confusion in the future.
1 parent 831f6a3 commit ace5385

File tree

5 files changed

+30
-32
lines changed

5 files changed

+30
-32
lines changed

gpMgmt/bin/gppylib/commands/gp.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1564,12 +1564,12 @@ def chk_local_db_running(datadir, port):
15641564
tmpfile_exists = os.path.exists("/tmp/.s.PGSQL.%d" % port)
15651565
lockfile_exists = os.path.exists(get_lockfile_name(port))
15661566

1567-
netstat_port_active = PgPortIsActive.local('check ss for postmaster port',"/tmp/.s.PGSQL.%d" % port, port)
1567+
ss_port_active = PgPortIsActive.local('check ss for postmaster port',"/tmp/.s.PGSQL.%d" % port, port)
15681568

15691569
logger.debug("postmaster_pid_exists: %s tmpfile_exists: %s lockfile_exists: %s ss port: %s pid: %s" %\
1570-
(postmaster_pid_exists, tmpfile_exists, lockfile_exists, netstat_port_active, pid_value))
1570+
(postmaster_pid_exists, tmpfile_exists, lockfile_exists, ss_port_active, pid_value))
15711571

1572-
return (postmaster_pid_exists, tmpfile_exists, lockfile_exists, netstat_port_active, pid_value)
1572+
return (postmaster_pid_exists, tmpfile_exists, lockfile_exists, ss_port_active, pid_value)
15731573

15741574
def get_lockfile_name(port):
15751575
return "/tmp/.s.PGSQL.%d.lock" % port

gpMgmt/bin/gppylib/commands/unix.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -625,8 +625,8 @@ def contains_port(self):
625625

626626
for r in rows:
627627
val = r.split('.')
628-
netstatport = int(val[len(val) - 1])
629-
if netstatport == self.port:
628+
ssport = int(val[len(val) - 1])
629+
if ssport == self.port:
630630
return True
631631

632632
return False

gpMgmt/bin/gpstart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -392,17 +392,17 @@ class GpStart:
392392
lockfile = "/tmp/.s.PGSQL.%s" % self.port
393393
tmpfile_exists = os.path.exists(lockfile)
394394

395-
netstat_port_active = unix.PgPortIsActive.local('check ss for coordinator port',
395+
ss_port_active = unix.PgPortIsActive.local('check ss for coordinator port',
396396
lockfile, self.port)
397-
if tmpfile_exists and netstat_port_active:
397+
if tmpfile_exists and ss_port_active:
398398
logger.info("Have lock file %s and a process running on port %s" % (lockfile, self.port))
399399
raise ExceptionNoStackTraceNeeded("Coordinator instance process running")
400-
elif tmpfile_exists and not netstat_port_active:
400+
elif tmpfile_exists and not ss_port_active:
401401
logger.info("Have lock file %s but no process running on port %s" % (lockfile, self.port))
402-
elif not tmpfile_exists and netstat_port_active:
402+
elif not tmpfile_exists and ss_port_active:
403403
logger.info("No lock file %s but a process running on port %s" % (lockfile, self.port))
404404
raise ExceptionNoStackTraceNeeded("Port %s is already in use" % self.port)
405-
elif not tmpfile_exists and not netstat_port_active:
405+
elif not tmpfile_exists and not ss_port_active:
406406
logger.info("No socket connection or lock file in /tmp found for port=%s" % self.port)
407407

408408
logger.info("No Coordinator instance process, entering recovery startup mode")

gpMgmt/bin/lib/gp_bash_functions.sh

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -857,32 +857,31 @@ GET_PG_PID_ACTIVE () {
857857
PORT=$1;shift
858858
HOST=$1
859859
PG_LOCK_FILE="/tmp/.s.PGSQL.${PORT}.lock"
860-
PG_LOCK_NETSTAT=""
860+
PG_LOCK_SS=""
861861
if [ x"" == x"$HOST" ];then
862-
#See if we have a netstat entry for this local host
862+
#See if we have a ss entry for this local host
863863
PORT_ARRAY=(`$SS -an 2>/dev/null |$AWK '{for (i =1; i<=NF ; i++) if ($i==".s.PGSQL.${PORT}") print $i}'|$AWK -F"." '{print $NF}'|$SORT -u`)
864864
for P_CHK in ${PORT_ARRAY[@]}
865865
do
866-
if [ $P_CHK -eq $PORT ];then PG_LOCK_NETSTAT=$PORT;fi
866+
if [ $P_CHK -eq $PORT ];then PG_LOCK_SS=$PORT;fi
867867
done
868-
#PG_LOCK_NETSTAT=`$NETSTAT -an 2>/dev/null |$GREP ".s.PGSQL.${PORT}"|$AWK '{print $NF}'|$HEAD -1`
869868
#See if we have a lock file in /tmp
870869
if [ -f ${PG_LOCK_FILE} ];then
871870
PG_LOCK_TMP=1
872871
else
873872
PG_LOCK_TMP=0
874873
fi
875-
if [ x"" == x"$PG_LOCK_NETSTAT" ] && [ $PG_LOCK_TMP -eq 0 ];then
874+
if [ x"" == x"$PG_LOCK_SS" ] && [ $PG_LOCK_TMP -eq 0 ];then
876875
PID=0
877876
LOG_MSG "[INFO]:-No socket connection or lock file in /tmp found for port=${PORT}"
878877
else
879878
#Now check the failure combinations
880-
if [ $PG_LOCK_TMP -eq 0 ] && [ x"" != x"$PG_LOCK_NETSTAT" ];then
879+
if [ $PG_LOCK_TMP -eq 0 ] && [ x"" != x"$PG_LOCK_SS" ];then
881880
#Have a process but no lock file
882881
LOG_MSG "[WARN]:-No lock file $PG_LOCK_FILE but process running on port $PORT" 1
883882
PID=1
884883
fi
885-
if [ $PG_LOCK_TMP -eq 1 ] && [ x"" == x"$PG_LOCK_NETSTAT" ];then
884+
if [ $PG_LOCK_TMP -eq 1 ] && [ x"" == x"$PG_LOCK_SS" ];then
886885
#Have a lock file but no process
887886
if [ -r ${PG_LOCK_FILE} ];then
888887
PID=`$CAT ${PG_LOCK_FILE}|$HEAD -1|$AWK '{print $1}'`
@@ -892,8 +891,8 @@ GET_PG_PID_ACTIVE () {
892891
fi
893892
LOG_MSG "[WARN]:-Have lock file $PG_LOCK_FILE but no process running on port $PORT" 1
894893
fi
895-
if [ $PG_LOCK_TMP -eq 1 ] && [ x"" != x"$PG_LOCK_NETSTAT" ];then
896-
#Have both a lock file and a netstat process
894+
if [ $PG_LOCK_TMP -eq 1 ] && [ x"" != x"$PG_LOCK_SS" ];then
895+
#Have both a lock file and a ss process
897896
if [ -r ${PG_LOCK_FILE} ];then
898897
PID=`$CAT ${PG_LOCK_FILE}|$HEAD -1|$AWK '{print $1}'`
899898
else
@@ -911,21 +910,20 @@ GET_PG_PID_ACTIVE () {
911910
PORT_ARRAY=($( REMOTE_EXECUTE_AND_GET_OUTPUT $HOST "$SS -an 2>/dev/null |$AWK '{for (i =1; i<=NF ; i++) if (\$i==\".s.PGSQL.${PORT}\") print \$i}'|$AWK -F\".\" '{print \$NF}'|$SORT -u"))
912911
for P_CHK in ${PORT_ARRAY[@]}
913912
do
914-
if [ $P_CHK -eq $PORT ];then PG_LOCK_NETSTAT=$PORT;fi
913+
if [ $P_CHK -eq $PORT ];then PG_LOCK_SS=$PORT;fi
915914
done
916-
#PG_LOCK_NETSTAT=`$TRUSTED_SHELL $HOST "$NETSTAT -an 2>/dev/null |$GREP ".s.PGSQL.${PORT}" 2>/dev/null"|$AWK '{print $NF}'|$HEAD -1`
917915
PG_LOCK_TMP=$( REMOTE_EXECUTE_AND_GET_OUTPUT $HOST "ls ${PG_LOCK_FILE} 2>/dev/null|$WC -l" )
918-
if [ x"" == x"$PG_LOCK_NETSTAT" ] && [ $PG_LOCK_TMP -eq 0 ];then
916+
if [ x"" == x"$PG_LOCK_SS" ] && [ $PG_LOCK_TMP -eq 0 ];then
919917
PID=0
920918
LOG_MSG "[INFO]:-No socket connection or lock file $PG_LOCK_FILE found for port=${PORT}"
921919
else
922920
#Now check the failure combinations
923-
if [ $PG_LOCK_TMP -eq 0 ] && [ x"" != x"$PG_LOCK_NETSTAT" ];then
921+
if [ $PG_LOCK_TMP -eq 0 ] && [ x"" != x"$PG_LOCK_SS" ];then
924922
#Have a process but no lock file
925923
LOG_MSG "[WARN]:-No lock file $PG_LOCK_FILE but process running on port $PORT on $HOST" 1
926924
PID=1
927925
fi
928-
if [ $PG_LOCK_TMP -eq 1 ] && [ x"" == x"$PG_LOCK_NETSTAT" ];then
926+
if [ $PG_LOCK_TMP -eq 1 ] && [ x"" == x"$PG_LOCK_SS" ];then
929927
#Have a lock file but no process
930928
CAN_READ=$( REMOTE_EXECUTE_AND_GET_OUTPUT $HOST "if [ -r ${PG_LOCK_FILE} ];then echo 1;else echo 0;fi" )
931929

@@ -937,8 +935,8 @@ GET_PG_PID_ACTIVE () {
937935
LOG_MSG "[WARN]:-Have lock file $PG_LOCK_FILE but no process running on port $PORT on $HOST" 1
938936
PID=1
939937
fi
940-
if [ $PG_LOCK_TMP -eq 1 ] && [ x"" != x"$PG_LOCK_NETSTAT" ];then
941-
#Have both a lock file and a netstat process
938+
if [ $PG_LOCK_TMP -eq 1 ] && [ x"" != x"$PG_LOCK_SS" ];then
939+
#Have both a lock file and a ss process
942940
CAN_READ=$( REMOTE_EXECUTE_AND_GET_OUTPUT $HOST "if [ -r ${PG_LOCK_FILE} ];then echo 1;else echo 0;fi" )
943941
if [ $CAN_READ -eq 1 ];then
944942
PID=$( REMOTE_EXECUTE_AND_GET_OUTPUT $HOST "$CAT ${PG_LOCK_FILE}|$HEAD -1 2>/dev/null"|$AWK '{print $1}' )

gpMgmt/sbin/gpgetstatususingtransition.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,17 +119,17 @@ def getPidStatus(self, seg, pidRunningStatus):
119119
"""
120120

121121
lockFileExists = pidRunningStatus['lockFileExists']
122-
netstatPortActive = pidRunningStatus['netstatPortActive']
122+
ssPortActive = pidRunningStatus['ssPortActive']
123123
pidValue = pidRunningStatus['pidValue']
124124

125125
lockFileName = gp.get_lockfile_name(seg.getSegmentPort())
126126

127127
error = None
128-
if not lockFileExists and not netstatPortActive:
128+
if not lockFileExists and not ssPortActive:
129129
error = "No socket connection or lock file (%s) found for port %s" % (lockFileName, seg.getSegmentPort())
130-
elif not lockFileExists and netstatPortActive:
130+
elif not lockFileExists and ssPortActive:
131131
error = "No lock file %s but process running on port %s" % (lockFileName, seg.getSegmentPort())
132-
elif lockFileExists and not netstatPortActive:
132+
elif lockFileExists and not ssPortActive:
133133
error = "Have lock file %s but no process running on port %s" % (lockFileName, seg.getSegmentPort())
134134
else:
135135
if pidValue == 0:
@@ -145,14 +145,14 @@ def getPidRunningStatus(self, seg):
145145
"""
146146
Get an object containing various information about the postmaster pid's status
147147
"""
148-
(postmasterPidFileExists, tempFileExists, lockFileExists, netstatPortActive, pidValue) = \
148+
(postmasterPidFileExists, tempFileExists, lockFileExists, ssPortActive, pidValue) = \
149149
gp.chk_local_db_running(seg.getSegmentDataDirectory(), seg.getSegmentPort())
150150

151151
return {
152152
'postmasterPidFileExists' : postmasterPidFileExists,
153153
'tempFileExists' : tempFileExists,
154154
'lockFileExists' : lockFileExists,
155-
'netstatPortActive' : netstatPortActive,
155+
'ssPortActive' : ssPortActive,
156156
'pidValue' : pidValue
157157
}
158158

0 commit comments

Comments
 (0)