From d47de028790fd093b1e48ce06c62ed8f6748614c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Ha=C5=82as?= Date: Mon, 30 Mar 2026 13:48:46 +0200 Subject: [PATCH] Move rebootWorker from Database to AdminClient - Add rebootWorker() method to AdminClient class - Add Database::getDatabasePointer() internal method - Database::rebootWorker() now delegates to AdminClient (marked as deprecated) - Maintains backward compatibility - old code still works - All 158 integration tests pass - PHPStan and PHPCS clean Closes #28 --- src/AdminClient.php | 34 +++++++++++++++++++++++++++++++++- src/Database.php | 27 +++++++++------------------ 2 files changed, 42 insertions(+), 19 deletions(-) diff --git a/src/AdminClient.php b/src/AdminClient.php index 8b23413..b8a341e 100644 --- a/src/AdminClient.php +++ b/src/AdminClient.php @@ -22,7 +22,6 @@ public function __construct( private Database $database, - /** @phpstan-ignore property.onlyWritten */ private NativeClient $client ) { } @@ -95,6 +94,39 @@ public function listTenants(): array return $tenants; } + /** + * Reboots a FoundationDB worker process. + * + * @param string $address The network address of the worker to reboot (e.g., "127.0.0.1:4500") + * @param bool $checkFile If true, checks that a file exists at the specified path before rebooting + * @param int $suspendDuration Duration in seconds to suspend the process (0 for immediate restart) + * + * @throws RebootWorkerException If the reboot operation fails + * + * @warning Do not close the Database immediately after calling this method, as the operation + * may still be in progress. Allow sufficient time for the operation to complete. + */ + public function rebootWorker(string $address, bool $checkFile = false, int $suspendDuration = 0): void + { + $future = new Future\FutureInt64( + // @phpstan-ignore method.notFound + $this->client->fdb->fdb_database_reboot_worker( + $this->database->getDatabasePointer(), + $address, + strlen($address), + $checkFile ? 1 : 0, + $suspendDuration, + ), + $this->client, + ); + + $result = $future->await(); + + if ($result === 0) { + throw new RebootWorkerException($address); + } + } + /** * Configure the database. * diff --git a/src/Database.php b/src/Database.php index 85d279c..9d7385e 100644 --- a/src/Database.php +++ b/src/Database.php @@ -355,6 +355,8 @@ public function getClientStatus(): string /** * Reboots a FoundationDB worker process. * + * @deprecated Use $database->admin()->rebootWorker() instead. This method will be removed in a future version. + * * @param string $address The network address of the worker to reboot (e.g., "127.0.0.1:4500") * @param bool $checkFile If true, checks that a file exists at the specified path before rebooting * @param int $suspendDuration Duration in seconds to suspend the process (0 for immediate restart) @@ -366,24 +368,7 @@ public function getClientStatus(): string */ public function rebootWorker(string $address, bool $checkFile = false, int $suspendDuration = 0): void { - $this->ensureOpen(); - - $future = new Future\FutureInt64( - $this->client->fdb->fdb_database_reboot_worker( - $this->dpointer, - $address, - strlen($address), - $checkFile ? 1 : 0, - $suspendDuration, - ), - $this->client, - ); - - $result = $future->await(); - - if ($result === 0) { - throw new RebootWorkerException($address); - } + $this->admin()->rebootWorker($address, $checkFile, $suspendDuration); } public function options(): DatabaseOptions @@ -409,6 +394,12 @@ public function getClient(): NativeClient return $this->client; } + /** @internal */ + public function getDatabasePointer(): \FFI\CData + { + return $this->dpointer; + } + /** * Get an AdminClient for cluster administration operations. *