Skip to content

Commit 98f77d2

Browse files
authored
[PGPRO-5691] ptrack-2.3: move mmapped ptrack map into shared postgres… (#471)
* [PGPRO-5691] ptrack-2.3: move mmapped ptrack map into shared postgres memory In ptrack-2.3 ptrack.map.mmap will be removed and 'incorrect checksum' error will not be fatal (postgrespro/ptrack#19) * added test_corrupt_ptrack_map test compatibility with both version 2.2 and version 2.3 of ptrack
1 parent 1790a99 commit 98f77d2

File tree

1 file changed

+36
-27
lines changed

1 file changed

+36
-27
lines changed

Diff for: tests/ptrack.py

+36-27
Original file line numberDiff line numberDiff line change
@@ -4314,6 +4314,8 @@ def test_corrupt_ptrack_map(self):
43144314
"postgres",
43154315
"CREATE EXTENSION ptrack")
43164316

4317+
ptrack_version = self.get_ptrack_version(node)
4318+
43174319
# Create table
43184320
node.safe_psql(
43194321
"postgres",
@@ -4338,48 +4340,55 @@ def test_corrupt_ptrack_map(self):
43384340
node.stop(['-m', 'immediate', '-D', node.data_dir])
43394341

43404342
ptrack_map = os.path.join(node.data_dir, 'global', 'ptrack.map')
4341-
ptrack_map_mmap = os.path.join(node.data_dir, 'global', 'ptrack.map.mmap')
43424343

4343-
# Let`s do index corruption. ptrack.map, ptrack.map.mmap
4344+
# Let`s do index corruption. ptrack.map
43444345
with open(ptrack_map, "rb+", 0) as f:
43454346
f.seek(42)
43464347
f.write(b"blablahblahs")
43474348
f.flush()
43484349
f.close
43494350

4350-
with open(ptrack_map_mmap, "rb+", 0) as f:
4351-
f.seek(42)
4352-
f.write(b"blablahblahs")
4353-
f.flush()
4354-
f.close
4355-
43564351
# os.remove(os.path.join(node.logs_dir, node.pg_log_name))
43574352

4358-
try:
4353+
if self.verbose:
4354+
print('Ptrack version:', ptrack_version)
4355+
if ptrack_version >= self.version_to_num("2.3"):
43594356
node.slow_start()
4360-
# we should die here because exception is what we expect to happen
4361-
self.assertEqual(
4362-
1, 0,
4363-
"Expecting Error because ptrack.map is corrupted"
4364-
"\n Output: {0} \n CMD: {1}".format(
4365-
repr(self.output), self.cmd))
4366-
except StartNodeException as e:
4357+
4358+
log_file = os.path.join(node.logs_dir, 'postgresql.log')
4359+
with open(log_file, 'r') as f:
4360+
log_content = f.read()
4361+
43674362
self.assertIn(
4368-
'Cannot start node',
4369-
e.message,
4370-
'\n Unexpected Error Message: {0}\n'
4371-
' CMD: {1}'.format(repr(e.message), self.cmd))
4363+
'WARNING: ptrack read map: incorrect checksum of file "{0}"'.format(ptrack_map),
4364+
log_content)
43724365

4373-
log_file = os.path.join(node.logs_dir, 'postgresql.log')
4374-
with open(log_file, 'r') as f:
4375-
log_content = f.read()
4366+
node.stop(['-D', node.data_dir])
4367+
else:
4368+
try:
4369+
node.slow_start()
4370+
# we should die here because exception is what we expect to happen
4371+
self.assertEqual(
4372+
1, 0,
4373+
"Expecting Error because ptrack.map is corrupted"
4374+
"\n Output: {0} \n CMD: {1}".format(
4375+
repr(self.output), self.cmd))
4376+
except StartNodeException as e:
4377+
self.assertIn(
4378+
'Cannot start node',
4379+
e.message,
4380+
'\n Unexpected Error Message: {0}\n'
4381+
' CMD: {1}'.format(repr(e.message), self.cmd))
4382+
4383+
log_file = os.path.join(node.logs_dir, 'postgresql.log')
4384+
with open(log_file, 'r') as f:
4385+
log_content = f.read()
43764386

4377-
self.assertIn(
4378-
'FATAL: ptrack init: incorrect checksum of file "{0}"'.format(ptrack_map),
4379-
log_content)
4387+
self.assertIn(
4388+
'FATAL: ptrack init: incorrect checksum of file "{0}"'.format(ptrack_map),
4389+
log_content)
43804390

43814391
self.set_auto_conf(node, {'ptrack.map_size': '0'})
4382-
43834392
node.slow_start()
43844393

43854394
try:

0 commit comments

Comments
 (0)