From 286f34dfceb7ee2546cc319f1706111e8ebaa669 Mon Sep 17 00:00:00 2001 From: Christian Schwarz Date: Tue, 28 Nov 2023 10:51:37 +0100 Subject: [PATCH] test suite: add method for generation-aware detachment of a tenant (#5939) Part of getpage@lsn benchmark epic: https://github.com/neondatabase/neon/issues/5771 --- test_runner/fixtures/neon_fixtures.py | 18 ++++++++++++++++-- .../regress/test_pageserver_generations.py | 4 ++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/test_runner/fixtures/neon_fixtures.py b/test_runner/fixtures/neon_fixtures.py index 08e1c5eacb..f060a63344 100644 --- a/test_runner/fixtures/neon_fixtures.py +++ b/test_runner/fixtures/neon_fixtures.py @@ -1572,7 +1572,7 @@ class NeonAttachmentService: self.running = False return self - def attach_hook(self, tenant_id: TenantId, pageserver_id: int) -> int: + def attach_hook_issue(self, tenant_id: TenantId, pageserver_id: int) -> int: response = requests.post( f"{self.env.control_plane_api}/attach-hook", json={"tenant_id": str(tenant_id), "node_id": pageserver_id}, @@ -1582,6 +1582,13 @@ class NeonAttachmentService: assert isinstance(gen, int) return gen + def attach_hook_drop(self, tenant_id: TenantId): + response = requests.post( + f"{self.env.control_plane_api}/attach-hook", + json={"tenant_id": str(tenant_id), "node_id": None}, + ) + response.raise_for_status() + def __enter__(self) -> "NeonAttachmentService": return self @@ -1781,13 +1788,20 @@ class NeonPageserver(PgProtocol): to call into the pageserver HTTP client. """ if self.env.attachment_service is not None: - generation = self.env.attachment_service.attach_hook(tenant_id, self.id) + generation = self.env.attachment_service.attach_hook_issue(tenant_id, self.id) else: generation = None client = self.http_client() return client.tenant_attach(tenant_id, config, config_null, generation=generation) + def tenant_detach(self, tenant_id: TenantId): + if self.env.attachment_service is not None: + self.env.attachment_service.attach_hook_drop(tenant_id) + + client = self.http_client() + return client.tenant_detach(tenant_id) + def append_pageserver_param_overrides( params_to_update: List[str], diff --git a/test_runner/regress/test_pageserver_generations.py b/test_runner/regress/test_pageserver_generations.py index c3f4ad476f..66cc286aba 100644 --- a/test_runner/regress/test_pageserver_generations.py +++ b/test_runner/regress/test_pageserver_generations.py @@ -282,7 +282,7 @@ def test_deferred_deletion(neon_env_builder: NeonEnvBuilder): # Now advance the generation in the control plane: subsequent validations # from the running pageserver will fail. No more deletions should happen. - env.attachment_service.attach_hook(env.initial_tenant, some_other_pageserver) + env.attachment_service.attach_hook_issue(env.initial_tenant, some_other_pageserver) generate_uploads_and_deletions(env, init=False) assert_deletion_queue(ps_http, lambda n: n > 0) @@ -397,7 +397,7 @@ def test_deletion_queue_recovery( if keep_attachment == KeepAttachment.LOSE: some_other_pageserver = 101010 assert env.attachment_service is not None - env.attachment_service.attach_hook(env.initial_tenant, some_other_pageserver) + env.attachment_service.attach_hook_issue(env.initial_tenant, some_other_pageserver) env.pageserver.start()