mirror of
https://github.com/neondatabase/neon.git
synced 2026-01-05 04:22:56 +00:00
this patch adds support for tenants. This touches mostly pageserver. Directory layout on disk is changed to contain new layer of indirection. Now path to particular repository has the following structure: <pageserver workdir>/tenants/<tenant id>. Tenant id has the same format as timeline id. Tenant id is included in pageserver commands when needed. Also new commands are available in pageserver: tenant_list, tenant_create. This is also reflected CLI. During init default tenant is created and it's id is saved in CLI config, so following commands can use it without extra options. Tenant id is also included in compute postgres configuration, so it can be passed via ServerInfo to safekeeper and in connection string to pageserver. For more info see docs/multitenancy.md.
66 lines
2.2 KiB
Python
66 lines
2.2 KiB
Python
from fixtures.zenith_fixtures import PostgresFactory, ZenithPageserver
|
|
|
|
pytest_plugins = ("fixtures.zenith_fixtures")
|
|
|
|
|
|
#
|
|
# Test multixact state after branching
|
|
# Now this test is very minimalistic -
|
|
# it only checks next_multixact_id field in restored pg_control,
|
|
# since we don't have functions to check multixact internals.
|
|
#
|
|
def test_multixact(pageserver: ZenithPageserver, postgres: PostgresFactory, pg_bin, zenith_cli, base_dir):
|
|
# Create a branch for us
|
|
zenith_cli.run(["branch", "test_multixact", "empty"])
|
|
pg = postgres.create_start('test_multixact')
|
|
|
|
print("postgres is running on 'test_multixact' branch")
|
|
pg_conn = pg.connect()
|
|
cur = pg_conn.cursor()
|
|
|
|
cur.execute('''
|
|
CREATE TABLE t1(i int primary key);
|
|
INSERT INTO t1 select * from generate_series(1, 100);
|
|
''')
|
|
|
|
cur.execute('SELECT next_multixact_id FROM pg_control_checkpoint()')
|
|
next_multixact_id_old = cur.fetchone()[0]
|
|
|
|
# Lock entries in parallel connections to set multixact
|
|
nclients = 3
|
|
connections = []
|
|
for i in range(nclients):
|
|
# Do not turn on autocommit. We want to hold the key-share locks.
|
|
conn = pg.connect(autocommit=False)
|
|
conn.cursor().execute('select * from t1 for key share')
|
|
connections.append(conn)
|
|
|
|
# We should have a multixact now. We can close the connections.
|
|
for c in connections:
|
|
c.close()
|
|
|
|
# force wal flush
|
|
cur.execute('checkpoint')
|
|
|
|
cur.execute('SELECT next_multixact_id, pg_current_wal_flush_lsn() FROM pg_control_checkpoint()')
|
|
res = cur.fetchone()
|
|
next_multixact_id = res[0]
|
|
lsn = res[1]
|
|
|
|
# Ensure that we did lock some tuples
|
|
assert int(next_multixact_id) > int(next_multixact_id_old)
|
|
|
|
# Branch at this point
|
|
zenith_cli.run(["branch", "test_multixact_new", "test_multixact@" + lsn])
|
|
pg_new = postgres.create_start('test_multixact_new')
|
|
|
|
print("postgres is running on 'test_multixact_new' branch")
|
|
pg_new_conn = pg_new.connect()
|
|
cur_new = pg_new_conn.cursor()
|
|
|
|
cur_new.execute('SELECT next_multixact_id FROM pg_control_checkpoint()')
|
|
next_multixact_id_new = cur_new.fetchone()[0]
|
|
|
|
# Check that we restored pg_controlfile correctly
|
|
assert next_multixact_id_new == next_multixact_id
|