Separate
One container per queue for scale-out
diff --git a/src/Appwrite/Platform/Installer/Http/Installer/View.php b/src/Appwrite/Platform/Installer/Http/Installer/View.php
index dea356eaaf..15a775d0fa 100644
--- a/src/Appwrite/Platform/Installer/Http/Installer/View.php
+++ b/src/Appwrite/Platform/Installer/Http/Installer/View.php
@@ -44,6 +44,7 @@ class View extends Action
$defaultHttpsPort = $config->getDefaultHttpsPort();
$isUpgrade = $config->isUpgrade();
$lockedDatabase = $config->getLockedDatabase();
+ $topology = $config->getTopology();
$enabledDatabases = $config->getEnabledDatabases();
$isLocalInstall = $config->isLocal();
diff --git a/src/Appwrite/Platform/Installer/Runtime/Config.php b/src/Appwrite/Platform/Installer/Runtime/Config.php
index 7f478dae37..d87efbf99a 100644
--- a/src/Appwrite/Platform/Installer/Runtime/Config.php
+++ b/src/Appwrite/Platform/Installer/Runtime/Config.php
@@ -14,6 +14,7 @@ final class Config
'isLocal',
'hostPath',
'lockedDatabase',
+ 'topology',
'enabledDatabases',
'vars',
];
@@ -27,6 +28,7 @@ final class Config
private bool $isLocal = false;
private ?string $hostPath = null;
private ?string $lockedDatabase = null;
+ private ?string $topology = null;
private array $enabledDatabases = ['postgresql', 'mariadb', 'mongodb'];
private array $vars = [];
@@ -69,6 +71,9 @@ final class Config
if ($this->hasValidStringValue($values, 'lockedDatabase')) {
$this->setLockedDatabase((string) $values['lockedDatabase']);
}
+ if ($this->hasValidStringValue($values, 'topology')) {
+ $this->setTopology((string) $values['topology']);
+ }
if (array_key_exists('enabledDatabases', $values) && is_array($values['enabledDatabases'])) {
$this->setEnabledDatabases($values['enabledDatabases']);
}
@@ -105,6 +110,7 @@ final class Config
'isLocal' => $this->isLocal,
'hostPath' => $this->hostPath,
'lockedDatabase' => $this->lockedDatabase,
+ 'topology' => $this->getTopology(),
'enabledDatabases' => $this->enabledDatabases,
];
}
@@ -209,6 +215,23 @@ final class Config
$this->lockedDatabase = $value;
}
+ public function hasTopology(): bool
+ {
+ return $this->topology !== null;
+ }
+
+ public function getTopology(): string
+ {
+ return $this->topology ?? 'combined';
+ }
+
+ public function setTopology(string $value): void
+ {
+ $this->topology = \in_array($value, ['combined', 'separate'], true)
+ ? $value
+ : 'combined';
+ }
+
/**
* @return string[]
*/
diff --git a/src/Appwrite/Platform/Installer/Server.php b/src/Appwrite/Platform/Installer/Server.php
index 7e6eb6a162..8dd355d843 100644
--- a/src/Appwrite/Platform/Installer/Server.php
+++ b/src/Appwrite/Platform/Installer/Server.php
@@ -201,15 +201,11 @@ class Server
/**
* Auto-detect upgrade mode by checking for existing config files.
- * Sets isUpgrade and lockedDatabase on the config when an existing
- * installation is found and these values aren't already set.
+ * Sets isUpgrade, lockedDatabase, and topology on the config when an
+ * existing installation is found and these values aren't already set.
*/
private function autoDetectUpgrade(Config $config): void
{
- if ($config->isUpgrade()) {
- return;
- }
-
$basePath = $config->isLocal() ? '/usr/src/code' : (getcwd() ?: '.');
if ($config->isLocal()) {
$composePath = $basePath . '/' . self::LOCAL_COMPOSE_FILE;
@@ -223,16 +219,41 @@ class Server
return;
}
- $config->setIsUpgrade(true);
-
- if ($config->getLockedDatabase() !== null) {
- return;
+ if (!$config->isUpgrade()) {
+ $config->setIsUpgrade(true);
}
- $database = $this->detectDatabaseFromFiles($composePath, $envPath);
- if ($database !== null) {
- $config->setLockedDatabase($database);
+ if ($config->getLockedDatabase() === null) {
+ $database = $this->detectDatabaseFromFiles($composePath, $envPath);
+ if ($database !== null) {
+ $config->setLockedDatabase($database);
+ }
}
+
+ if (!$config->hasTopology()) {
+ $topology = $this->detectTopologyFromFiles($composePath);
+ if ($topology !== null) {
+ $config->setTopology($topology);
+ }
+ }
+ }
+
+ private function detectTopologyFromFiles(string $composePath): ?string
+ {
+ $composeData = @file_get_contents($composePath);
+ if ($composeData === false) {
+ return null;
+ }
+
+ if (preg_match('/^\s*appwrite-worker:\s*$/m', $composeData) === 1) {
+ return 'combined';
+ }
+
+ if (preg_match('/^\s*appwrite-worker-functions:\s*$/m', $composeData) === 1) {
+ return 'separate';
+ }
+
+ return null;
}
private function detectDatabaseFromFiles(string $composePath, string $envPath): ?string
diff --git a/src/Appwrite/Platform/Tasks/Install.php b/src/Appwrite/Platform/Tasks/Install.php
index 0f821711d9..3afc7c7bf0 100644
--- a/src/Appwrite/Platform/Tasks/Install.php
+++ b/src/Appwrite/Platform/Tasks/Install.php
@@ -361,6 +361,7 @@ class Install extends Action
'vars' => $vars,
'isUpgrade' => $isUpgrade,
'lockedDatabase' => $lockedDatabase,
+ 'topology' => $this->topology,
'enabledDatabases' => $enabledDatabases,
'isLocal' => $this->isLocalInstall(),
'hostPath' => $this->hostPath ?: null,
diff --git a/tests/unit/Platform/Modules/Installer/Http/Installer/ViewTest.php b/tests/unit/Platform/Modules/Installer/Http/Installer/ViewTest.php
index bcca6883ee..24caec8acf 100644
--- a/tests/unit/Platform/Modules/Installer/Http/Installer/ViewTest.php
+++ b/tests/unit/Platform/Modules/Installer/Http/Installer/ViewTest.php
@@ -49,11 +49,24 @@ final class ViewTest extends TestCase
$this->assertMatchesRegularExpression('/name="database" value="postgresql"[^>]*disabled/', $html);
}
+ public function testUpgradeWithDetectedSeparateTopologyPreselectsSeparate(): void
+ {
+ $html = $this->render([
+ 'isUpgrade' => true,
+ 'topology' => 'separate',
+ ]);
+
+ $this->assertStringContainsString('data-topology="separate"', $html);
+ $this->assertMatchesRegularExpression('/name="topology" value="separate"[^>]*checked/', $html);
+ $this->assertDoesNotMatchRegularExpression('/name="topology" value="combined"[^>]*checked/', $html);
+ }
+
private function render(array $values = []): string
{
$step = 1;
$isUpgrade = false;
$lockedDatabase = null;
+ $topology = 'combined';
$vars = [];
$enabledDatabases = ['postgresql', 'mariadb', 'mongodb'];
$csrfToken = 'test-token';
diff --git a/tests/unit/Platform/Modules/Installer/Runtime/ConfigTest.php b/tests/unit/Platform/Modules/Installer/Runtime/ConfigTest.php
index b6cb4e7ee5..064bc2da58 100644
--- a/tests/unit/Platform/Modules/Installer/Runtime/ConfigTest.php
+++ b/tests/unit/Platform/Modules/Installer/Runtime/ConfigTest.php
@@ -415,6 +415,7 @@ final class ConfigTest extends TestCase
'isLocal',
'hostPath',
'lockedDatabase',
+ 'topology',
'enabledDatabases',
];
@@ -439,6 +440,7 @@ final class ConfigTest extends TestCase
$this->assertFalse($array['isLocal']);
$this->assertNull($array['hostPath']);
$this->assertNull($array['lockedDatabase']);
+ $this->assertEquals('combined', $array['topology']);
$this->assertEquals(['postgresql', 'mariadb', 'mongodb'], $array['enabledDatabases']);
}