import sys from mpp.gpdb.tests.storage.walrepl.lib.standby import Standby def pline(msg, cmd=None): sys.stdout.write('----' + msg + '\n') if cmd: sys.stdout.write(cmd + '\n') sys.stdin.readline() if __name__ == '__main__': mpp.gpdb.tests.storage.walrepl.lib.cleanupFilespaces(dbname='haradh1') standby = Standby('standby', '5433') standby.stop() standby.stop() shutil.rmtree('standby', True) sys.stdout.write(''' *********************************************************** *** Demo for Filespace support *********************************************************** ''') pline('Initialize standby info in catalog and take online backup') standby.create() subprocess.call(['ls', 'standby']) subprocess.call(['psql', '-c', 'select * from gp_segment_configuration'])
def test_icg(self): # 1. Verify if the system is UP and there is no WAL Receiver running # 2. Perform basebackup and deploy it into some dest. directory # 3. Copy recover.conf into the dest. directory to be used by Standby # 4. Initiate the Standby using the Master (primary) postmaster # paramerters # 5. Once the WAL receiver waits for the next record to arrive, perform # installCheck-good # 0. Stop standby if it's running standby = Standby('base', 5433) standby.stop() # 1. Verify if the system is UP and there is no WAL sender running self.assertEqual(self.count_wal_sender(), 0) logger.info('No active WAL Receiver found') # Set environmental variable GPSRC for now for make installcheck purpose source_file = sys.modules[self.__class__.__module__].__file__ source_dir = os.path.dirname(source_file) os.environ['GPSRC'] = os.path.join(source_dir, '../../../../') # 2. Perform basebackup and deploy it into some dest. # (currenttly hardcoded 'base') directory shutil.rmtree('base', True) logger.info('Performing and deploying base backup ...') standby.create() # 3.Copy recover.conf into the dest. directory to be used by StandBy logger.info('Deploying recovery.conf...') # 4. Initiate the StandBy using the Master (primary) postmaster # paramerters logger.info('Initiating Standby...') res = standby.start() self.assertTrue(res.wasSuccessful()) num_walsender = 0 for i in polling(10, 0.5): num_walsender = self.count_wal_sender() if num_walsender > 0: break self.assertEqual(num_walsender, 1) logger.info('Activated WAL Receiver...') # 6. Run installcheck-good self.assertTrue(os.environ["GPSRC"]) installCheckGoodPath = os.path.join(os.environ.get('GPSRC'), 'test', 'regress') self.assertTrue(os.path.exists(installCheckGoodPath)) os.chdir(installCheckGoodPath) regression_diffs = os.path.join(installCheckGoodPath, 'regression.diffs') if os.path.exists(regression_diffs): os.remove(regression_diffs) logger.info('Perform InstallCheck-Good...') subprocess.check_call('make installcheck-good', shell=True) # Verify installcheck result by checking if regression.diff is present. self.assertTrue(not os.path.exists(regression_diffs))
import shutil import subprocess import sys from mpp.gpdb.tests.storage.walrepl.lib.standby import Standby def pline(msg, cmd=None): sys.stdout.write('----' + msg + '\n') if cmd: sys.stdout.write(cmd + '\n') sys.stdin.readline() if __name__ == '__main__': mpp.gpdb.tests.storage.walrepl.lib.cleanupFilespaces(dbname='haradh1') standby = Standby('standby', '5433') standby.stop() standby.stop() shutil.rmtree('standby', True) sys.stdout.write(''' *********************************************************** *** Demo for Filespace support *********************************************************** ''') pline('Initialize standby info in catalog and take online backup') standby.create() subprocess.call(['ls', 'standby']) subprocess.call(['psql', '-c', 'select * from gp_segment_configuration'])
def test_smart_shutdown(self): # 1. Verify if the system is UP and there is no WAL Receiver running # 2. Perform basebackup and deploy it into some dest. directory # 3. Copy recover.conf into the dest. directory to be used by Standby # 4. Initiate the Standby using the Master (primary) postmaster # paramerters # 5. Perform some transaction to generate xlog. Then do a smart shutdown # 6. Once the primary DB is down, find the last checkpoint from pg_control # on primary. Check the last modified xlog seg from the standby and find # if the last checkpoint from primary exists # 7. It should be present there! # 0. Stop standby if it's running PSQL.run_sql_command('DROP table if exists foo') standby = Standby('base', 5433) standby.stop() # 1. Verify if the system is UP and there is no WAL sender running self.assertEqual(self.count_walsender(), 0) logger.info('No active WAL Receiver found') # 2. Perform basebackup and deploy it into some dest. # (currenttly hardcoded 'base') directory shutil.rmtree('base', True) logger.info('Performing and deploying base backup ...') standby.create() # 3.Copy recover.conf into the dest. directory to be used by StandBy logger.info('Deploying recovery.conf...') # 4. Initiate the StandBy using the Master (primary) postmaster # paramerters logger.info('Initiating Standby...') res = standby.start() self.assertTrue(res.wasSuccessful()) num_walsender = 0 for i in polling(10, 0.5): num_walsender = self.count_walsender() if num_walsender > 0: break self.assertEqual(num_walsender, 1) logger.info('Activated WAL Receiver...') # 5. Perform some transaction to generate xlog. Then do a smart shutdown logger.info('Perform some transaction to generate some XLOG') PSQL.run_sql_command('Create table foo (a int)') logger.info('Now perform smart shutdown (gpstop -a)') cmd = Command(name="gpstop smart", cmdStr="source %s/greenplum_path.sh;\ gpstop -a" % os.environ["GPHOME"]) cmd.run(validateAfter=True) # 6. Once the primary DB is down, find the last checkpoint from pg_control # on primary. Check the last modified xlog seg from the standby and find # if the last checkpoint from primary exists logger.info( 'Read the pg_control from primary, find the last checkpoint & see if it made to standby' ) standby_xlog_path = os.path.join('base', 'pg_xlog') cmd = Command( name='pg_controldata ' + os.environ.get('MASTER_DATA_DIRECTORY'), cmdStr='pg_controldata ' + os.environ.get('MASTER_DATA_DIRECTORY')) cmd.run(validateAfter=True) primary_last_ckpt_lsn = self.last_ckpt_lsn((cmd.get_results()).stdout) logger.info("Primary last checkpoint LSN = " + primary_last_ckpt_lsn) standby_last_mod_xlog = self.last_mod_file(standby_xlog_path) logger.info("Last mod standby XLOG = " + standby_last_mod_xlog) cmd = Command(name='xlogdump standby last modifiled xlog', cmdStr="xlogdump " + standby_last_mod_xlog) cmd.run(validateAfter=True) logger.info('See if we find the shutdown LSN in the XLOG seg file') lines = (cmd.get_results()).stdout.splitlines() flag = False for line in range(0, len(lines) - 1): if ((lines[line]).find(primary_last_ckpt_lsn) > -1): self.assertTrue((lines[line]).find("checkpoint") > -1) self.assertTrue((lines[line]).find("shutdown") > -1) flag = True break self.assertTrue(flag) logger.info('PASS') # Re-start the database logger.info('Now restart the DB (gpstart -a)') cmd = Command(name="gpstop smart", cmdStr="source %s/greenplum_path.sh;\ gpstart -a" % os.environ["GPHOME"]) cmd.run(validateAfter=True) # Cleanup. Currently we dont have a clean way of WAL rcv dying logger.info( 'Kill the standby processes as clean standby killing is not supported' ) cmd = Command( name="kill standby", cmdStr= "kill -9 `ps -ef | grep 5433 | grep -v grep | awk '{print $2}'`") cmd.run(validateAfter=True)
def test_smart_shutdown(self): # 1. Verify if the system is UP and there is no WAL Receiver running # 2. Perform basebackup and deploy it into some dest. directory # 3. Copy recover.conf into the dest. directory to be used by Standby # 4. Initiate the Standby using the Master (primary) postmaster # paramerters # 5. Perform some transaction to generate xlog. Then do a smart shutdown # 6. Once the primary DB is down, find the last checkpoint from pg_control # on primary. Check the last modified xlog seg from the standby and find # if the last checkpoint from primary exists # 7. It should be present there! # 0. Stop standby if it's running PSQL.run_sql_command('DROP table if exists foo') standby = Standby('base', 5433) standby.stop() # 1. Verify if the system is UP and there is no WAL sender running self.assertEqual(self.count_walsender(), 0) logger.info('No active WAL Receiver found') # 2. Perform basebackup and deploy it into some dest. # (currenttly hardcoded 'base') directory shutil.rmtree('base', True) logger.info('Performing and deploying base backup ...') standby.create() # 3.Copy recover.conf into the dest. directory to be used by StandBy logger.info('Deploying recovery.conf...') # 4. Initiate the StandBy using the Master (primary) postmaster # paramerters logger.info('Initiating Standby...') res = standby.start() self.assertTrue(res.wasSuccessful()) num_walsender = 0 for i in polling(10, 0.5): num_walsender = self.count_walsender() if num_walsender > 0: break self.assertEqual(num_walsender, 1) logger.info('Activated WAL Receiver...') # 5. Perform some transaction to generate xlog. Then do a smart shutdown logger.info('Perform some transaction to generate some XLOG') PSQL.run_sql_command('Create table foo (a int)') logger.info('Now perform smart shutdown (gpstop -a)') cmd = Command(name="gpstop smart", cmdStr="source %s/greenplum_path.sh;\ gpstop -a" % os.environ["GPHOME"]) cmd.run(validateAfter=True) # 6. Once the primary DB is down, find the last checkpoint from pg_control # on primary. Check the last modified xlog seg from the standby and find # if the last checkpoint from primary exists logger.info('Read the pg_control from primary, find the last checkpoint & see if it made to standby') standby_xlog_path = os.path.join('base','pg_xlog') cmd= Command(name = 'pg_controldata ' + os.environ.get('MASTER_DATA_DIRECTORY'), cmdStr = 'pg_controldata ' + os.environ.get('MASTER_DATA_DIRECTORY')) cmd.run(validateAfter=True); primary_last_ckpt_lsn = self.last_ckpt_lsn((cmd.get_results()).stdout) logger.info ("Primary last checkpoint LSN = " + primary_last_ckpt_lsn) standby_last_mod_xlog = self.last_mod_file(standby_xlog_path) logger.info ("Last mod standby XLOG = " + standby_last_mod_xlog ) cmd= Command(name = 'xlogdump standby last modifiled xlog', cmdStr="xlogdump " + standby_last_mod_xlog) cmd.run(validateAfter=True); logger.info('See if we find the shutdown LSN in the XLOG seg file') lines = (cmd.get_results()).stdout.splitlines() flag = False for line in range(0, len(lines) - 1): if ((lines[line]).find(primary_last_ckpt_lsn) > -1): self.assertTrue((lines[line]).find("checkpoint") > -1) self.assertTrue((lines[line]).find("shutdown") > -1) flag = True break self.assertTrue(flag) logger.info('PASS') # Re-start the database logger.info('Now restart the DB (gpstart -a)') cmd = Command(name="gpstop smart", cmdStr="source %s/greenplum_path.sh;\ gpstart -a" % os.environ["GPHOME"]) cmd.run(validateAfter=True) # Cleanup. Currently we dont have a clean way of WAL rcv dying logger.info('Kill the standby processes as clean standby killing is not supported') cmd = Command(name="kill standby", cmdStr="kill -9 `ps -ef | grep 5433 | grep -v grep | awk '{print $2}'`") cmd.run(validateAfter=True)