Skip to content

Commit 2cb4326

Browse files
committed
[Issue #66] tests for hint bits
1 parent 7506825 commit 2cb4326

File tree

1 file changed

+242
-0
lines changed

1 file changed

+242
-0
lines changed

tests/incr_restore.py

Lines changed: 242 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,5 +1252,247 @@ def test_make_replica_via_incr_lsn_restore(self):
12521252
# Clean after yourself
12531253
self.del_test_dir(module_name, fname)
12541254

1255+
# @unittest.skip("skip")
1256+
# @unittest.expectedFailure
1257+
def test_incr_checksum_long_xact(self):
1258+
"""
1259+
"""
1260+
fname = self.id().split('.')[3]
1261+
node = self.make_simple_node(
1262+
base_dir=os.path.join(module_name, fname, 'node'),
1263+
set_replication=True,
1264+
# initdb_params=['--data-checksums'],
1265+
pg_options={
1266+
'autovacuum': 'off'})
1267+
1268+
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
1269+
self.init_pb(backup_dir)
1270+
self.add_instance(backup_dir, 'node', node)
1271+
self.set_archiving(backup_dir, 'node', node)
1272+
node.slow_start()
1273+
1274+
node.safe_psql(
1275+
'postgres',
1276+
'create extension pageinspect')
1277+
1278+
# FULL backup
1279+
con = node.connect("postgres")
1280+
con.execute("CREATE TABLE t1 (a int)")
1281+
con.commit()
1282+
1283+
1284+
con.execute("INSERT INTO t1 values (1)")
1285+
con.commit()
1286+
1287+
# leave uncommited
1288+
con2 = node.connect("postgres")
1289+
con.execute("INSERT INTO t1 values (2)")
1290+
con2.execute("INSERT INTO t1 values (3)")
1291+
1292+
full_id = self.backup_node(
1293+
backup_dir, 'node', node,
1294+
backup_type="full", options=["-j", "4", "--stream"])
1295+
1296+
self.backup_node(
1297+
backup_dir, 'node', node,
1298+
backup_type="delta", options=["-j", "4", "--stream"])
1299+
1300+
con.commit()
1301+
1302+
node.safe_psql(
1303+
'postgres',
1304+
'select * from t1')
1305+
1306+
con2.commit()
1307+
node.safe_psql(
1308+
'postgres',
1309+
'select * from t1')
1310+
1311+
node.stop()
1312+
1313+
print(self.restore_node(
1314+
backup_dir, 'node', node, backup_id=full_id,
1315+
options=["-j", "4", '--incremental-mode=checksum']))
1316+
1317+
node.slow_start()
1318+
1319+
self.assertEqual(
1320+
node.safe_psql(
1321+
'postgres',
1322+
'select count(*) from t1').rstrip(),
1323+
'1')
1324+
1325+
# Clean after yourself
1326+
self.del_test_dir(module_name, fname)
1327+
1328+
# @unittest.skip("skip")
1329+
# @unittest.expectedFailure
1330+
def test_incr_lsn_long_xact_1(self):
1331+
"""
1332+
"""
1333+
fname = self.id().split('.')[3]
1334+
node = self.make_simple_node(
1335+
base_dir=os.path.join(module_name, fname, 'node'),
1336+
set_replication=True,
1337+
# initdb_params=['--data-checksums'],
1338+
pg_options={
1339+
'autovacuum': 'off'})
1340+
1341+
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
1342+
self.init_pb(backup_dir)
1343+
self.add_instance(backup_dir, 'node', node)
1344+
self.set_archiving(backup_dir, 'node', node)
1345+
node.slow_start()
1346+
1347+
node.safe_psql(
1348+
'postgres',
1349+
'create extension pageinspect')
1350+
1351+
# FULL backup
1352+
con = node.connect("postgres")
1353+
con.execute("CREATE TABLE t1 (a int)")
1354+
con.commit()
1355+
1356+
1357+
con.execute("INSERT INTO t1 values (1)")
1358+
con.commit()
1359+
1360+
# leave uncommited
1361+
con2 = node.connect("postgres")
1362+
con.execute("INSERT INTO t1 values (2)")
1363+
con2.execute("INSERT INTO t1 values (3)")
1364+
1365+
full_id = self.backup_node(
1366+
backup_dir, 'node', node,
1367+
backup_type="full", options=["-j", "4", "--stream"])
1368+
1369+
self.backup_node(
1370+
backup_dir, 'node', node,
1371+
backup_type="delta", options=["-j", "4", "--stream"])
1372+
1373+
con.commit()
1374+
1375+
# when does LSN gets stamped when checksum gets updated ?
1376+
node.safe_psql(
1377+
'postgres',
1378+
'select * from t1')
1379+
1380+
con2.commit()
1381+
node.safe_psql(
1382+
'postgres',
1383+
'select * from t1')
1384+
1385+
node.stop()
1386+
1387+
try:
1388+
print(self.restore_node(
1389+
backup_dir, 'node', node, backup_id=full_id,
1390+
options=["-j", "4", '--incremental-mode=lsn']))
1391+
# we should die here because exception is what we expect to happen
1392+
self.assertEqual(
1393+
1, 0,
1394+
"Expecting Error because incremental restore in lsn mode is impossible\n "
1395+
"Output: {0} \n CMD: {1}".format(
1396+
repr(self.output), self.cmd))
1397+
except ProbackupException as e:
1398+
self.assertIn(
1399+
"ERROR: Incremental restore in 'lsn' mode require data_checksums to be "
1400+
"enabled in destination data directory",
1401+
e.message,
1402+
'\n Unexpected Error Message: {0}\n CMD: {1}'.format(
1403+
repr(e.message), self.cmd))
1404+
1405+
# Clean after yourself
1406+
self.del_test_dir(module_name, fname)
1407+
1408+
# @unittest.skip("skip")
1409+
# @unittest.expectedFailure
1410+
def test_incr_lsn_long_xact_2(self):
1411+
"""
1412+
"""
1413+
fname = self.id().split('.')[3]
1414+
node = self.make_simple_node(
1415+
base_dir=os.path.join(module_name, fname, 'node'),
1416+
set_replication=True,
1417+
initdb_params=['--data-checksums'],
1418+
pg_options={
1419+
'autovacuum': 'off',
1420+
'full_page_writes': 'off',
1421+
'wal_log_hints': 'off'})
1422+
1423+
backup_dir = os.path.join(self.tmp_path, module_name, fname, 'backup')
1424+
self.init_pb(backup_dir)
1425+
self.add_instance(backup_dir, 'node', node)
1426+
self.set_archiving(backup_dir, 'node', node)
1427+
node.slow_start()
1428+
1429+
node.safe_psql(
1430+
'postgres',
1431+
'create extension pageinspect')
1432+
1433+
# FULL backup
1434+
con = node.connect("postgres")
1435+
con.execute("CREATE TABLE t1 (a int)")
1436+
con.commit()
1437+
1438+
1439+
con.execute("INSERT INTO t1 values (1)")
1440+
con.commit()
1441+
1442+
# leave uncommited
1443+
con2 = node.connect("postgres")
1444+
con.execute("INSERT INTO t1 values (2)")
1445+
con2.execute("INSERT INTO t1 values (3)")
1446+
1447+
full_id = self.backup_node(
1448+
backup_dir, 'node', node,
1449+
backup_type="full", options=["-j", "4", "--stream"])
1450+
1451+
self.backup_node(
1452+
backup_dir, 'node', node,
1453+
backup_type="delta", options=["-j", "4", "--stream"])
1454+
1455+
print(node.safe_psql(
1456+
'postgres',
1457+
"select * from page_header(get_raw_page('t1', 0))"))
1458+
1459+
con.commit()
1460+
1461+
# when does LSN gets stamped when checksum gets updated ?
1462+
node.safe_psql(
1463+
'postgres',
1464+
'select * from t1')
1465+
1466+
print(node.safe_psql(
1467+
'postgres',
1468+
"select * from page_header(get_raw_page('t1', 0))"))
1469+
1470+
print("HELLO")
1471+
1472+
con2.commit()
1473+
node.safe_psql(
1474+
'postgres',
1475+
'select * from t1')
1476+
1477+
print(node.safe_psql(
1478+
'postgres',
1479+
"select * from page_header(get_raw_page('t1', 0))"))
1480+
1481+
node.stop()
1482+
1483+
print(self.restore_node(
1484+
backup_dir, 'node', node, backup_id=full_id,
1485+
options=["-j", "4", '--incremental-mode=lsn']))
1486+
1487+
node.slow_start()
1488+
1489+
self.assertEqual(
1490+
node.safe_psql(
1491+
'postgres',
1492+
'select count(*) from t1').rstrip(),
1493+
'1')
1494+
1495+
# Clean after yourself
1496+
self.del_test_dir(module_name, fname)
12551497
# check that MinRecPoint and BackupStartLsn are correctly used in case of --incrementa-lsn
12561498
# incremental restore + partial restore.

0 commit comments

Comments
 (0)