mirror of
https://github.com/neondatabase/neon.git
synced 2026-01-15 09:22:55 +00:00
We use the term "endpoint" in for compute Postgres nodes in the web UI
and user-facing documentation now. Adjust the nomenclature in the code.
This changes the name of the "neon_local pg" command to "neon_local
endpoint". Also adjust names of classes, variables etc. in the python
tests accordingly.
This also changes the directory structure so that endpoints are now
stored in:
.neon/endpoints/<endpoint id>
instead of:
.neon/pgdatadirs/tenants/<tenant_id>/<endpoint (node) name>
The tenant ID is no longer part of the path. That means that you
cannot have two endpoints with the same name/ID in two different
tenants anymore. That's consistent with how we treat endpoints in the
real control plane and proxy: the endpoint ID must be globally unique.
87 lines
2.8 KiB
Python
87 lines
2.8 KiB
Python
import os
|
|
|
|
from fixtures.log_helper import log
|
|
from fixtures.neon_fixtures import NeonEnv, fork_at_current_lsn
|
|
|
|
|
|
#
|
|
# Test branching, when a transaction is in prepared state
|
|
#
|
|
def test_twophase(neon_simple_env: NeonEnv):
|
|
env = neon_simple_env
|
|
env.neon_cli.create_branch("test_twophase", "empty")
|
|
endpoint = env.endpoints.create_start(
|
|
"test_twophase", config_lines=["max_prepared_transactions=5"]
|
|
)
|
|
log.info("postgres is running on 'test_twophase' branch")
|
|
|
|
conn = endpoint.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'")
|
|
|
|
# Prepare a transaction that will insert a row
|
|
cur.execute("BEGIN")
|
|
cur.execute("INSERT INTO foo VALUES ('three')")
|
|
cur.execute("PREPARE TRANSACTION 'insert_three'")
|
|
|
|
# Prepare another transaction that will insert a row
|
|
cur.execute("BEGIN")
|
|
cur.execute("INSERT INTO foo VALUES ('four')")
|
|
cur.execute("PREPARE TRANSACTION 'insert_four'")
|
|
|
|
# On checkpoint state data copied to files in
|
|
# pg_twophase directory and fsynced
|
|
cur.execute("CHECKPOINT")
|
|
|
|
twophase_files = os.listdir(endpoint.pg_twophase_dir_path())
|
|
log.info(twophase_files)
|
|
assert len(twophase_files) == 4
|
|
|
|
cur.execute("COMMIT PREPARED 'insert_three'")
|
|
cur.execute("ROLLBACK PREPARED 'insert_four'")
|
|
cur.execute("CHECKPOINT")
|
|
|
|
twophase_files = os.listdir(endpoint.pg_twophase_dir_path())
|
|
log.info(twophase_files)
|
|
assert len(twophase_files) == 2
|
|
|
|
# Create a branch with the transaction in prepared state
|
|
fork_at_current_lsn(env, endpoint, "test_twophase_prepared", "test_twophase")
|
|
|
|
# Start compute on the new branch
|
|
endpoint2 = env.endpoints.create_start(
|
|
"test_twophase_prepared",
|
|
config_lines=["max_prepared_transactions=5"],
|
|
)
|
|
|
|
# Check that we restored only needed twophase files
|
|
twophase_files2 = os.listdir(endpoint2.pg_twophase_dir_path())
|
|
log.info(twophase_files2)
|
|
assert twophase_files2.sort() == twophase_files.sort()
|
|
|
|
conn2 = endpoint2.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",), ("three",)]
|
|
|
|
# Only one committed insert is visible on the original branch
|
|
cur.execute("SELECT * FROM foo")
|
|
assert cur.fetchall() == [("three",)]
|