mirror of
https://github.com/neondatabase/neon.git
synced 2026-01-04 20:12:54 +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.
52 lines
1.7 KiB
Python
52 lines
1.7 KiB
Python
from fixtures.zenith_fixtures import PostgresFactory, ZenithPageserver
|
|
|
|
|
|
pytest_plugins = ("fixtures.zenith_fixtures")
|
|
|
|
|
|
#
|
|
# Test branching, when a transaction is in prepared state
|
|
#
|
|
def test_twophase(zenith_cli, pageserver: ZenithPageserver, postgres: PostgresFactory, pg_bin):
|
|
zenith_cli.run(["branch", "test_twophase", "empty"])
|
|
|
|
pg = postgres.create_start('test_twophase', config_lines=['max_prepared_transactions=5'])
|
|
print("postgres is running on 'test_twophase' branch")
|
|
|
|
conn = pg.connect()
|
|
cur = conn.cursor()
|
|
|
|
cur.execute('CREATE TABLE foo (t text)')
|
|
|
|
# Prepare a transaction that will insert a row
|
|
cur.execute('BEGIN')
|
|
cur.execute("INSERT INTO foo VALUES ('one')")
|
|
cur.execute("PREPARE TRANSACTION 'insert_one'")
|
|
|
|
# Prepare another transaction that will insert a row
|
|
cur.execute('BEGIN')
|
|
cur.execute("INSERT INTO foo VALUES ('two')")
|
|
cur.execute("PREPARE TRANSACTION 'insert_two'")
|
|
|
|
# Create a branch with the transaction in prepared state
|
|
zenith_cli.run(["branch", "test_twophase_prepared", "test_twophase"])
|
|
|
|
pg2 = postgres.create_start(
|
|
'test_twophase_prepared',
|
|
config_lines=['max_prepared_transactions=5'],
|
|
)
|
|
conn2 = pg2.connect()
|
|
cur2 = conn2.cursor()
|
|
|
|
# On the new branch, commit one of the prepared transactions, abort the other one.
|
|
cur2.execute("COMMIT PREPARED 'insert_one'")
|
|
cur2.execute("ROLLBACK PREPARED 'insert_two'")
|
|
|
|
cur2.execute('SELECT * FROM foo')
|
|
assert cur2.fetchall() == [('one', )]
|
|
|
|
# Neither insert is visible on the original branch, the transactions are still
|
|
# in prepared state there.
|
|
cur.execute('SELECT * FROM foo')
|
|
assert cur.fetchall() == []
|