Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit d1e4d2b

Browse files
committed
tests: add ptrack test for unlogged tables
1 parent 37ced69 commit d1e4d2b

File tree

1 file changed

+35
-62
lines changed

1 file changed

+35
-62
lines changed

tests/exclude.py

Lines changed: 35 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,24 @@ def test_exclude_temp_tables(self):
7777
self.del_test_dir(module_name, fname)
7878

7979
# @unittest.skip("skip")
80-
def test_exclude_unlogged_tables(self):
81-
"""make node without archiving, create temp table, take full backup, check that temp table not present in backup catalogue"""
80+
def test_exclude_unlogged_tables_1(self):
81+
"""
82+
make node without archiving, create unlogged table, take full backup,
83+
alter table to unlogged, take ptrack backup, restore ptrack backup,
84+
check that PGDATA`s are physically the same
85+
"""
8286
fname = self.id().split('.')[3]
8387
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
84-
node = self.make_simple_node(base_dir="{0}/{1}/node".format(module_name, fname),
88+
node = self.make_simple_node(
89+
base_dir="{0}/{1}/node".format(module_name, fname),
8590
set_replication=True,
8691
initdb_params=['--data-checksums'],
87-
pg_options={'wal_level': 'replica', 'max_wal_senders': '2', "shared_buffers": "1GB", "fsync": "off", 'ptrack_enable': 'on'}
92+
pg_options={
93+
'wal_level': 'replica',
94+
'max_wal_senders': '2',
95+
"shared_buffers": "1GB",
96+
"fsync": "off",
97+
'ptrack_enable': 'on'}
8898
)
8999

90100
self.init_pb(backup_dir)
@@ -94,75 +104,38 @@ def test_exclude_unlogged_tables(self):
94104
conn = node.connect()
95105
with node.connect("postgres") as conn:
96106

97-
conn.execute("create unlogged table test as select generate_series(0,5005000)::text")
107+
conn.execute(
108+
"create unlogged table test as "
109+
"select generate_series(0,5005000)::text")
98110
conn.commit()
99111

100112
conn.execute("create index test_idx on test (generate_series)")
101113
conn.commit()
102114

103-
heap_path = conn.execute("select pg_relation_filepath('test')")[0][0]
104-
conn.commit()
115+
self.backup_node(
116+
backup_dir, 'node', node,
117+
backup_type='full', options=['--stream'])
105118

106-
index_path = conn.execute("select pg_relation_filepath('test_idx')")[0][0]
107-
conn.commit()
108-
index_init_path = index_path + "_init"
119+
node.safe_psql('postgres', "alter table test set logged")
109120

110-
heap_oid = conn.execute("select 'test'::regclass::oid")[0][0]
111-
conn.commit()
121+
self.backup_node(
122+
backup_dir, 'node', node, backup_type='ptrack',
123+
options=['--stream', '--log-level-file=verbose']
124+
)
112125

113-
toast_path = conn.execute("select pg_relation_filepath('{0}.{1}')".format("pg_toast", "pg_toast_" + str(heap_oid)))[0][0]
114-
conn.commit()
115-
toast_init_path = toast_path + "_init"
126+
pgdata = self.pgdata_content(node.data_dir)
116127

117-
toast_idx_path = conn.execute("select pg_relation_filepath('{0}.{1}')".format("pg_toast", "pg_toast_" + str(heap_oid) + "_index"))[0][0]
118-
conn.commit()
119-
toast_index_idx_path = toast_idx_path + "_init"
120-
121-
unlogged_heap_filename = os.path.basename(heap_path)
122-
unlogged_heap_init_filename = unlogged_heap_filename + "_init"
123-
124-
unlogged_idx_filename = os.path.basename(index_path)
125-
unlogged_idx_init_filename = unlogged_idx_filename + "_init"
126-
127-
unlogged_toast_filename = os.path.basename(toast_path)
128-
unlogged_toast_init_filename = unlogged_toast_filename + "_init"
128+
node_restored = self.make_simple_node(
129+
base_dir="{0}/{1}/node_restored".format(module_name, fname),
130+
)
131+
node_restored.cleanup()
129132

130-
unlogged_idx_toast_filename = os.path.basename(toast_idx_path)
131-
unlogged_idx_toast_init_filename = unlogged_idx_toast_filename + "_init"
133+
self.restore_node(
134+
backup_dir, 'node', node_restored, options=["-j", "4"])
132135

133-
self.backup_node(backup_dir, 'node', node, backup_type='full', options=['--stream'])
134-
135-
found_unlogged_heap_init = False
136-
found_unlogged_idx_init = False
137-
found_unlogged_toast = False
138-
found_unlogged_idx_toast_init = False
139-
for root, dirs, files in os.walk(backup_dir):
140-
for file in files:
141-
if file in [unlogged_heap_filename, unlogged_heap_filename + ".1",
142-
unlogged_idx_filename,
143-
unlogged_idx_filename + ".1",
144-
unlogged_toast_filename,
145-
unlogged_toast_filename + ".1",
146-
unlogged_idx_toast_filename,
147-
unlogged_idx_toast_filename + ".1"]:
148-
self.assertTrue(False, "Found unlogged table file in backup catalogue.\n Filepath: {0}".format(file))
149-
150-
if file == unlogged_heap_init_filename:
151-
found_unlogged_heap_init = True
152-
153-
if file == unlogged_idx_init_filename:
154-
found_unlogged_idx_init = True
155-
156-
if file == unlogged_toast_init_filename:
157-
found_unlogged_toast = True
158-
159-
if file == unlogged_idx_toast_init_filename:
160-
found_unlogged_idx_toast_init = True
161-
162-
self.assertTrue(found_unlogged_heap_init, "{0} is not found in backup catalogue".format(unlogged_heap_init_filename));
163-
self.assertTrue(found_unlogged_idx_init, "{0} is not found in backup catalogue".format(unlogged_idx_init_filename));
164-
self.assertTrue(found_unlogged_toast, "{0} is not found in backup catalogue".format(unlogged_toast_filename));
165-
self.assertTrue(found_unlogged_idx_toast_init, "{0} is not found in backup catalogue".format(unlogged_idx_toast_init_filename));
136+
# Physical comparison
137+
pgdata_restored = self.pgdata_content(node_restored.data_dir)
138+
self.compare_pgdata(pgdata, pgdata_restored)
166139

167140
# Clean after yourself
168141
self.del_test_dir(module_name, fname)

0 commit comments

Comments
 (0)