8000 [PBCKP-327] test_ptrack_multiple_segments: try to avoid memory consum… · postgrespro/pg_probackup@9bcefb2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9bcefb2

Browse files
committed
[PBCKP-327] test_ptrack_multiple_segments: try to avoid memory consumption
1 parent 744c285 commit 9bcefb2

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

tests/helpers/ptrack_helpers.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
from time import sleep
1616
import re
1717
import json
18+
from hashlib import md5
19+
import random
1820

1921
idx_ptrack = {
2022
't_heap': {
@@ -200,6 +202,32 @@ def kill(self, someone = None):
200202
os.kill(self.auxiliary_pids[someone][0], sig)
201203
self.is_started = False
202204

205+
def table_checksum(self, table, sort, dbname="postgres"):
206+
curname = "cur_"+str(random.randint(0,2**48))
207+
208+
sum = md5(b"\x01")
209+
210+
con = self.connect(dbname=dbname)
211+
212+
con.execute(f"""
213+
DECLARE {curname} NO SCROLL CURSOR FOR
214+
SELECT t::text FROM {table} as t ORDER BY {sort};
215+
""")
216+
217+
while True:
218+
rows = con.execute(f"FETCH FORWARD 10000 FROM {curname}")
219+
if not rows:
220+
break
221+
for row in rows:
222+
sum.update(row[0].encode('utf8'))
223+
sum.update(b'\x00')
224+
225+
con.execute(f"CLOSE {curname}; ROLLBACK;")
226+
227+
con.close()
228+
sum.update(b'\x02')
229+
return sum.hexdigest()
230+
203231
class ProbackupTest(object):
204232
# Class attributes
205233
enterprise = is_enterprise()

tests/ptrack_test.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2039,6 +2039,8 @@ def test_ptrack_multiple_segments(self):
20392039

20402040
# CREATE TABLE
20412041
node.pgbench_init(scale=100, options=['--tablespace=somedata'])
2042+
result = node.table_checksum("pgbench_accounts", "aid",
2043+
dbname="postgres")
20422044
# FULL BACKUP
20432045
self.backup_node(backup_dir, 'node', node, options=['--stream'])
20442046

@@ -2075,7 +2077,8 @@ def test_ptrack_multiple_segments(self):
20752077

20762078
# GET LOGICAL CONTENT FROM NODE
20772079
# it`s stupid, because hint`s are ignored by ptrack
2078-
result = node.safe_psql("postgres", "select * from pgbench_accounts")
2080+
result = node.table_checksum("pgbench_accounts", "aid",
2081+
dbname="postgres")
20792082
# FIRTS PTRACK BACKUP
20802083
self.backup_node(
20812084
backup_dir, 'node', node, backup_type='ptrack', options=['--stream'])
@@ -2108,9 +2111,8 @@ def test_ptrack_multiple_segments(self):
21082111
restored_node, {'port': restored_node.port})
21092112
restored_node.slow_start()
21102113

2111-
result_new = restored_node.safe_psql(
2112-
"postgres",
2113-
"select * from pgbench_accounts")
2114+
result_new = restored_node.table_checksum("pgbench_accounts", "aid",
2115+
dbname="postgres")
21142116

21152117
# COMPARE RESTORED FILES
21162118
self.assertEqual(result, result_new, 'data is lost')

0 commit comments

Comments
 (0)
0