mirror of
https://github.com/postgrespro/pg_probackup.git
synced 2024-11-24 08:52:38 +02:00
tests: table_checksum needs no sorting in fact
since we are compare table content exactly
This commit is contained in:
parent
8d8a92c1d1
commit
02e3fb0477
@ -2215,7 +2215,7 @@ class ArchiveTest(ProbackupTest, unittest.TestCase):
|
||||
node.slow_start()
|
||||
|
||||
node.pgbench_init(scale=20)
|
||||
result = node.table_checksum("pgbench_accounts", "aid")
|
||||
result = node.table_checksum("pgbench_accounts")
|
||||
node.stop()
|
||||
node.cleanup()
|
||||
|
||||
@ -2240,7 +2240,7 @@ class ArchiveTest(ProbackupTest, unittest.TestCase):
|
||||
|
||||
node.slow_start()
|
||||
|
||||
result_new = node.table_checksum("pgbench_accounts", "aid")
|
||||
result_new = node.table_checksum("pgbench_accounts")
|
||||
|
||||
self.assertEqual(result, result_new)
|
||||
|
||||
|
@ -761,7 +761,7 @@ class CfsBackupNoEncTest(ProbackupTest, unittest.TestCase):
|
||||
't_heap', tblspace_name)
|
||||
)
|
||||
|
||||
full_result = self.node.table_checksum("t_heap", "id")
|
||||
full_result = self.node.table_checksum("t_heap")
|
||||
|
||||
try:
|
||||
backup_id_full = self.backup_node(
|
||||
@ -783,7 +783,7 @@ class CfsBackupNoEncTest(ProbackupTest, unittest.TestCase):
|
||||
't_heap')
|
||||
)
|
||||
|
||||
page_result = self.node.table_checksum("t_heap", "id")
|
||||
page_result = self.node.table_checksum("t_heap")
|
||||
|
||||
try:
|
||||
backup_id_page = self.backup_node(
|
||||
@ -824,7 +824,7 @@ class CfsBackupNoEncTest(ProbackupTest, unittest.TestCase):
|
||||
self.node.slow_start()
|
||||
self.assertEqual(
|
||||
full_result,
|
||||
self.node.table_checksum("t_heap", "id"),
|
||||
self.node.table_checksum("t_heap"),
|
||||
'Lost data after restore')
|
||||
|
||||
# CHECK PAGE BACKUP
|
||||
@ -843,7 +843,7 @@ class CfsBackupNoEncTest(ProbackupTest, unittest.TestCase):
|
||||
self.node.slow_start()
|
||||
self.assertEqual(
|
||||
page_result,
|
||||
self.node.table_checksum("t_heap", "id"),
|
||||
self.node.table_checksum("t_heap"),
|
||||
'Lost data after restore')
|
||||
|
||||
# @unittest.expectedFailure
|
||||
@ -877,8 +877,8 @@ class CfsBackupNoEncTest(ProbackupTest, unittest.TestCase):
|
||||
"FROM generate_series(0,1005000) i".format(
|
||||
't_heap_2', tblspace_name_2))
|
||||
|
||||
full_result_1 = self.node.table_checksum("t_heap_1", "id")
|
||||
full_result_2 = self.node.table_checksum("t_heap_2", "id")
|
||||
full_result_1 = self.node.table_checksum("t_heap_1")
|
||||
full_result_2 = self.node.table_checksum("t_heap_2")
|
||||
|
||||
try:
|
||||
backup_id_full = self.backup_node(
|
||||
@ -909,8 +909,8 @@ class CfsBackupNoEncTest(ProbackupTest, unittest.TestCase):
|
||||
't_heap_2')
|
||||
)
|
||||
|
||||
page_result_1 = self.node.table_checksum("t_heap_1", "id")
|
||||
page_result_2 = self.node.table_checksum("t_heap_2", "id")
|
||||
page_result_1 = self.node.table_checksum("t_heap_1")
|
||||
page_result_2 = self.node.table_checksum("t_heap_2")
|
||||
|
||||
try:
|
||||
backup_id_page = self.backup_node(
|
||||
@ -951,11 +951,11 @@ class CfsBackupNoEncTest(ProbackupTest, unittest.TestCase):
|
||||
|
||||
self.assertEqual(
|
||||
full_result_1,
|
||||
self.node.table_checksum("t_heap_1", "id"),
|
||||
self.node.table_checksum("t_heap_1"),
|
||||
'Lost data after restore')
|
||||
self.assertEqual(
|
||||
full_result_2,
|
||||
self.node.table_checksum("t_heap_2", "id"),
|
||||
self.node.table_checksum("t_heap_2"),
|
||||
'Lost data after restore')
|
||||
|
||||
# CHECK PAGE BACKUP
|
||||
@ -972,11 +972,11 @@ class CfsBackupNoEncTest(ProbackupTest, unittest.TestCase):
|
||||
|
||||
self.assertEqual(
|
||||
page_result_1,
|
||||
self.node.table_checksum("t_heap_1", "id"),
|
||||
self.node.table_checksum("t_heap_1"),
|
||||
'Lost data after restore')
|
||||
self.assertEqual(
|
||||
page_result_2,
|
||||
self.node.table_checksum("t_heap_2", "id"),
|
||||
self.node.table_checksum("t_heap_2"),
|
||||
'Lost data after restore')
|
||||
|
||||
# @unittest.expectedFailure
|
||||
|
@ -15,7 +15,6 @@ import select
|
||||
from time import sleep
|
||||
import re
|
||||
import json
|
||||
from hashlib import md5
|
||||
import random
|
||||
|
||||
idx_ptrack = {
|
||||
@ -202,30 +201,28 @@ class PostgresNodeExtended(testgres.PostgresNode):
|
||||
os.kill(self.auxiliary_pids[someone][0], sig)
|
||||
self.is_started = False
|
||||
|
||||
def table_checksum(self, table, sort, dbname="postgres"):
|
||||
curname = "cur_"+str(random.randint(0,2**48))
|
||||
|
||||
sum = md5(b"\x01")
|
||||
|
||||
def table_checksum(self, table, dbname="postgres"):
|
||||
con = self.connect(dbname=dbname)
|
||||
|
||||
con.execute(f"""
|
||||
DECLARE {curname} NO SCROLL CURSOR FOR
|
||||
SELECT t::text FROM {table} as t ORDER BY {sort};
|
||||
""")
|
||||
curname = "cur_"+str(random.randint(0,2**48))
|
||||
|
||||
con.execute("""
|
||||
DECLARE %s NO SCROLL CURSOR FOR
|
||||
SELECT t::text FROM %s as t
|
||||
""" % (curname, table))
|
||||
|
||||
sum = hashlib.md5()
|
||||
while True:
|
||||
rows = con.execute(f"FETCH FORWARD 5000 FROM {curname}")
|
||||
rows = con.execute("FETCH FORWARD 5000 FROM %s" % curname)
|
||||
if not rows:
|
||||
break
|
||||
for row in rows:
|
||||
# hash uses SipHash since Python3.4, therefore it is good enough
|
||||
sum.update(row[0].encode('utf8'))
|
||||
sum.update(b'\x00')
|
||||
|
||||
con.execute(f"CLOSE {curname}; ROLLBACK;")
|
||||
|
||||
con.close()
|
||||
sum.update(b'\x02')
|
||||
return sum.hexdigest()
|
||||
|
||||
class ProbackupTest(object):
|
||||
|
@ -1191,7 +1191,7 @@ class PageTest(ProbackupTest, unittest.TestCase):
|
||||
|
||||
pgdata = self.pgdata_content(node.data_dir)
|
||||
|
||||
result = node.table_checksum("pgbench_accounts", "aid")
|
||||
result = node.table_checksum("pgbench_accounts")
|
||||
|
||||
node_restored = self.make_simple_node(
|
||||
base_dir=os.path.join(self.module_name, self.fname, 'node_restored'))
|
||||
@ -1203,7 +1203,7 @@ class PageTest(ProbackupTest, unittest.TestCase):
|
||||
self.set_auto_conf(node_restored, {'port': node_restored.port})
|
||||
node_restored.slow_start()
|
||||
|
||||
result_new = node_restored.table_checksum("pgbench_accounts", "aid")
|
||||
result_new = node_restored.table_checksum("pgbench_accounts")
|
||||
|
||||
self.assertEqual(result, result_new)
|
||||
|
||||
|
@ -375,7 +375,7 @@ class PtrackTest(ProbackupTest, unittest.TestCase):
|
||||
|
||||
self.switch_wal_segment(node)
|
||||
|
||||
result = node.table_checksum("pgbench_accounts", "aid")
|
||||
result = node.table_checksum("pgbench_accounts")
|
||||
|
||||
node_restored.cleanup()
|
||||
self.restore_node(backup_dir, 'node', node_restored)
|
||||
@ -396,7 +396,7 @@ class PtrackTest(ProbackupTest, unittest.TestCase):
|
||||
# Logical comparison
|
||||
self.assertEqual(
|
||||
result,
|
||||
node.table_checksum("pgbench_accounts", "aid"),
|
||||
node.table_checksum("pgbench_accounts"),
|
||||
'Data loss')
|
||||
|
||||
# @unittest.skip("skip")
|
||||
@ -2037,8 +2037,7 @@ class PtrackTest(ProbackupTest, unittest.TestCase):
|
||||
|
||||
# CREATE TABLE
|
||||
node.pgbench_init(scale=100, options=['--tablespace=somedata'])
|
||||
result = node.table_checksum("pgbench_accounts", "aid",
|
||||
dbname="postgres")
|
||||
result = node.table_checksum("pgbench_accounts")
|
||||
# FULL BACKUP
|
||||
self.backup_node(backup_dir, 'node', node, options=['--stream'])
|
||||
|
||||
@ -2075,8 +2074,7 @@ class PtrackTest(ProbackupTest, unittest.TestCase):
|
||||
|
||||
# GET LOGICAL CONTENT FROM NODE
|
||||
# it`s stupid, because hint`s are ignored by ptrack
|
||||
result = node.table_checksum("pgbench_accounts", "aid",
|
||||
dbname="postgres")
|
||||
result = node.table_checksum("pgbench_accounts")
|
||||
# FIRTS PTRACK BACKUP
|
||||
self.backup_node(
|
||||
backup_dir, 'node', node, backup_type='ptrack', options=['--stream'])
|
||||
@ -2109,8 +2107,7 @@ class PtrackTest(ProbackupTest, unittest.TestCase):
|
||||
restored_node, {'port': restored_node.port})
|
||||
restored_node.slow_start()
|
||||
|
||||
result_new = restored_node.table_checksum("pgbench_accounts", "aid",
|
||||
dbname="postgres")
|
||||
result_new = restored_node.table_checksum("pgbench_accounts")
|
||||
|
||||
# COMPARE RESTORED FILES
|
||||
self.assertEqual(result, result_new, 'data is lost')
|
||||
|
@ -326,7 +326,7 @@ class ReplicaTest(ProbackupTest, unittest.TestCase):
|
||||
|
||||
self.switch_wal_segment(master)
|
||||
|
||||
before = master.table_checksum("pgbench_accounts", "aid")
|
||||
before = master.table_checksum("pgbench_accounts")
|
||||
|
||||
self.validate_pb(backup_dir, 'replica')
|
||||
self.assertEqual(
|
||||
@ -342,7 +342,7 @@ class ReplicaTest(ProbackupTest, unittest.TestCase):
|
||||
node.slow_start()
|
||||
|
||||
# CHECK DATA CORRECTNESS
|
||||
after = master.table_checksum("pgbench_accounts", "aid")
|
||||
after = master.table_checksum("pgbench_accounts")
|
||||
self.assertEqual(
|
||||
before, after, 'Restored data is not equal to original')
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user