refactor(NeonEnv): shutdown of child processes (#6327)

Also shuts down `Broker`, which, before this PR, we did start in
`start()` but relied on the fixture to stop. Do it a bit earlier so
that, after `NeonEnv.stop()` returns, there are no child processes using
`repo_dir`.


Also, drive-by-fixes inverted logic around `ps_assert_metric_no_errors`,
missed during https://github.com/neondatabase/neon/pull/6295

---------

Co-authored-by: Alexander Bayandin <alexander@neon.tech>
This commit is contained in:
Christian Schwarz
2024-01-12 10:23:21 +01:00
committed by GitHub
parent 7f828890cf
commit 42613d4c30
2 changed files with 23 additions and 14 deletions

View File

@@ -54,7 +54,10 @@ class NeonBroker:
else:
break # success
def stop(self):
def stop(self, immediate: bool = False):
if self.handle is not None:
self.handle.terminate()
if immediate:
self.handle.kill()
else:
self.handle.terminate()
self.handle.wait()

View File

@@ -754,20 +754,12 @@ class NeonEnvBuilder:
# Stop all the nodes.
if self.env:
log.info("Cleaning up all storage and compute nodes")
self.env.endpoints.stop_all()
for sk in self.env.safekeepers:
sk.stop(immediate=True)
for pageserver in self.env.pageservers:
self.env.stop(
immediate=True,
# if the test threw an exception, don't check for errors
# as a failing assertion would cause the cleanup below to fail
if exc_type is not None:
pageserver.assert_no_metric_errors()
pageserver.stop(immediate=True)
self.env.attachment_service.stop(immediate=True)
ps_assert_metric_no_errors=(exc_type is None),
)
cleanup_error = None
if self.scrub_on_exit:
@@ -950,6 +942,20 @@ class NeonEnv:
for safekeeper in self.safekeepers:
safekeeper.start()
def stop(self, immediate=False, ps_assert_metric_no_errors=False):
"""
After this method returns, there should be no child processes running.
"""
self.endpoints.stop_all()
for sk in self.safekeepers:
sk.stop(immediate=immediate)
for pageserver in self.pageservers:
if ps_assert_metric_no_errors:
pageserver.assert_no_metric_errors()
pageserver.stop(immediate=immediate)
self.attachment_service.stop(immediate=immediate)
self.broker.stop(immediate=immediate)
@property
def pageserver(self) -> NeonPageserver:
"""