Select lifecycle-manager based on environment variable (like in FoundationDbClusterExtension)
Some checks are pending
Update Documentation / build (push) Waiting to run
Service CI / build (push) Waiting to run

This commit is contained in:
Ravi Khadiwala 2026-06-25 15:08:23 -05:00 committed by Jon Chambers
parent 2abf55e395
commit aa5ac70ad3
3 changed files with 14 additions and 10 deletions

View File

@ -10,27 +10,31 @@ import com.apple.foundationdb.FDB;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonTypeName; import com.fasterxml.jackson.annotation.JsonTypeName;
import java.io.IOException; import java.io.IOException;
import org.whispersystems.textsecuregcm.storage.FoundationDbDatabaseLifecycleManager;
import org.whispersystems.textsecuregcm.storage.ServiceContainerFoundationDbDatabaseLifecycleManager;
import org.whispersystems.textsecuregcm.storage.TestcontainersFoundationDbDatabaseLifecycleManager; import org.whispersystems.textsecuregcm.storage.TestcontainersFoundationDbDatabaseLifecycleManager;
@JsonTypeName("local") @JsonTypeName("local")
public class LocalFoundationDbDatabaseFactory implements FoundationDbDatabaseFactory { public class LocalFoundationDbDatabaseFactory implements FoundationDbDatabaseFactory {
@JsonIgnore
private final TestcontainersFoundationDbDatabaseLifecycleManager testcontainersFoundationDbDatabaseLifecycleManager;
@JsonIgnore @JsonIgnore
private Database database; private Database database;
private LocalFoundationDbDatabaseFactory() { private LocalFoundationDbDatabaseFactory() {
this.testcontainersFoundationDbDatabaseLifecycleManager = new TestcontainersFoundationDbDatabaseLifecycleManager();
} }
@Override @Override
public synchronized Database build(final FDB fdb) throws IOException { public synchronized Database build(final FDB fdb) throws IOException {
if (database == null) { if (database == null) {
Runtime.getRuntime().addShutdownHook(new Thread(testcontainersFoundationDbDatabaseLifecycleManager::closeDatabase)); final String serviceContainerNamePrefix = System.getProperty("foundationDb.serviceContainerNamePrefix");
testcontainersFoundationDbDatabaseLifecycleManager.initializeDatabase(fdb);
database = testcontainersFoundationDbDatabaseLifecycleManager.getDatabase(); final FoundationDbDatabaseLifecycleManager lifecycleManager = serviceContainerNamePrefix != null
? new ServiceContainerFoundationDbDatabaseLifecycleManager(serviceContainerNamePrefix + "0")
: new TestcontainersFoundationDbDatabaseLifecycleManager();
Runtime.getRuntime().addShutdownHook(new Thread(lifecycleManager::closeDatabase));
lifecycleManager.initializeDatabase(fdb);
database = lifecycleManager.getDatabase();
} }
return database; return database;

View File

@ -9,7 +9,7 @@ import com.apple.foundationdb.Database;
import com.apple.foundationdb.FDB; import com.apple.foundationdb.FDB;
import java.io.IOException; import java.io.IOException;
interface FoundationDbDatabaseLifecycleManager { public interface FoundationDbDatabaseLifecycleManager {
void initializeDatabase(final FDB fdb) throws IOException; void initializeDatabase(final FDB fdb) throws IOException;

View File

@ -16,7 +16,7 @@ import org.slf4j.LoggerFactory;
/** /**
* Manages the lifecycle of a database connected to a FoundationDB instance running as an external service container. * Manages the lifecycle of a database connected to a FoundationDB instance running as an external service container.
*/ */
class ServiceContainerFoundationDbDatabaseLifecycleManager implements FoundationDbDatabaseLifecycleManager { public class ServiceContainerFoundationDbDatabaseLifecycleManager implements FoundationDbDatabaseLifecycleManager {
private final String foundationDbServiceContainerName; private final String foundationDbServiceContainerName;
@ -24,7 +24,7 @@ class ServiceContainerFoundationDbDatabaseLifecycleManager implements Foundation
private static final Logger log = LoggerFactory.getLogger(ServiceContainerFoundationDbDatabaseLifecycleManager.class); private static final Logger log = LoggerFactory.getLogger(ServiceContainerFoundationDbDatabaseLifecycleManager.class);
ServiceContainerFoundationDbDatabaseLifecycleManager(final String foundationDbServiceContainerName) { public ServiceContainerFoundationDbDatabaseLifecycleManager(final String foundationDbServiceContainerName) {
log.info("Using FoundationDB service container: {}", foundationDbServiceContainerName); log.info("Using FoundationDB service container: {}", foundationDbServiceContainerName);
this.foundationDbServiceContainerName = foundationDbServiceContainerName; this.foundationDbServiceContainerName = foundationDbServiceContainerName;
} }