Skip to content

Commit c69f669

Browse files
authored
Don't overwrite gpexpand template on the same host (#1100)
In RedOS, when both the master and a segment are on the same host, running gpexpand correctly was impossible. Typically, the master is excluded from the gpexpand host array. However, if both the master and a segment are on the same host, the master's host gets included in the array. The issue arises due to the scp command corrupting and truncating the gpexpand_schema.tar file when the host, source and destination paths are the same. Don't issue a scp command if we are dealing with the local host with and paths are the same. Note that gpexpand always uses relative filepaths for scp's destination, and that they are relative to /home/gpadmin/. This problem does not occur in GPDB 7, as it uses rsync instead of scp, which does not have said issue. Ticket: ADBDEV-6472
1 parent d995de5 commit c69f669

File tree

4 files changed

+41
-1
lines changed

4 files changed

+41
-1
lines changed

gpMgmt/bin/gpexpand

+13-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import sys
1515
import json
1616
import shutil
1717
import signal
18+
import socket
1819
import traceback
1920
from collections import defaultdict
2021
from time import strftime, sleep
@@ -773,8 +774,19 @@ class SegmentTemplate:
773774

774775
def _distribute_tarfile(self):
775776
"""Distributes template tar file to hosts"""
777+
localHostAddr = socket.gethostbyname(getLocalHostname())
778+
# NOTE: Currently, GP's scp transfers relative file paths into the home
779+
# directory by default.
780+
pathsAreSame = os.path.realpath(self.segTarFile) == os.path.join(getHomePath(), self.schema_tar_file)
781+
776782
for host in self.hosts:
777-
logger.debug('Copying tar file to %s' % host)
783+
# If the source and the destination are the same on the local
784+
# machine, scp may corrupt the file. Don't overwrite it.
785+
if socket.gethostbyname(host) == localHostAddr and pathsAreSame:
786+
logger.debug('Skipping tar file (%s) copy to %s' % (self.schema_tar_file, host))
787+
continue
788+
789+
logger.debug('Copying tar file (%s) to %s' % (self.schema_tar_file, host))
778790
cpCmd = Scp(name='gpexpand distribute tar file to new hosts',
779791
srcFile=self.schema_tar_file,
780792
dstFile=self.segTarDir,

gpMgmt/bin/gppylib/commands/unix.py

+4
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ def getUserName():
8181
return pwd.getpwuid(os.getuid()).pw_name
8282

8383

84+
def getHomePath():
85+
return pwd.getpwuid(os.getuid()).pw_dir
86+
87+
8488
def check_pid_on_remotehost(pid, host):
8589
""" Check For the existence of a unix pid on remote host. """
8690

gpMgmt/test/behave/mgmt_utils/gpexpand.feature

+19
Original file line numberDiff line numberDiff line change
@@ -804,3 +804,22 @@ Feature: expand the cluster by adding more segments
804804
And table "test_good_2" should be marked as expanded
805805
And table "test_already_expanded" should be marked as expanded
806806
And table "test_broken" should not be marked as expanded
807+
808+
@gpexpand_avoid_tarfile_overwrite
809+
Scenario: Avoid overwriting the tar file on coordinator
810+
Given the database is not running
811+
# need to remove this log because otherwise SCAN_LOG may pick up a previous error/warning in the log
812+
And the user runs command "rm -rf ~/gpAdminLogs/gpinitsystem*"
813+
# gpconfigurenewsegment scp's tar file to home by default
814+
And a working directory of the test as '/data/gpdata/gpexpand'
815+
And a temporary directory under "/data/gpdata/gpexpand/expandedData" to expand into
816+
And the cluster is generated with "1" primaries only
817+
And database "gptest" exists
818+
And the directory is changed to '/home/gpadmin'
819+
And there are no gpexpand_inputfiles
820+
And the cluster is setup for an expansion on hosts "localhost"
821+
When the user runs gpexpand interview to add 1 new segment and 0 new host "ignored.host"
822+
Then the number of segments have been saved
823+
When the user runs gpexpand with the latest gpexpand_inputfile with additional parameters "--verbose"
824+
Then gpexpand should print "[DEBUG]:-Skipping tar file (gpexpand_schema.tar) copy to cdw" escaped to stdout
825+
And verify that the cluster has 1 new segments

gpMgmt/test/behave/mgmt_utils/steps/mgmt_utils.py

+5
Original file line numberDiff line numberDiff line change
@@ -3038,6 +3038,11 @@ def impl(context, working_directory, mode):
30383038
def impl(context, working_directory):
30393039
_create_working_directory(context, working_directory)
30403040

3041+
@given("the directory is changed to '{working_directory}'")
3042+
def impl(context, working_directory):
3043+
context.working_directory = working_directory
3044+
os.chdir(working_directory)
3045+
30413046
def _create_working_directory(context, working_directory, mode=''):
30423047
context.working_directory = working_directory
30433048
# Don't fail if directory already exists, which can occur for the first scenario

0 commit comments

Comments
 (0)