2017-09-28 09:32:06 +02:00
|
|
|
import os
|
|
|
|
import unittest
|
|
|
|
from .helpers.ptrack_helpers import ProbackupTest, idx_ptrack
|
|
|
|
|
|
|
|
|
|
|
|
module_name = 'ptrack_truncate'
|
|
|
|
|
|
|
|
|
|
|
|
class SimpleTest(ProbackupTest, unittest.TestCase):
|
|
|
|
|
2018-10-17 16:04:23 +02:00
|
|
|
@unittest.skip("skip")
|
2017-09-28 09:32:06 +02:00
|
|
|
# @unittest.expectedFailure
|
|
|
|
def test_ptrack_truncate(self):
|
|
|
|
fname = self.id().split('.')[3]
|
2018-10-16 21:53:59 +02:00
|
|
|
node = self.make_simple_node(
|
2018-12-26 21:59:13 +02:00
|
|
|
base_dir=os.path.join(module_name, fname, 'node'),
|
2017-09-28 09:32:06 +02:00
|
|
|
set_replication=True,
|
|
|
|
initdb_params=['--data-checksums'],
|
2018-10-16 21:53:59 +02:00
|
|
|
pg_options={
|
|
|
|
'ptrack_enable': 'on',
|
|
|
|
'wal_level': 'replica',
|
|
|
|
'max_wal_senders': '2'})
|
|
|
|
|
2017-09-28 09:32:06 +02:00
|
|
|
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
|
|
|
|
self.init_pb(backup_dir)
|
|
|
|
self.add_instance(backup_dir, 'node', node)
|
2018-10-18 08:46:02 +02:00
|
|
|
node.slow_start()
|
2017-09-28 09:32:06 +02:00
|
|
|
|
|
|
|
self.create_tblspace_in_node(node, 'somedata')
|
|
|
|
|
|
|
|
# Create table and indexes
|
|
|
|
node.safe_psql(
|
|
|
|
"postgres",
|
2018-10-19 13:54:17 +02:00
|
|
|
"create extension bloom; create sequence t_seq; "
|
|
|
|
"create table t_heap tablespace somedata "
|
2018-10-16 21:53:59 +02:00
|
|
|
"as select i as id, md5(i::text) as text, "
|
|
|
|
"md5(repeat(i::text,10))::tsvector as tsvector "
|
|
|
|
"from generate_series(0,2560) i")
|
|
|
|
|
2017-09-28 09:32:06 +02:00
|
|
|
for i in idx_ptrack:
|
|
|
|
if idx_ptrack[i]['type'] != 'heap' and idx_ptrack[i]['type'] != 'seq':
|
2018-10-16 21:53:59 +02:00
|
|
|
node.safe_psql(
|
|
|
|
"postgres",
|
|
|
|
"create index {0} on {1} using {2}({3}) "
|
|
|
|
"tablespace somedata".format(
|
|
|
|
i, idx_ptrack[i]['relation'],
|
|
|
|
idx_ptrack[i]['type'], idx_ptrack[i]['column']))
|
2017-09-28 09:32:06 +02:00
|
|
|
|
|
|
|
node.safe_psql('postgres', 'truncate t_heap')
|
|
|
|
node.safe_psql('postgres', 'checkpoint')
|
|
|
|
|
|
|
|
for i in idx_ptrack:
|
|
|
|
# get fork size and calculate it in pages
|
|
|
|
idx_ptrack[i]['old_size'] = self.get_fork_size(node, i)
|
|
|
|
# get path to heap and index files
|
|
|
|
idx_ptrack[i]['path'] = self.get_fork_path(node, i)
|
|
|
|
# calculate md5sums for every page of this fork
|
|
|
|
idx_ptrack[i]['old_pages'] = self.get_md5_per_page_for_fork(
|
|
|
|
idx_ptrack[i]['path'], idx_ptrack[i]['old_size'])
|
|
|
|
|
|
|
|
# Make full backup to clean every ptrack
|
2018-10-16 21:53:59 +02:00
|
|
|
self.backup_node(
|
|
|
|
backup_dir, 'node', node, options=['-j10', '--stream'])
|
2018-10-17 11:56:03 +02:00
|
|
|
|
2017-09-28 09:32:06 +02:00
|
|
|
for i in idx_ptrack:
|
|
|
|
idx_ptrack[i]['ptrack'] = self.get_ptrack_bits_per_page_for_fork(
|
|
|
|
node, idx_ptrack[i]['path'], [idx_ptrack[i]['old_size']])
|
|
|
|
self.check_ptrack_clean(idx_ptrack[i], idx_ptrack[i]['old_size'])
|
|
|
|
|
|
|
|
# Clean after yourself
|
|
|
|
self.del_test_dir(module_name, fname)
|
|
|
|
|
2018-10-17 16:04:23 +02:00
|
|
|
@unittest.skip("skip")
|
2017-09-28 09:32:06 +02:00
|
|
|
def test_ptrack_truncate_replica(self):
|
|
|
|
fname = self.id().split('.')[3]
|
2018-10-16 21:53:59 +02:00
|
|
|
master = self.make_simple_node(
|
2018-12-26 21:59:13 +02:00
|
|
|
base_dir=os.path.join(module_name, fname, 'master'),
|
2017-09-28 09:32:06 +02:00
|
|
|
set_replication=True,
|
|
|
|
initdb_params=['--data-checksums'],
|
2018-10-16 21:53:59 +02:00
|
|
|
pg_options={
|
|
|
|
'ptrack_enable': 'on',
|
|
|
|
'wal_level': 'replica',
|
|
|
|
'max_wal_senders': '2',
|
|
|
|
'checkpoint_timeout': '30'})
|
|
|
|
|
2017-09-28 09:32:06 +02:00
|
|
|
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
|
|
|
|
self.init_pb(backup_dir)
|
|
|
|
self.add_instance(backup_dir, 'master', master)
|
2018-10-18 08:46:02 +02:00
|
|
|
master.slow_start()
|
2017-09-28 09:32:06 +02:00
|
|
|
|
|
|
|
self.backup_node(backup_dir, 'master', master, options=['--stream'])
|
|
|
|
|
2018-10-16 21:53:59 +02:00
|
|
|
replica = self.make_simple_node(
|
2018-12-26 21:59:13 +02:00
|
|
|
base_dir=os.path.join(module_name, fname, 'replica'))
|
2017-09-28 09:32:06 +02:00
|
|
|
replica.cleanup()
|
|
|
|
|
|
|
|
self.restore_node(backup_dir, 'master', replica)
|
|
|
|
|
|
|
|
self.add_instance(backup_dir, 'replica', replica)
|
|
|
|
self.set_replica(master, replica, 'replica', synchronous=True)
|
|
|
|
self.set_archiving(backup_dir, 'replica', replica, replica=True)
|
2018-10-18 08:46:02 +02:00
|
|
|
replica.slow_start(replica=True)
|
2017-09-28 09:32:06 +02:00
|
|
|
|
|
|
|
# Create table and indexes
|
2018-10-17 11:56:03 +02:00
|
|
|
self.create_tblspace_in_node(master, 'somedata')
|
2017-09-28 09:32:06 +02:00
|
|
|
master.safe_psql(
|
|
|
|
"postgres",
|
2018-10-19 13:54:17 +02:00
|
|
|
"create extension bloom; create sequence t_seq; "
|
|
|
|
"create table t_heap tablespace somedata "
|
2018-10-16 21:53:59 +02:00
|
|
|
"as select i as id, md5(i::text) as text, "
|
|
|
|
"md5(repeat(i::text,10))::tsvector as tsvector "
|
|
|
|
"from generate_series(0,2560) i")
|
2017-09-28 09:32:06 +02:00
|
|
|
for i in idx_ptrack:
|
|
|
|
if idx_ptrack[i]['type'] != 'heap' and idx_ptrack[i]['type'] != 'seq':
|
2018-10-16 21:53:59 +02:00
|
|
|
master.safe_psql(
|
|
|
|
"postgres", "create index {0} on {1} using {2}({3}) "
|
|
|
|
"tablespace somedata".format(
|
|
|
|
i, idx_ptrack[i]['relation'],
|
|
|
|
idx_ptrack[i]['type'], idx_ptrack[i]['column']))
|
2017-09-28 09:32:06 +02:00
|
|
|
|
2018-10-16 21:53:59 +02:00
|
|
|
# Sync master and replica
|
2018-10-18 08:46:02 +02:00
|
|
|
self.wait_until_replica_catch_with_master(master, replica)
|
2018-10-16 21:53:59 +02:00
|
|
|
replica.safe_psql('postgres', 'checkpoint')
|
|
|
|
|
2017-09-28 09:32:06 +02:00
|
|
|
for i in idx_ptrack:
|
|
|
|
# get fork size and calculate it in pages
|
|
|
|
idx_ptrack[i]['old_size'] = self.get_fork_size(replica, i)
|
|
|
|
# get path to heap and index files
|
|
|
|
idx_ptrack[i]['path'] = self.get_fork_path(replica, i)
|
|
|
|
# calculate md5sums for every page of this fork
|
|
|
|
idx_ptrack[i]['old_pages'] = self.get_md5_per_page_for_fork(
|
|
|
|
idx_ptrack[i]['path'], idx_ptrack[i]['old_size'])
|
|
|
|
|
|
|
|
# Make full backup to clean every ptrack
|
2018-10-16 21:53:59 +02:00
|
|
|
self.backup_node(
|
2018-10-17 16:04:23 +02:00
|
|
|
backup_dir, 'replica', replica,
|
|
|
|
options=[
|
|
|
|
'-j10',
|
|
|
|
'--master-host=localhost',
|
|
|
|
'--master-db=postgres',
|
|
|
|
'--master-port={0}'.format(master.port)])
|
|
|
|
|
2017-09-28 09:32:06 +02:00
|
|
|
for i in idx_ptrack:
|
|
|
|
idx_ptrack[i]['ptrack'] = self.get_ptrack_bits_per_page_for_fork(
|
|
|
|
replica, idx_ptrack[i]['path'], [idx_ptrack[i]['old_size']])
|
|
|
|
self.check_ptrack_clean(idx_ptrack[i], idx_ptrack[i]['old_size'])
|
|
|
|
|
2018-10-17 11:56:03 +02:00
|
|
|
master.safe_psql('postgres', 'truncate t_heap')
|
2017-09-28 09:32:06 +02:00
|
|
|
master.safe_psql('postgres', 'checkpoint')
|
|
|
|
|
2018-10-16 21:53:59 +02:00
|
|
|
# Sync master and replica
|
2018-10-18 08:46:02 +02:00
|
|
|
self.wait_until_replica_catch_with_master(master, replica)
|
2018-10-16 21:53:59 +02:00
|
|
|
replica.safe_psql('postgres', 'checkpoint')
|
|
|
|
|
|
|
|
# CHECK PTRACK SANITY
|
|
|
|
success = True
|
2017-09-28 09:32:06 +02:00
|
|
|
for i in idx_ptrack:
|
|
|
|
# get new size of heap and indexes and calculate it in pages
|
|
|
|
idx_ptrack[i]['new_size'] = self.get_fork_size(replica, i)
|
|
|
|
# update path to heap and index files in case they`ve changed
|
|
|
|
idx_ptrack[i]['path'] = self.get_fork_path(replica, i)
|
|
|
|
# calculate new md5sums for pages
|
|
|
|
idx_ptrack[i]['new_pages'] = self.get_md5_per_page_for_fork(
|
|
|
|
idx_ptrack[i]['path'], idx_ptrack[i]['new_size'])
|
|
|
|
# get ptrack for every idx
|
|
|
|
idx_ptrack[i]['ptrack'] = self.get_ptrack_bits_per_page_for_fork(
|
2018-10-16 21:53:59 +02:00
|
|
|
replica, idx_ptrack[i]['path'],
|
|
|
|
[idx_ptrack[i]['old_size'], idx_ptrack[i]['new_size']])
|
2017-09-28 09:32:06 +02:00
|
|
|
|
|
|
|
# compare pages and check ptrack sanity
|
2018-10-16 21:53:59 +02:00
|
|
|
if not self.check_ptrack_sanity(idx_ptrack[i]):
|
|
|
|
success = False
|
|
|
|
|
|
|
|
self.assertTrue(
|
|
|
|
success, 'Ptrack has failed to register changes in data files'
|
|
|
|
)
|
2017-09-28 09:32:06 +02:00
|
|
|
|
|
|
|
# Clean after yourself
|
|
|
|
self.del_test_dir(module_name, fname)
|