Skip to content

Commit

Permalink
migration: Don't keep MigrationService in memory
Browse files Browse the repository at this point in the history
The MigrationService isn't needed anymore after the data directory has
been migrated. This change removes the ApplicationService's reference to
the MigrationService after it has run.
  • Loading branch information
alvasw committed Nov 4, 2024
1 parent b397b76 commit e1b4e49
Show file tree
Hide file tree
Showing 14 changed files with 28 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import bisq.common.logging.AsciiLogo;
import bisq.common.logging.LogSetup;
import bisq.common.util.ExceptionUtil;
import bisq.application.migration.MigrationService;
import bisq.i18n.Res;
import bisq.persistence.PersistenceService;
import com.typesafe.config.ConfigFactory;
Expand Down Expand Up @@ -122,6 +123,7 @@ public Config(Path baseDir,
protected final Config config;
@Getter
protected final PersistenceService persistenceService;
private Optional<MigrationService> migrationService;
private FileLock instanceLock;

public ApplicationService(String configFileName, String[] args, Path userDataDir) {
Expand Down Expand Up @@ -178,6 +180,7 @@ public ApplicationService(String configFileName, String[] args, Path userDataDir

String absoluteDataDirPath = dataDir.toAbsolutePath().toString();
persistenceService = new PersistenceService(absoluteDataDirPath);
migrationService = Optional.of(new MigrationService(dataDir));
}

private void checkInstanceLock() {
Expand All @@ -204,7 +207,11 @@ public CompletableFuture<Boolean> readAllPersisted() {
return persistenceService.readAllPersisted();
}

public abstract CompletableFuture<Boolean> initialize();
public CompletableFuture<Boolean> initialize() {
CompletableFuture<Boolean> completableFuture = migrationService.orElseThrow().initialize();
migrationService = Optional.empty();
return completableFuture;
}

public abstract CompletableFuture<Boolean> shutdown();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package bisq.evolution.migration;
package bisq.application.migration;

import bisq.application.migration.migrations.Migration;
import bisq.application.migration.migrations.MigrationsForV2_1_2;
import bisq.common.application.ApplicationVersion;
import bisq.common.application.Service;
import bisq.common.platform.Version;
import bisq.evolution.migration.migrations.Migration;
import bisq.evolution.migration.migrations.MigrationsForV2_1_2;

import java.io.File;
import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package bisq.evolution.migration;
package bisq.application.migration;

import bisq.common.application.ApplicationVersion;
import bisq.common.platform.Version;
import bisq.evolution.migration.migrations.Migration;
import bisq.evolution.migration.migrations.MigrationFailedException;
import bisq.application.migration.migrations.Migration;
import bisq.application.migration.migrations.MigrationFailedException;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package bisq.evolution.migration.migrations;
package bisq.application.migration.migrations;

import bisq.common.platform.Version;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package bisq.evolution.migration.migrations;
package bisq.application.migration.migrations;

public class MigrationFailedException extends RuntimeException {
public MigrationFailedException(String message) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package bisq.evolution.migration.migrations;
package bisq.application.migration.migrations;

import bisq.common.file.FileUtils;
import bisq.common.platform.OS;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package bisq.evolution.migration;
package bisq.application.migration;

import bisq.application.migration.MigrationService;
import bisq.common.platform.InvalidVersionException;
import bisq.common.platform.Version;
import org.junit.jupiter.api.Test;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package bisq.evolution.migration;
package bisq.application.migration;

import bisq.application.migration.migrations.Migration;
import bisq.application.migration.migrations.MigrationFailedException;
import bisq.common.application.ApplicationVersion;
import bisq.common.platform.Version;
import bisq.evolution.migration.migrations.Migration;
import bisq.evolution.migration.migrations.MigrationFailedException;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package bisq.evolution.migration.migrations;
package bisq.application.migration.migrations;

import bisq.application.migration.migrations.MigrationsForV2_1_2;
import bisq.common.platform.Version;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledOnOs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,7 @@ private Optional<OsSpecificNotificationService> findSystemNotificationDelegate()

@Override
public CompletableFuture<Boolean> initialize() {
return migrationService.initialize()
.thenCompose(result -> memoryReportService.initialize())
return memoryReportService.initialize()
.thenCompose(result -> securityService.initialize())
.thenCompose(result -> {
setState(State.INITIALIZE_NETWORK);
Expand Down Expand Up @@ -338,7 +337,6 @@ public CompletableFuture<Boolean> shutdown() {
.orElse(CompletableFuture.completedFuture(true)))
.thenCompose(result -> securityService.shutdown().exceptionally(this::logError))
.thenCompose(result -> memoryReportService.shutdown().exceptionally(this::logError))
.thenCompose(result -> migrationService.shutdown().exceptionally(this::logError))
.orTimeout(SHUTDOWN_TIMEOUT_SEC, TimeUnit.SECONDS)
.handle((result, throwable) -> {
if (throwable == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ public OracleNodeApplicationService(String[] args) {

@Override
public CompletableFuture<Boolean> initialize() {
return migrationService.initialize()
.thenCompose(result -> memoryReportService.initialize())
return memoryReportService.initialize()
.thenCompose(result -> securityService.initialize())
.thenCompose(result -> networkService.initialize())
.thenCompose(result -> identityService.initialize())
Expand All @@ -110,7 +109,6 @@ public CompletableFuture<Boolean> shutdown() {
.thenCompose(result -> networkService.shutdown())
.thenCompose(result -> securityService.shutdown())
.thenCompose(result -> memoryReportService.shutdown())
.thenCompose(result -> migrationService.shutdown())
.orTimeout(2, TimeUnit.MINUTES)
.handle((result, throwable) -> throwable == null)
.join());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,7 @@ public RestApiApplicationService(String[] args) {

@Override
public CompletableFuture<Boolean> initialize() {
return migrationService.initialize()
.thenCompose(result -> memoryReportService.initialize())
return memoryReportService.initialize()
.thenCompose(result -> securityService.initialize())
.thenCompose(result -> {
setState(State.INITIALIZE_NETWORK);
Expand Down Expand Up @@ -255,7 +254,6 @@ public CompletableFuture<Boolean> shutdown() {
.orElse(CompletableFuture.completedFuture(true)))
.thenCompose(result -> securityService.shutdown())
.thenCompose(result -> memoryReportService.shutdown())
.thenCompose(result -> migrationService.shutdown())
.orTimeout(10, TimeUnit.SECONDS)
.handle((result, throwable) -> throwable == null)
.join());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ public SeedNodeApplicationService(String[] args) {

@Override
public CompletableFuture<Boolean> initialize() {
return migrationService.initialize()
.thenCompose(result -> memoryReportService.initialize())
return memoryReportService.initialize()
.thenCompose(result -> securityService.initialize())
.thenCompose(result -> networkService.initialize())
.thenCompose(result -> identityService.initialize())
Expand Down Expand Up @@ -105,7 +104,6 @@ public CompletableFuture<Boolean> shutdown() {
.thenCompose(result -> networkService.shutdown())
.thenCompose(result -> securityService.shutdown())
.thenCompose(result -> memoryReportService.shutdown())
.thenCompose(result -> migrationService.shutdown())
.orTimeout(10, TimeUnit.SECONDS)
.handle((result, throwable) -> {
if (throwable != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import bisq.common.facades.FacadeProvider;
import bisq.common.platform.MemoryReportService;
import bisq.common.platform.PlatformUtils;
import bisq.evolution.migration.MigrationService;
import bisq.java_se.facades.JavaSeGuavaFacade;
import bisq.java_se.facades.JavaSeJdkFacade;
import bisq.java_se.jvm.JvmMemoryReportService;
Expand All @@ -31,7 +30,6 @@
@Getter
@Slf4j
public abstract class JavaSeApplicationService extends ApplicationService {
protected final MigrationService migrationService;
protected final MemoryReportService memoryReportService;

public JavaSeApplicationService(String configFileName, String[] args) {
Expand All @@ -43,7 +41,6 @@ public JavaSeApplicationService(String configFileName, String[] args) {
FacadeProvider.setGuavaFacade(new JavaSeGuavaFacade());
FacadeProvider.setJdkFacade(new JavaSeJdkFacade());

migrationService = new MigrationService(getConfig().getBaseDir());
memoryReportService = new JvmMemoryReportService(getConfig().getMemoryReportIntervalSec(), getConfig().isIncludeThreadListInMemoryReport());
}
}

0 comments on commit e1b4e49

Please sign in to comment.