Compare commits

...

4 Commits

Author SHA1 Message Date
Arthur Petukhovsky
19e26f53fb Adjust test parameters 2021-10-08 12:42:48 +03:00
Arthur Petukhovsky
18ade98955 Remove large wal test 2021-10-08 11:49:29 +03:00
Arthur Petukhovsky
849bbfa777 Set more test iterations 2021-10-07 17:02:46 +03:00
Arthur Petukhovsky
f7f377cfc1 Add safekeeper test with large wal records 2021-10-07 16:15:44 +03:00
3 changed files with 18 additions and 10 deletions

2
.gitmodules vendored
View File

@@ -1,4 +1,4 @@
[submodule "vendor/postgres"]
path = vendor/postgres
url = https://github.com/zenithdb/postgres
branch = main
branch = walproposer_more_logs

View File

@@ -33,11 +33,16 @@ class BankClient(object):
row = await self.conn.fetchrow('SELECT sum(amount) AS sum FROM bank_accs')
assert row['sum'] == self.n_accounts * self.init_amount
async def bank_transfer(conn: asyncpg.Connection, from_uid, to_uid, amount):
async def bank_transfer(conn: asyncpg.Connection, from_uid, to_uid, amount, large_wal=False):
# avoid deadlocks by sorting uids
if from_uid > to_uid:
from_uid, to_uid, amount = to_uid, from_uid, -amount
if large_wal:
# record with size about 128kb
await conn.execute("SELECT pg_logical_emit_message(false, 'hello', REPEAT('abacaba', 19000))")
return
async with conn.transaction():
await conn.execute(
'UPDATE bank_accs SET amount = amount + ($1) WHERE uid = $2',
@@ -72,7 +77,7 @@ class WorkerStats(object):
print('All workers made {} transactions'.format(progress))
async def run_random_worker(stats: WorkerStats, pg: Postgres, worker_id, n_accounts, max_transfer):
async def run_random_worker(stats: WorkerStats, pg: Postgres, worker_id, n_accounts, max_transfer, large_wal=False):
pg_conn = await pg.connect_async()
debug_print('Started worker {}'.format(worker_id))
@@ -81,7 +86,7 @@ async def run_random_worker(stats: WorkerStats, pg: Postgres, worker_id, n_accou
to_uid = (from_uid + random.randint(1, n_accounts - 1)) % n_accounts
amount = random.randint(1, max_transfer)
await bank_transfer(pg_conn, from_uid, to_uid, amount)
await bank_transfer(pg_conn, from_uid, to_uid, amount, large_wal=large_wal)
stats.inc_progress(worker_id)
debug_print('Executed transfer({}) {} => {}'.format(amount, from_uid, to_uid))
@@ -95,12 +100,10 @@ async def run_random_worker(stats: WorkerStats, pg: Postgres, worker_id, n_accou
# On each iteration 1 acceptor is stopped, and 2 others should allow
# background workers execute transactions. In the end, state should remain
# consistent.
async def run_restarts_under_load(pg: Postgres, acceptors: List[WalAcceptor], n_workers=10):
async def run_restarts_under_load(pg: Postgres, acceptors: List[WalAcceptor], n_workers=10, period_time=10, iterations=6, large_wal=False, normal_work_sleep=0):
n_accounts = 100
init_amount = 100000
max_transfer = 100
period_time = 10
iterations = 6
pg_conn = await pg.connect_async()
bank = BankClient(pg_conn, n_accounts=n_accounts, init_amount=init_amount)
@@ -110,7 +113,7 @@ async def run_restarts_under_load(pg: Postgres, acceptors: List[WalAcceptor], n_
stats = WorkerStats(n_workers)
workers = []
for worker_id in range(n_workers):
worker = run_random_worker(stats, pg, worker_id, bank.n_accounts, max_transfer)
worker = run_random_worker(stats, pg, worker_id, bank.n_accounts, max_transfer, large_wal=large_wal)
workers.append(asyncio.create_task(worker))
@@ -133,6 +136,11 @@ async def run_restarts_under_load(pg: Postgres, acceptors: List[WalAcceptor], n_
stats.check_progress()
victim.start()
# sleep to sync all safekepeers together
if normal_work_sleep > 0:
await asyncio.sleep(normal_work_sleep)
print('Iterations are finished, exiting coroutines...')
stats.running = False
@@ -153,7 +161,7 @@ def test_restarts_under_load(zenith_cli, pageserver: ZenithPageserver, postgres:
pg = postgres.create_start('test_wal_acceptors_restarts_under_load',
wal_acceptors=wa_factory.get_connstrs())
asyncio.run(run_restarts_under_load(pg, wa_factory.instances))
asyncio.run(run_restarts_under_load(pg, wa_factory.instances, iterations=9, n_workers=30, period_time=5))
# TODO: Remove when https://github.com/zenithdb/zenith/issues/644 is fixed
pg.stop()