mirror of
https://github.com/neondatabase/neon.git
synced 2026-06-01 20:40:37 +00:00
Previously, transaction commit could happen regardless of whether
pageserver has caught up or not. This patch aims to fix that.
There are two notable changes:
1. ComputeControlPlane::new_node() now sets the
`synchronous_standby_names = 'pageserver'` parameter to delay
transaction commit until pageserver acting as a standby has
fetched and ack'd a relevant portion of WAL.
2. pageserver now has to:
- Specify the `application_name = pageserver` which matches the
one in `synchronous_standby_names`.
- Properly reply with the ack'd LSNs.
This means that some tests don't need sleeps anymore.
TODO: We should probably make this behavior configurable.
Fixes #187.
51 lines
1.6 KiB
Python
51 lines
1.6 KiB
Python
import psycopg2
|
|
|
|
pytest_plugins = ("fixtures.zenith_fixtures")
|
|
|
|
|
|
#
|
|
# Test restarting and recreating a postgres instance
|
|
#
|
|
def test_restart_compute(zenith_cli, pageserver, postgres, pg_bin):
|
|
zenith_cli.run(["branch", "test_restart_compute", "empty"])
|
|
|
|
pg = postgres.create_start('test_restart_compute')
|
|
print("postgres is running on 'test_restart_compute' branch")
|
|
|
|
pg_conn = psycopg2.connect(pg.connstr())
|
|
pg_conn.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
|
|
cur = pg_conn.cursor()
|
|
|
|
# Create table, and insert a row
|
|
cur.execute('CREATE TABLE foo (t text)')
|
|
cur.execute("INSERT INTO foo VALUES ('bar')")
|
|
|
|
# Stop and restart the Postgres instance
|
|
pg_conn.close()
|
|
pg.stop()
|
|
pg.start()
|
|
pg_conn = psycopg2.connect(pg.connstr())
|
|
pg_conn.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
|
|
cur = pg_conn.cursor()
|
|
|
|
# We can still see the row
|
|
cur.execute('SELECT count(*) FROM foo')
|
|
assert cur.fetchone() == (1, )
|
|
|
|
# Insert another row
|
|
cur.execute("INSERT INTO foo VALUES ('bar2')")
|
|
cur.execute('SELECT count(*) FROM foo')
|
|
assert cur.fetchone() == (2, )
|
|
|
|
# Stop, and destroy the Postgres instance. Then recreate and restart it.
|
|
pg_conn.close()
|
|
pg.stop_and_destroy()
|
|
pg.create_start('test_restart_compute')
|
|
pg_conn = psycopg2.connect(pg.connstr())
|
|
pg_conn.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
|
|
cur = pg_conn.cursor()
|
|
|
|
# We can still see the rows
|
|
cur.execute('SELECT count(*) FROM foo')
|
|
assert cur.fetchone() == (2, )
|