mirror of
https://github.com/neondatabase/neon.git
synced 2026-01-05 12:32:54 +00:00
The codepath for tenant_create command first launched the WAL redo
thread, and then called branches::create_repo() which checked if the
tenant's directory already exists. That's problematic, because
launching the WAL redo thread will run initdb if the directory doesn't
already exist. Race condition: If the tenant already exists, it will
have a WAL redo thread already running, and the old and new WAL redo
thread might try to run initdb at the same time, causing all kinds of
weird failures.
The test_pageserver_api test was failing 100% repeatably on my laptop
because of this. I'm not sure why this doesn't occur on the CI:
Jul 31 18:05:48.877 INFO running initdb in "./tenants/5227e4eb90894775ac6b8a8c76f24b2e/wal-redo-datadir", location: pageserver::walredo, pageserver/src/walredo.rs:483
thread 'WAL redo thread' panicked at 'initdb failed: The files belonging to this database system will be owned by user "heikki".
This user must also own the server process.
The database cluster will be initialized with locale "C".
The default database encoding has accordingly been set to "SQL_ASCII".
The default text search configuration will be set to "english".
Data page checksums are disabled.
creating directory ./tenants/0305b1326f3ea33add0929d516da7cb6/wal-redo-datadir ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... Europe/Helsinki
creating configuration files ... ok
running bootstrap script ...
stderr:
2021-07-31 15:05:48.875 GMT [282569] LOG: could not open configuration file "/home/heikki/git-sandbox/zenith/test_output/test_tenant_list/repo/./tenants/0305b1326f3ea33add0929d516da7cb6/wal-redo-datadir/postgresql.conf": No such file or directory
2021-07-31 15:05:48.875 GMT [282569] FATAL: configuration file "/home/heikki/git-sandbox/zenith/test_output/test_tenant_list/repo/./tenants/0305b1326f3ea33add0929d516da7cb6/wal-redo-datadir/postgresql.conf" contains errors
child process exited with exit code 1
initdb: removing data directory "./tenants/0305b1326f3ea33add0929d516da7cb6/wal-redo-datadir"
77 lines
2.5 KiB
Python
77 lines
2.5 KiB
Python
import json
|
|
import uuid
|
|
import pytest
|
|
import psycopg2
|
|
from fixtures.zenith_fixtures import ZenithPageserver
|
|
|
|
pytest_plugins = ("fixtures.zenith_fixtures")
|
|
|
|
|
|
def test_status(pageserver):
|
|
assert pageserver.safe_psql('status') == [
|
|
('hello world', ),
|
|
]
|
|
|
|
|
|
def test_branch_list(pageserver: ZenithPageserver, zenith_cli):
|
|
# Create a branch for us
|
|
zenith_cli.run(["branch", "test_branch_list_main", "empty"])
|
|
|
|
conn = pageserver.connect()
|
|
cur = conn.cursor()
|
|
|
|
cur.execute(f'branch_list {pageserver.initial_tenant}')
|
|
branches = json.loads(cur.fetchone()[0])
|
|
# Filter out branches created by other tests
|
|
branches = [x for x in branches if x['name'].startswith('test_branch_list')]
|
|
|
|
assert len(branches) == 1
|
|
assert branches[0]['name'] == 'test_branch_list_main'
|
|
assert 'timeline_id' in branches[0]
|
|
assert 'latest_valid_lsn' in branches[0]
|
|
assert 'ancestor_id' in branches[0]
|
|
assert 'ancestor_lsn' in branches[0]
|
|
|
|
# Create another branch, and start Postgres on it
|
|
zenith_cli.run(['branch', 'test_branch_list_experimental', 'test_branch_list_main'])
|
|
zenith_cli.run(['pg', 'create', 'test_branch_list_experimental'])
|
|
|
|
cur.execute(f'branch_list {pageserver.initial_tenant}')
|
|
new_branches = json.loads(cur.fetchone()[0])
|
|
# Filter out branches created by other tests
|
|
new_branches = [x for x in new_branches if x['name'].startswith('test_branch_list')]
|
|
assert len(new_branches) == 2
|
|
new_branches.sort(key=lambda k: k['name'])
|
|
|
|
assert new_branches[0]['name'] == 'test_branch_list_experimental'
|
|
assert new_branches[0]['timeline_id'] != branches[0]['timeline_id']
|
|
|
|
# TODO: do the LSNs have to match here?
|
|
assert new_branches[1] == branches[0]
|
|
|
|
conn.close()
|
|
|
|
|
|
def test_tenant_list(pageserver: ZenithPageserver, zenith_cli):
|
|
res = zenith_cli.run(["tenant", "list"])
|
|
res.check_returncode()
|
|
tenants = res.stdout.splitlines()
|
|
assert tenants == [pageserver.initial_tenant]
|
|
|
|
conn = pageserver.connect()
|
|
cur = conn.cursor()
|
|
|
|
# check same tenant cannot be created twice
|
|
with pytest.raises(psycopg2.DatabaseError, match=f'tenant {pageserver.initial_tenant} already exists'):
|
|
cur.execute(f'tenant_create {pageserver.initial_tenant}')
|
|
|
|
# create one more tenant
|
|
tenant1 = uuid.uuid4().hex
|
|
cur.execute(f'tenant_create {tenant1}')
|
|
|
|
cur.execute('tenant_list')
|
|
|
|
# compare tenants list
|
|
new_tenants = sorted(json.loads(cur.fetchone()[0]))
|
|
assert sorted([pageserver.initial_tenant, tenant1]) == new_tenants
|