diff --git a/control_plane/src/compute.rs b/control_plane/src/compute.rs index f33d77720c..9a262a075a 100644 --- a/control_plane/src/compute.rs +++ b/control_plane/src/compute.rs @@ -87,9 +87,11 @@ impl ComputeControlPlane { pub fn new_node( &mut self, tenantid: ZTenantId, + name: &str, branch_name: &str, port: Option, ) -> Result> { + // Resolve the timeline ID, given the human-readable branch name let timeline_id = self .pageserver .branch_get_by_name(&tenantid, branch_name)? @@ -97,7 +99,7 @@ impl ComputeControlPlane { let port = port.unwrap_or_else(|| self.get_port()); let node = Arc::new(PostgresNode { - name: branch_name.to_owned(), + name: name.to_owned(), address: SocketAddr::new("127.0.0.1".parse().unwrap(), port), env: self.env.clone(), pageserver: Arc::clone(&self.pageserver), diff --git a/test_runner/batch_others/test_tenants.py b/test_runner/batch_others/test_tenants.py index ee6bb0bfd3..b05a4a9f62 100644 --- a/test_runner/batch_others/test_tenants.py +++ b/test_runner/batch_others/test_tenants.py @@ -28,11 +28,13 @@ def test_tenants_normal_work( pg_tenant1 = postgres.create_start( f"test_tenants_normal_work_with_wal_acceptors{with_wal_acceptors}", + None, # branch name, None means same as node name tenant_1, wal_acceptors=wa_factory.get_connstrs() if with_wal_acceptors else None, ) pg_tenant2 = postgres.create_start( f"test_tenants_normal_work_with_wal_acceptors{with_wal_acceptors}", + None, # branch name, None means same as node name tenant_2, wal_acceptors=wa_factory.get_connstrs() if with_wal_acceptors else None, ) diff --git a/test_runner/fixtures/zenith_fixtures.py b/test_runner/fixtures/zenith_fixtures.py index 80246193fa..eda04a8da6 100644 --- a/test_runner/fixtures/zenith_fixtures.py +++ b/test_runner/fixtures/zenith_fixtures.py @@ -530,15 +530,16 @@ class Postgres(PgProtocol): self.zenith_cli = zenith_cli self.running = False self.repo_dir = repo_dir - self.branch: Optional[str] = None # dubious, see asserts below + self.node_name: Optional[str] = None # dubious, see asserts below self.pgdata_dir: Optional[str] = None # Path to computenode PGDATA self.tenant_id = tenant_id self.pg_bin = pg_bin - # path to conf is /pgdatadirs/tenants///postgresql.conf + # path to conf is /pgdatadirs/tenants///postgresql.conf def create( self, - branch: str, + node_name: str, + branch: Optional[str] = None, wal_acceptors: Optional[str] = None, config_lines: Optional[List[str]] = None, ) -> 'Postgres': @@ -552,9 +553,12 @@ class Postgres(PgProtocol): if not config_lines: config_lines = [] - self.zenith_cli.run(['pg', 'create', branch, f'--tenantid={self.tenant_id}', f'--port={self.port}']) - self.branch = branch - path = pathlib.Path('pgdatadirs') / 'tenants' / self.tenant_id / self.branch + if branch is None: + branch = node_name + + self.zenith_cli.run(['pg', 'create', f'--tenantid={self.tenant_id}', f'--port={self.port}', node_name, branch]) + self.node_name = node_name + path = pathlib.Path('pgdatadirs') / 'tenants' / self.tenant_id / self.node_name self.pgdata_dir = os.path.join(self.repo_dir, path) if wal_acceptors is not None: @@ -571,11 +575,11 @@ class Postgres(PgProtocol): Returns self. """ - assert self.branch is not None + assert self.node_name is not None - log.info(f"Starting postgres on branch {self.branch}") + log.info(f"Starting postgres node {self.node_name}") - run_result = self.zenith_cli.run(['pg', 'start', self.branch, f'--tenantid={self.tenant_id}', f'--port={self.port}']) + run_result = self.zenith_cli.run(['pg', 'start', f'--tenantid={self.tenant_id}', f'--port={self.port}', self.node_name]) self.running = True log.info(f"stdout: {run_result.stdout}") @@ -584,7 +588,7 @@ class Postgres(PgProtocol): def pg_data_dir_path(self) -> str: """ Path to data directory """ - path = pathlib.Path('pgdatadirs') / 'tenants' / self.tenant_id / self.branch + path = pathlib.Path('pgdatadirs') / 'tenants' / self.tenant_id / self.node_name return os.path.join(self.repo_dir, path) def pg_xact_dir_path(self) -> str: @@ -641,8 +645,8 @@ class Postgres(PgProtocol): """ if self.running: - assert self.branch is not None - self.zenith_cli.run(['pg', 'stop', self.branch, f'--tenantid={self.tenant_id}']) + assert self.node_name is not None + self.zenith_cli.run(['pg', 'stop', self.node_name, f'--tenantid={self.tenant_id}']) self.running = False return self @@ -653,15 +657,16 @@ class Postgres(PgProtocol): Returns self. """ - assert self.branch is not None + assert self.node_name is not None assert self.tenant_id is not None - self.zenith_cli.run(['pg', 'stop', '--destroy', self.branch, f'--tenantid={self.tenant_id}']) + self.zenith_cli.run(['pg', 'stop', '--destroy', self.node_name, f'--tenantid={self.tenant_id}']) return self def create_start( self, - branch: str, + node_name: str, + branch: Optional[str] = None, wal_acceptors: Optional[str] = None, config_lines: Optional[List[str]] = None, ) -> 'Postgres': @@ -672,6 +677,7 @@ class Postgres(PgProtocol): """ self.create( + node_name=node_name, branch=branch, wal_acceptors=wal_acceptors, config_lines=config_lines, @@ -698,11 +704,13 @@ class PostgresFactory: def create_start( self, - branch: str = "main", + node_name: str = "main", + branch: Optional[str] = None, tenant_id: Optional[str] = None, wal_acceptors: Optional[str] = None, config_lines: Optional[List[str]] = None ) -> Postgres: + pg = Postgres( zenith_cli=self.zenith_cli, repo_dir=self.repo_dir, @@ -714,6 +722,7 @@ class PostgresFactory: self.instances.append(pg) return pg.create_start( + node_name=node_name, branch=branch, wal_acceptors=wal_acceptors, config_lines=config_lines, @@ -721,7 +730,8 @@ class PostgresFactory: def create( self, - branch: str = "main", + node_name: str = "main", + branch: Optional[str] = None, tenant_id: Optional[str] = None, wal_acceptors: Optional[str] = None, config_lines: Optional[List[str]] = None @@ -739,6 +749,7 @@ class PostgresFactory: self.instances.append(pg) return pg.create( + node_name=node_name, branch=branch, wal_acceptors=wal_acceptors, config_lines=config_lines, @@ -746,7 +757,7 @@ class PostgresFactory: def config( self, - branch: str = "main", + node_name: str = "main", tenant_id: Optional[str] = None, wal_acceptors: Optional[str] = None, config_lines: Optional[List[str]] = None @@ -764,7 +775,7 @@ class PostgresFactory: self.instances.append(pg) return pg.config( - branch=branch, + node_name=node_name, wal_acceptors=wal_acceptors, config_lines=config_lines, ) @@ -1116,7 +1127,7 @@ def check_restored_datadir_content(zenith_cli: ZenithCli, test_output_dir: str, pg.stop() # Take a basebackup from pageserver - restored_dir_path = os.path.join(test_output_dir, f"{pg.branch}_restored_datadir") + restored_dir_path = os.path.join(test_output_dir, f"{pg.node_name}_restored_datadir") mkdir_if_needed(restored_dir_path) psql_path = os.path.join(pg.pg_bin.pg_bin_path, 'psql') diff --git a/test_runner/performance/test_bulk_tenant_create.py b/test_runner/performance/test_bulk_tenant_create.py index e1de1dd014..3612189544 100644 --- a/test_runner/performance/test_bulk_tenant_create.py +++ b/test_runner/performance/test_bulk_tenant_create.py @@ -46,6 +46,7 @@ def test_bulk_tenant_create( pg_tenant = postgres.create_start( f"test_bulk_tenant_create_{tenants_count}_{i}_{use_wal_acceptors}", + None, # branch name, None means same as node name tenant, wal_acceptors=wa_factory.get_connstrs() if use_wal_acceptors == 'with_wa' else None, ) diff --git a/zenith/src/main.rs b/zenith/src/main.rs index e86ce10041..1692695767 100644 --- a/zenith/src/main.rs +++ b/zenith/src/main.rs @@ -457,26 +457,28 @@ fn handle_pg(pg_match: &ArgMatches, env: &local_env::LocalEnv) -> Result<()> { let tenantid: ZTenantId = create_match .value_of("tenantid") .map_or(Ok(env.tenantid), |value| value.parse())?; - let timeline_name = create_match.value_of("timeline").unwrap_or("main"); + let node_name = start_match.value_of("node").unwrap_or("main"); + let timeline_name = start_match.value_of("timeline"); let port: Option = match create_match.value_of("port") { Some(p) => Some(p.parse()?), None => None, }; - cplane.new_node(tenantid, timeline_name, port)?; + cplane.new_node(tenantid, node_name, timeline_name, port)?; } ("start", Some(start_match)) => { let tenantid: ZTenantId = start_match .value_of("tenantid") .map_or(Ok(env.tenantid), |value| value.parse())?; - let timeline_name = start_match.value_of("timeline").unwrap_or("main"); + let node_name = start_match.value_of("node").unwrap_or("main"); + let timeline_name = start_match.value_of("timeline"); let port: Option = match start_match.value_of("port") { Some(p) => Some(p.parse()?), None => None, }; - let node = cplane.nodes.get(&(tenantid, timeline_name.to_owned())); + let node = cplane.nodes.get(&(tenantid, node_name.to_owned())); let auth_token = if matches!(env.auth_type, AuthType::ZenithJWT) { let claims = Claims::new(Some(tenantid), Scope::Tenant); @@ -498,7 +500,7 @@ fn handle_pg(pg_match: &ArgMatches, env: &local_env::LocalEnv) -> Result<()> { // start --port X // stop // start <-- will also use port X even without explicit port argument - let node = cplane.new_node(tenantid, timeline_name, port)?; + let node = cplane.new_node(tenantid, node_name, timeline_name, port)?; node.start(&auth_token)?; } }