1
0
mirror of https://github.com/postgrespro/pg_probackup.git synced 2025-02-12 14:56:08 +02:00

tests: minor fixes and comments for test_minrecpoint_on_replica()

This commit is contained in:
Grigory Smolkin 2019-02-12 20:03:44 +03:00
parent 841e608fa7
commit 8bbf1f44c6

View File

@ -16,9 +16,6 @@ class BugTest(ProbackupTest, unittest.TestCase):
def test_minrecpoint_on_replica(self): def test_minrecpoint_on_replica(self):
""" """
https://jira.postgrespro.ru/browse/PGPRO-2068 https://jira.postgrespro.ru/browse/PGPRO-2068
make node without archive support, make backup which should fail
check that backup status equal to ERROR
check that no files where copied to backup catalogue
""" """
fname = self.id().split('.')[3] fname = self.id().split('.')[3]
node = self.make_simple_node( node = self.make_simple_node(
@ -43,6 +40,7 @@ class BugTest(ProbackupTest, unittest.TestCase):
self.backup_node( self.backup_node(
backup_dir, 'node', node, options=['--stream']) backup_dir, 'node', node, options=['--stream'])
# start replica
replica = self.make_simple_node( replica = self.make_simple_node(
base_dir=os.path.join(module_name, fname, 'replica')) base_dir=os.path.join(module_name, fname, 'replica'))
replica.cleanup() replica.cleanup()
@ -57,6 +55,7 @@ class BugTest(ProbackupTest, unittest.TestCase):
replica.append_conf( replica.append_conf(
'postgresql.auto.conf', 'restart_after_crash = off') 'postgresql.auto.conf', 'restart_after_crash = off')
# we need those later
node.safe_psql( node.safe_psql(
"postgres", "postgres",
"CREATE EXTENSION plpythonu") "CREATE EXTENSION plpythonu")
@ -65,29 +64,25 @@ class BugTest(ProbackupTest, unittest.TestCase):
"postgres", "postgres",
"CREATE EXTENSION pageinspect") "CREATE EXTENSION pageinspect")
# pg_last_wal_replay_lsn
replica.slow_start(replica=True) replica.slow_start(replica=True)
# generate some data
node.pgbench_init(scale=10) node.pgbench_init(scale=10)
pgbench = node.pgbench( pgbench = node.pgbench(
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, stderr=subprocess.STDOUT,
options=["-c", "4", "-T", "20"] options=["-c", "4", "-T", "20"])
)
pgbench.wait() pgbench.wait()
pgbench.stdout.close() pgbench.stdout.close()
# generate some more data and leave it in background
pgbench = node.pgbench( pgbench = node.pgbench(
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, stderr=subprocess.STDOUT,
options=["-c", "4", "-T", "30"] options=["-c", "4", "-T", "30"])
)
# select pid from pg_stat_activity where backend_type in ('walreceiver', 'checkpointer', 'background writer', 'startup') ; # get pids of background workers
startup_pid = replica.safe_psql( startup_pid = replica.safe_psql(
'postgres', 'postgres',
"select pid from pg_stat_activity where backend_type = 'startup'").rstrip() "select pid from pg_stat_activity where backend_type = 'startup'").rstrip()
@ -100,34 +95,31 @@ class BugTest(ProbackupTest, unittest.TestCase):
'postgres', 'postgres',
"select pid from pg_stat_activity where backend_type = 'background writer'").rstrip() "select pid from pg_stat_activity where backend_type = 'background writer'").rstrip()
# wait for shared_buffer to be filled with dirty data
sleep(5) sleep(5)
# startup process # break checkpointer on UpdateLastRemovedPtr
# checkpointer
# writer process
# block checkpointer on UpdateLastRemovedPtr
gdb_checkpointer = self.gdb_attach(checkpointer_pid) gdb_checkpointer = self.gdb_attach(checkpointer_pid)
gdb_checkpointer.set_breakpoint('UpdateLastRemovedPtr') gdb_checkpointer.set_breakpoint('UpdateLastRemovedPtr')
gdb_checkpointer.continue_execution_until_break() gdb_checkpointer.continue_execution_until_break()
# block recovery in on UpdateMinRecoveryPoint # break recovery on UpdateControlFile
gdb_recovery = self.gdb_attach(startup_pid) gdb_recovery = self.gdb_attach(startup_pid)
gdb_recovery.set_breakpoint('UpdateMinRecoveryPoint') gdb_recovery.set_breakpoint('UpdateMinRecoveryPoint')
gdb_recovery.continue_execution_until_break() gdb_recovery.continue_execution_until_break()
gdb_recovery.set_breakpoint('UpdateControlFile') gdb_recovery.set_breakpoint('UpdateControlFile')
gdb_recovery.continue_execution_until_break() gdb_recovery.continue_execution_until_break()
# stop bgwriter # stop data generation
# gdb_bgwriter = self.gdb_attach(bgwriter_pid)
pgbench.wait() pgbench.wait()
pgbench.stdout.close() pgbench.stdout.close()
# kill someone, we need a crash
os.kill(int(bgwriter_pid), 9) os.kill(int(bgwriter_pid), 9)
gdb_recovery._execute('detach') gdb_recovery._execute('detach')
gdb_checkpointer._execute('detach') gdb_checkpointer._execute('detach')
# just to be sure
try: try:
replica.stop(['-m', 'immediate', '-D', replica.data_dir]) replica.stop(['-m', 'immediate', '-D', replica.data_dir])
except: except:
@ -136,13 +128,8 @@ class BugTest(ProbackupTest, unittest.TestCase):
# Promote replica with 'immediate' target action # Promote replica with 'immediate' target action
replica.append_conf( replica.append_conf(
'recovery.conf', "recovery_target = 'immediate'") 'recovery.conf', "recovery_target = 'immediate'")
replica.append_conf( replica.append_conf(
'recovery.conf', "recovery_target_action = 'promote'") 'recovery.conf', "recovery_target_action = 'promote'")
#os.remove(os.path.join(replica.data_dir, 'postmaster.pid'))
# sleep(5)
replica.slow_start() replica.slow_start()
script = ''' script = '''
@ -166,6 +153,7 @@ if found_corruption:
$$ LANGUAGE plpythonu; $$ LANGUAGE plpythonu;
''' '''
# Find blocks from future
replica.safe_psql( replica.safe_psql(
'postgres', 'postgres',
script) script)