Example #1
0
 def check_stdby_stop(self):
     gpstdby = GpinitStandby()
     stdby_host = gpstdby.get_standbyhost()
     activate_stdby = GpactivateStandby()
     stdby_port = activate_stdby.get_standby_port()     
     master_pid = self.pgutil.get_pid_by_keyword(host=stdby_host, pgport=stdby_port, keyword="master", option = "bin")
     if int(master_pid) != -1:
         raise Exception("standby should stop but failed!")        
Example #2
0
 def check_stdby_stop(self):
     gpstdby = GpinitStandby()
     stdby_host = gpstdby.get_standbyhost()
     activate_stdby = GpactivateStandby()
     stdby_port = activate_stdby.get_standby_port()     
     master_pid = self.pgutil.get_pid_by_keyword(host=stdby_host, pgport=stdby_port, keyword="master", option = "bin")
     if int(master_pid) != -1:
         raise Exception("standby should stop but failed!")        
Example #3
0
 def start_stdby(self):
     gpstdby = GpinitStandby()
     stdby_host = gpstdby.get_standbyhost()
     stdby_dbid = self.get_standby_dbid()
     activate_stdby = GpactivateStandby()
     stdby_mdd = activate_stdby.get_standby_dd()
     stdby_port = activate_stdby.get_standby_port()
     cmd="pg_ctl -D %s -o '-p %s --gp_dbid=%s --gp_num_contents_in_cluster=2 --silent-mode=true -i -M master --gp_contentid=-1 -x 0 -E' start &"%(stdby_mdd, stdby_port, stdby_dbid)
     self.run_remote(stdby_host,cmd,stdby_port,stdby_mdd)
Example #4
0
 def start_stdby(self):
     gpstdby = GpinitStandby()
     stdby_host = gpstdby.get_standbyhost()
     stdby_dbid = self.get_standby_dbid()
     activate_stdby = GpactivateStandby()
     stdby_mdd = activate_stdby.get_standby_dd()
     stdby_port = activate_stdby.get_standby_port()
     cmd="pg_ctl -D %s -o '-p %s --gp_dbid=%s --gp_num_contents_in_cluster=2 --silent-mode=true -i -M master --gp_contentid=-1 -x 0 -E' start &"%(stdby_mdd, stdby_port, stdby_dbid)
     self.run_remote(stdby_host,cmd,stdby_port,stdby_mdd)
Example #5
0
 def start_stdby(self):
     gpstdby = GpinitStandby()
     stdby_host = gpstdby.get_standbyhost()
     stdby_dbid = self.get_standby_dbid()
     activate_stdby = GpactivateStandby()
     stdby_mdd = activate_stdby.get_standby_dd()
     stdby_port = activate_stdby.get_standby_port()
     cmd="pg_ctl -l postmaster.log -D %s -o '-p %s --gp_dbid=%s -i --gp_contentid=-1 -E' start &"%(stdby_mdd, stdby_port, stdby_dbid)
     self.run_remote(stdby_host,cmd,stdby_port,stdby_mdd)
Example #6
0
 def setUp(self):
     super(WalReplKillProcessScenarioTestCase, self).setUp()
     pgutil.check_and_start_gpdb()
     # We should forcibly recreate standby, as it might has been promoted.
     pgutil.remove_standby()
     pgutil.install_standby()
     gpact_stdby = GpactivateStandby()
     gpinit_stdb = GpinitStandby()
     WalReplKillProcessTestCase.stdby_port = gpact_stdby.get_standby_port()
     WalReplKillProcessTestCase.stdby_host = gpinit_stdb.get_standbyhost()
 def setUp(self):
     super(WalReplKillProcessScenarioTestCase, self).setUp()
     pgutil.check_and_start_gpdb()
     # We should forcibly recreate standby, as it might has been promoted.
     pgutil.remove_standby()
     pgutil.install_standby()
     gpact_stdby = GpactivateStandby()
     gpinit_stdb = GpinitStandby()
     WalReplKillProcessTestCase.stdby_port = gpact_stdby.get_standby_port()
     WalReplKillProcessTestCase.stdby_host = gpinit_stdb.get_standbyhost()
Example #8
0
 def setUp(self):
     pgutil.check_and_start_gpdb()
     # We should forcibly recreate standby, as it might has been promoted.
     # here we need to install locally, otherwise can not run remote sql
     pgutil.remove_standby()
     pgutil.install_standby(new_stdby_host=socket.gethostname())
     gpact_stdby = GpactivateStandby()
     gpinit_stdb = GpinitStandby()
     WalReplKillProcessTestCase.stdby_port = gpact_stdby.get_standby_port()
     WalReplKillProcessTestCase.stdby_host = gpinit_stdb.get_standbyhost()
     self.standby_dir = gpact_stdby.get_standby_dd()
 def setUp(self):
     pgutil.check_and_start_gpdb()
     # We should forcibly recreate standby, as it might has been promoted.
     # here we need to install locally, otherwise can not run remote sql
     pgutil.remove_standby()
     pgutil.install_standby(new_stdby_host=socket.gethostname())
     gpact_stdby = GpactivateStandby()
     gpinit_stdb = GpinitStandby()
     WalReplKillProcessTestCase.stdby_port = gpact_stdby.get_standby_port()
     WalReplKillProcessTestCase.stdby_host = gpinit_stdb.get_standbyhost()
     self.standby_dir = gpact_stdby.get_standby_dd()
 def test_gpactivatestandby_on_new_host(self):
     gputil.install_standby()
     initstdby = GpinitStandby()
     gpact_stdby = GpactivateStandby()
     self.mdd = gpact_stdby.get_standby_dd()
     self.host = initstdby.get_standbyhost()
     self.port = gpact_stdby.get_standby_port()
     self.standby_pid = gpact_stdby.get_standby_pid(self.host, self.port, self.mdd)
     PSQL.run_sql_file(local_path('create_tables.sql'), dbname = self.db_name)
     self.assertTrue(gpact_stdby.activate())
     self.assertTrue(gpact_stdby.verify_gpactivatestandby(self.standby_pid, self.host, self.port, self.mdd)) 
     gputil.failback_to_original_master(self.origin_mdd,self.host,self.mdd,self.port) 
Example #11
0
 def test_gpactivatestandby_on_new_host(self):
     gputil.install_standby()
     initstdby = GpinitStandby()
     gpact_stdby = GpactivateStandby()
     self.mdd = gpact_stdby.get_standby_dd()
     self.host = initstdby.get_standbyhost()
     self.port = gpact_stdby.get_standby_port()
     self.standby_pid = gpact_stdby.get_standby_pid(self.host, self.port, self.mdd)
     PSQL.run_sql_file(local_path('create_tables.sql'), dbname = self.db_name)
     self.assertTrue(gpact_stdby.activate())
     self.assertTrue(gpact_stdby.verify_gpactivatestandby(self.standby_pid, self.host, self.port, self.mdd)) 
     gputil.failback_to_original_master(self.origin_mdd,self.host,self.mdd,self.port) 
Example #12
0
 def start_stdby(self):
     gpstdby = GpinitStandby()
     stdby_host = gpstdby.get_standbyhost()
     stdby_dbid = self.get_standby_dbid()
     activate_stdby = GpactivateStandby()
     stdby_mdd = activate_stdby.get_standby_dd()
     stdby_port = activate_stdby.get_standby_port()
     cmd = "pg_ctl -D %s -o '-p %s -b %s -z 2 --silent-mode=true -i -M master -C -1 -x 0 -E' start &" % (
         stdby_mdd,
         stdby_port,
         stdby_dbid,
     )
     self.run_remote(stdby_host, cmd, stdby_port, stdby_mdd)
Example #13
0
 def kill_walreceiver(self):
     gpstdby = GpinitStandby()
     stdby_host = gpstdby.get_standbyhost()
     activate_stdby = GpactivateStandby()
     stdby_port = activate_stdby.get_standby_port()
     pid_list = []
     walreceiver_pid = self.pgutil.get_pid_by_keyword(host=stdby_host, pgport=stdby_port, keyword="wal receiver process")
     if int(walreceiver_pid) == -1:
         tinctest.logger.error("error: wal receiver process does not exist!")
         return False
     else:  
         pid_list.append(walreceiver_pid)
         self.killProcess_byPid(pid_toKill=pid_list, host=stdby_host)
Example #14
0
 def kill_walreceiver(self):
     gpstdby = GpinitStandby()
     stdby_host = gpstdby.get_standbyhost()
     activate_stdby = GpactivateStandby()
     stdby_port = activate_stdby.get_standby_port()
     pid_list = []
     walreceiver_pid = self.pgutil.get_pid_by_keyword(host=stdby_host, pgport=stdby_port, keyword="wal receiver process")
     if int(walreceiver_pid) == -1:
         tinctest.logger.error("error: wal receiver process does not exist!")
         return False
     else:  
         pid_list.append(walreceiver_pid)
         self.killProcess_byPid(pid_toKill=pid_list, host=stdby_host)
 def test_gpactivatestandby_new_host_with_filespace(self):
     #from mpp.lib.gpfilespace import Gpfilespace
     #gpfile = Gpfilespace()
     #gpfile.create_filespace('fs_walrepl_a')
     #PSQL.run_sql_file(local_path('filespace.sql'), dbname= self.db_name)
     gputil.install_standby()
     initstdby = GpinitStandby()
     gpact_stdby = GpactivateStandby()
     self.mdd = gpact_stdby.get_standby_dd()
     self.host = initstdby.get_standbyhost()
     self.port = gpact_stdby.get_standby_port()
     self.standby_pid = gpact_stdby.get_standby_pid(self.host, self.port, self.mdd)
     PSQL.run_sql_file(local_path('create_tables.sql'), dbname = self.db_name)
     self.assertTrue(gpact_stdby.activate())
     self.assertTrue(gpact_stdby.verify_gpactivatestandby(self.standby_pid, self.host, self.port, self.mdd)) 
     gputil.failback_to_original_master(self.origin_mdd,self.host,self.mdd,self.port)
Example #16
0
 def test_promote_incomplete_stdby(self):
     ''' 
     remove the standby base dir, try promote and check if fail       
     '''
     gpactivate_stdby = GpactivateStandby()
     gpinit_stdby = GpinitStandby()
     stdby_mdd = gpactivate_stdby.get_standby_dd()
     stdby_host = gpinit_stdby.get_standbyhost()
     stdby_port = gpactivate_stdby.get_standby_port()
     destDir = os.path.join(stdby_mdd, 'base')
     self.pgutil.clean_dir(stdby_host,destDir)
     promote_cmd = "pg_ctl promote -D %s"%stdby_mdd       
     (rc, output) = gpactivate_stdby.run_remote(stdby_host,promote_cmd ,stdby_port,stdby_mdd)
     self.assertEqual(rc, 0)
     pid = self.pgutil.get_pid_by_keyword(host=stdby_host, pgport=stdby_port, keyword='master', option='bin')
     self.assertTrue(int(pid) == -1, 'incomplete standby data directory promote succeeds.')
Example #17
0
 def test_gpactivatestandby_new_host_with_filespace(self):
     from mpp.lib.gpfilespace import Gpfilespace
     gpfile = Gpfilespace()
     gpfile.create_filespace('fs_walrepl_a')
     PSQL.run_sql_file(local_path('filespace.sql'), dbname= self.db_name)
     gputil.install_standby()
     initstdby = GpinitStandby()
     gpact_stdby = GpactivateStandby()
     self.mdd = gpact_stdby.get_standby_dd()
     self.host = initstdby.get_standbyhost()
     self.port = gpact_stdby.get_standby_port()
     self.standby_pid = gpact_stdby.get_standby_pid(self.host, self.port, self.mdd)
     PSQL.run_sql_file(local_path('create_tables.sql'), dbname = self.db_name)
     self.assertTrue(gpact_stdby.activate())
     self.assertTrue(gpact_stdby.verify_gpactivatestandby(self.standby_pid, self.host, self.port, self.mdd)) 
     gputil.failback_to_original_master(self.origin_mdd,self.host,self.mdd,self.port)
 def test_promote_incomplete_stdby(self):
     ''' 
    remove the standby base dir, try promote and check if fail       
    '''
     gpactivate_stdby = GpactivateStandby()
     gpinit_stdby = GpinitStandby()
     stdby_mdd = gpactivate_stdby.get_standby_dd()
     stdby_host = gpinit_stdby.get_standbyhost()
     stdby_port = gpactivate_stdby.get_standby_port()
     destDir = os.path.join(stdby_mdd, 'base')
     self.pgutil.clean_dir(stdby_host, destDir)
     promote_cmd = "pg_ctl promote -D %s" % stdby_mdd
     (rc, output) = gpactivate_stdby.run_remote(stdby_host, promote_cmd,
                                                stdby_port, stdby_mdd)
     self.assertEqual(rc, 0)
     pid = self.pgutil.get_pid_by_keyword(host=stdby_host,
                                          pgport=stdby_port,
                                          keyword='master',
                                          option='bin')
     self.assertTrue(
         int(pid) == -1,
         'incomplete standby data directory promote succeeds.')
class gpactivatestandby(mpp.gpdb.tests.storage.walrepl.run.StandbyRunMixin, mpp.gpdb.tests.storage.walrepl.lib.PreprocessFileMixin,
                        SQLTestCase):
    """
    @gucs gp_create_table_random_default_distribution=off
    """

    sql_dir = 'sql'
    ans_dir = 'ans'
    out_dir = 'output'

    standby_dir = ''
    standby_host = ''
    standby_port = ''


    @unittest.skipIf(config.is_multinode(), "Test applies only to a singlenode cluster")
    def setUp(self):
        # For each test case we create a fresh standby and start it.
        self.db_name = self.__class__.db_name
        self.createdb(self.db_name)
        gputil.remove_standby()
        gputil.install_standby(new_stdby_host=socket.gethostname()) 
        self.gpinit_stdby = GpinitStandby()
        self.activatestdby = GpactivateStandby()

    def tearDown(self):
        # Clean up filespaces to be tidy.  Although we want to preserve
        # it for the investigation in case of test failure, without cleaning
        # it up it will prevent next tests from running correctly.
        gputil.failback_to_original_master(origin_mdd,self.standby_host,self.standby_dir,self.standby_port)
        # remove standby
        cmd = Command('gpinitstandby', 'gpinitstandby -ar')
        cmd.run()

    def get_gp_dbid(self,standby_dd=''):
        # We use gppylib from the installation
        from gppylib.gp_dbid import GpDbidFile
        return GpDbidFile(standby_dd, True).dbid

    def run_test(self):
        """
        Override of SQLTestCase.  Initialize standby, run some sql,
        then activate it, and check if the data is streamed correctly.
        """
        sql_file = self.sql_file
        ans_file = self.ans_file

        nsender = self.wait_for_walsender()
        self.assertEqual(nsender, 1, 'replication has not begun')

        # setup script is run on primary while standby is running.
        # .in file will be substitute with runtime information, if any.
        setup_file = sql_file.replace('.sql', '_setup.sql')
        if os.path.exists(setup_file + '.in'):
            self.preprocess_file(setup_file + '.in')
        self.assertTrue(PSQL.run_sql_file(setup_file, dbname=self.db_name))

        self.standby_dir = self.activatestdby.get_standby_dd()
        self.standby_port = self.activatestdby.get_standby_port()
        self.standby_host = self.gpinit_stdby.get_standbyhost()
        self.activatestdby.activate()

        datadir = os.path.abspath(self.standby_datadir)
        with walrepl.NewEnv(MASTER_DATA_DIRECTORY=self.standby_dir,
                             PGPORT=self.standby_port) as env:
            result = super(gpactivatestandby, self).run_test()
            sql = 'SHOW gp_dbid'
            result = PSQL.run_sql_command(sql, flags='-A -t')
            self.assertEqual(result.strip(), '1')
            self.assertEqual(self.get_gp_dbid(self.standby_dir), 1, 'gp_dbid should show 1')
            if 'cleanup_filespace' in self._metadata:
                mpp.gpdb.tests.storage.walrepl.lib.cleanupFilespaces(dbname=self.db_name)
        return result