Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion src/AdminClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

public function __construct(
private Database $database,
/** @phpstan-ignore property.onlyWritten */
private NativeClient $client
) {
}
Expand Down Expand Up @@ -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.
*
Expand Down
27 changes: 9 additions & 18 deletions src/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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.
*
Expand Down
Loading