|
| 1 | +import os |
| 2 | +import unittest |
| 3 | +from .helpers.ptrack_helpers import ProbackupTest |
| 4 | +import subprocess |
| 5 | +from time import sleep |
| 6 | + |
| 7 | +module_name = 'time_consuming' |
| 8 | + |
| 9 | +class TimeConsumingTests(ProbackupTest, unittest.TestCase): |
| 10 | + def test_pbckp150(self): |
| 11 | + """ |
| 12 | + https://jira.postgrespro.ru/browse/PBCKP-150 |
| 13 | + create a node filled with pgbench |
| 14 | + create FULL backup followed by PTRACK backup |
| 15 | + run pgbench, vacuum VERBOSE FULL and ptrack backups in parallel |
| 16 | + """ |
| 17 | + # init node |
| 18 | + fname = self.id().split('.')[3] |
| 19 | + node = self.make_simple_node( |
| 20 | + base_dir=os.path.join(module_name, fname, 'node'), |
| 21 | + set_replication=True, |
| 22 | + initdb_params=['--data-checksums']) |
| 23 | + node.append_conf('postgresql.conf', |
| 24 | + """ |
| 25 | + max_connections = 100 |
| 26 | + wal_keep_size = 16000 |
| 27 | + ptrack.map_size = 1 |
| 28 | + shared_preload_libraries='ptrack' |
| 29 | + log_statement = 'none' |
| 30 | + fsync = off |
| 31 | + log_checkpoints = on |
| 32 | + autovacuum = off |
| 33 | + """) |
| 34 | + |
| 35 | + # init probackup and add an instance |
| 36 | + backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup') |
| 37 | + self.init_pb(backup_dir) |
| 38 | + self.add_instance(backup_dir, 'node', node) |
| 39 | + |
| 40 | + # run the node and init ptrack |
| 41 | + node.slow_start() |
| 42 | + node.safe_psql("postgres", "CREATE EXTENSION ptrack") |
| 43 | + # populate it with pgbench |
| 44 | + node.pgbench_init(scale=5) |
| 45 | + |
| 46 | + # FULL backup followed by PTRACK backup |
| 47 | + self.backup_node(backup_dir, 'node', node, options=['--stream']) |
| 48 | + self.backup_node(backup_dir, 'node', node, backup_type='ptrack', options=['--stream']) |
| 49 | + |
| 50 | + # run ordinary pgbench scenario to imitate some activity and another pgbench for vacuuming in parallel |
| 51 | + nBenchDuration = 30 |
| 52 | + pgbench = node.pgbench(options=['-c', '20', '-j', '8', '-T', str(nBenchDuration)]) |
| 53 | + with open('/tmp/pbckp150vacuum.sql', 'w') as f: |
| 54 | + f.write('VACUUM (FULL) pgbench_accounts, pgbench_tellers, pgbench_history; SELECT pg_sleep(1);\n') |
| 55 | + pgbenchval = node.pgbench(options=['-c', '1', '-f', '/tmp/pbckp150vacuum.sql', '-T', str(nBenchDuration)]) |
| 56 | + |
| 57 | + # several PTRACK backups |
| 58 | + for i in range(nBenchDuration): |
| 59 | + print("[{}] backing up PTRACK diff...".format(i+1)) |
| 60 | + self.backup_node(backup_dir, 'node', node, backup_type='ptrack', options=['--stream', '--log-level-console', 'VERBOSE']) |
| 61 | + sleep(0.1) |
| 62 | + # if the activity pgbench has finished, stop backing up |
| 63 | + if pgbench.poll() is not None: |
| 64 | + break |
| 65 | + |
| 66 | + pgbench.kill() |
| 67 | + pgbenchval.kill() |
| 68 | + pgbench.wait() |
| 69 | + pgbenchval.wait() |
| 70 | + |
| 71 | + backups = self.show_pb(backup_dir, 'node') |
| 72 | + for b in backups: |
| 73 | + self.assertEqual("OK", b['status']) |
| 74 | + |
| 75 | + # Clean after yourself |
| 76 | + self.del_test_dir(module_name, fname) |
0 commit comments