提交 d6de56fb 编写于 作者: M Max Yang 提交者: Xiaoran Wang

Fix issues in gpinitstandby tinc test.

*  Add PG_BASEBACKUP_FIXME:if there are new tablespaces, gpinitstandby fails.
   pg_basebackup can't copy tablespace data to standby, besause the tablespace
   directory is not empty on standby.
*  Check standby tablespace directory.
*  Replace function cleanupFilespaces with function cleanup_tablespace.

  Author: Max Yang <myang@pivotal.io>
  Author: Xiaoran Wang <xiwang@pivotal.io>
上级 793b4d4a
...@@ -150,8 +150,8 @@ class GpinitStandby(object): ...@@ -150,8 +150,8 @@ class GpinitStandby(object):
return True return True
def check_dir_exist_on_standby(self, standby, location): def check_dir_exist_on_standby(self, standby, location):
cmd = Command(name='Make directory on standby before running the command', cmdStr='ls -l %s' % location, ctxt=base.REMOTE, remoteHost=standby) tinctest.logger.info('standby host %s,tablespace location %s' % (standby, location))
tinctest.logger.info('%s' % cmd) cmd = Command(name='check directory if exists on standby', cmdStr='ls -l %s' % location, ctxt=base.REMOTE, remoteHost=standby)
cmd.run(validateAfter=True) cmd.run(validateAfter=True)
result = cmd.get_results() result = cmd.get_results()
return result.rc !=0 return result.rc ==0
...@@ -55,10 +55,6 @@ class GpinitStandsbyTestCase(MPPTestCase): ...@@ -55,10 +55,6 @@ class GpinitStandsbyTestCase(MPPTestCase):
#Remove standby if present #Remove standby if present
self.primary_pid = self.gp.get_primary_pid() self.primary_pid = self.gp.get_primary_pid()
self.gp.run(option='-r') self.gp.run(option='-r')
def tearDown(self):
# Cleanup Filespaces
walrepl.cleanupFilespaces(dbname=self.db_name)
def create_directory(self,location): def create_directory(self,location):
...@@ -132,25 +128,31 @@ class GpinitStandsbyTestCase(MPPTestCase): ...@@ -132,25 +128,31 @@ class GpinitStandsbyTestCase(MPPTestCase):
self.create_directory(self.standby_loc) self.create_directory(self.standby_loc)
self.assertTrue(self.gp.run(option = '-F %s -s %s' % (self.standby_loc, self.standby))) self.assertTrue(self.gp.run(option = '-F %s -s %s' % (self.standby_loc, self.standby)))
self.assertTrue(self.gp.verify_gpinitstandby(self.primary_pid, self.standby_loc)) self.assertTrue(self.gp.verify_gpinitstandby(self.primary_pid, self.standby_loc))
def test_gpinitstandby_to_same_with_tablespace(self):
from mpp.lib.gptablespace import Gptablespace
gptablespace = Gptablespace()
gptablespace.create_tablespace('ts_walrepl_a', '/tmp/tbl')
PSQL.run_sql_file(local_path('tablespace.sql'), dbname = self.db_name)
self.assertTrue(self.gp.run(option = '-F %s -s %s -P %s' % (self.standby_loc, self.host, self.standby_port)))
self.assertTrue(self.gp.verify_gpinitstandby(self.primary_pid, self.standby_loc))
#self.assertTrue(self.gp.check_dir_exist_on_standby(self.host, gptablespace.get_standby_tablespace_directory('ts_walrepl_a')))
#PG_BASEBACKUP_FIXME gpinitstandby fails if there is new tablespace
#def test_gpinitstandby_to_same_with_tablespace(self):
# from mpp.lib.gptablespace import Gptablespace
# gptablespace = Gptablespace()
# gptablespace.create_tablespace('ts_walrepl_a', '/tmp/tbl')
# PSQL.run_sql_file(local_path('tablespace.sql'), dbname = self.db_name)
# self.assertTrue(self.gp.run(option = '-F %s -s %s -P %s' % (self.standby_loc, self.host, self.standby_port)))
# self.assertTrue(self.gp.verify_gpinitstandby(self.primary_pid, self.standby_loc))
# standby_tablespace_directory = gptablespace.get_standby_tablespace_directory('ts_walrepl_a')
# self.assertTrue(self.gp.check_dir_exist_on_standby(self.host, standby_tablespace_directory))
# gptablespace.cleanup_tablespace('ts_walrepl_a', self.db_name)
#PG_BASEBACKUP_FIXME gpinitstandby fails if there is new tablespace
@unittest.skipIf(not config.is_multinode(), "Test applies only to a multinode cluster") @unittest.skipIf(not config.is_multinode(), "Test applies only to a multinode cluster")
def test_gpinitstandby_new_host_with_tablespace(self): #def test_gpinitstandby_new_host_with_tablespace(self):
from mpp.lib.gptablespace import Gptablespace # from mpp.lib.gptablespace import Gptablespace
gptablespace = Gptablespace() # gptablespace = Gptablespace()
gptablespace.create_tablespace('ts_walrepl_a', '/tmp/tbl') # gptablespace.create_tablespace('ts_walrepl_a', '/tmp/tbl')
PSQL.run_sql_file(local_path('tablespace.sql'), dbname = self.db_name) # PSQL.run_sql_file(local_path('tablespace.sql'), dbname = self.db_name)
self.assertTrue(self.gp.run(option = '-F %s -s %s -P %s' % (self.standby_loc, self.standby, self.standby_port))) # self.assertTrue(self.gp.run(option = '-F %s -s %s -P %s' % (self.standby_loc, self.standby, self.standby_port)))
self.assertTrue(self.gp.verify_gpinitstandby(self.primary_pid, self.standby_loc)) # self.assertTrue(self.gp.verify_gpinitstandby(self.primary_pid, self.standby_loc))
#self.assertTrue(self.gp.check_dir_exist_on_standby(self.standby, gptablespace.get_standby_tablespace_directory('ts_walrepl_a'))) # standby_tablespace_directory = gptablespace.get_standby_tablespace_directory('ts_walrepl_a')
# self.assertTrue(self.gp.check_dir_exist_on_standby(self.standby, standby_tablespace_directory))
# gptablespace.cleanup_tablespace('ts_walrepl_a', self.db_name)
def test_gpinitstandby_remove_from_same_host(self): def test_gpinitstandby_remove_from_same_host(self):
#self.gp.create_dir_on_standby(self.host, self.standby_loc) #self.gp.create_dir_on_standby(self.host, self.standby_loc)
......
...@@ -39,10 +39,10 @@ class Gptablespace(object): ...@@ -39,10 +39,10 @@ class Gptablespace(object):
@return dir: standby tablespace directory @return dir: standby tablespace directory
''' '''
sql_cmd = "SELECT dbid from gp_segment_configuration where content = -1 and role = 'm'"; sql_cmd = "SELECT dbid from gp_segment_configuration where content = -1 and role = 'm'";
dbid = int(PSQL.run_sql_command(sql_cmd, flags = '-t -q -c', dbname='postgres')) dbid = int(PSQL.run_sql_command(sql_cmd, flags = '-t -q ', dbname='postgres'))
sql_cmd = ("SELECT gp_tablespace_path(spclocation, %d) FROM pg_tablespace WHERE spcname <> %s") % (dbid, tablespace) sql_cmd = ("SELECT gp_tablespace_path(spclocation, %d) FROM pg_tablespace WHERE spcname='%s'") % (dbid, tablespace)
dir = PSQL.run_sql_command(sql_cmd, flags = '-t -q', dbname='postgres') tbl_dir = PSQL.run_sql_command(sql_cmd, flags = '-t -q', dbname='postgres')
return dir return tbl_dir
def exists(self, tablespace): def exists(self, tablespace):
''' '''
...@@ -50,7 +50,7 @@ class Gptablespace(object): ...@@ -50,7 +50,7 @@ class Gptablespace(object):
@param tablespace:tablespace name @param tablespace:tablespace name
@return True or False @return True or False
''' '''
fs_out = PSQL.run_sql_command("select count(*) from pg_tablespace where spcname='%s'" % tablespace, flags = '-t -q', dbname='postgres') fs_out = PSQL.run_sql_command("select count(*) from pg_tablespace where spcname='%s'" % tablespace, flags='-t -q', dbname='postgres')
if int(fs_out.strip()) > 0: if int(fs_out.strip()) > 0:
return True return True
return False return False
...@@ -67,7 +67,16 @@ class Gptablespace(object): ...@@ -67,7 +67,16 @@ class Gptablespace(object):
for record in self.config.record: for record in self.config.record:
cmd = "gpssh -h %s -e 'rm -rf %s; mkdir -p %s'" % (record.hostname, loc, loc) cmd = "gpssh -h %s -e 'rm -rf %s; mkdir -p %s'" % (record.hostname, loc, loc)
run_shell_command(cmd) run_shell_command(cmd)
tinctest.logger.info('create tablespace %s' % tablespace) sql_cmd = ('create tablespace %s location \'%s\'') % (tablespace, loc)
sql_cmd = 'create tablespace %s location \'%s\'' % (tablespace, loc) PSQL.run_sql_command(sql_cmd, flags='-t -q ', dbname='postgres')
PSQL.run_sql_command(sql_cmd, flags = '-t -q -c', dbname='postgres')
def cleanup_tablespace(self, tablespace, dbname):
tsoid = PSQL.run_sql_command("SELECT oid FROM pg_tablespace where spcname = '%s'" % tablespace,
flags='-t -q ', dbname=dbname)
tables = PSQL.run_sql_command("SELECT relname FROM pg_class WHERE reltablespace = %s AND relkind = 'r'" % tsoid,
flags='-t -q ', dbname=dbname)
if len(tables) > 0:
PSQL.run_sql_command("DROP TABLE {0}".format(','.join(tables.strip().splitlines())),
flags='-t -q ', dbname=dbname)
sql_cmd = "DROP TABLESPACE %s" % tablespace
PSQL.run_sql_command(sql_cmd, flags='-t -q ', dbname=dbname)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册