Skip to content

Commit

Permalink
FINERACT-2181: Liquibase migrations are stuck when multi-threaded mig…
Browse files Browse the repository at this point in the history
…rations are enabled and one tenant migration fails
  • Loading branch information
galovics committed Mar 6, 2025
1 parent f8e5d6c commit 868ba54
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,16 +148,23 @@ private void upgradeIndividualTenants() {
}
}

List<Exception> exceptions = new ArrayList<>();
try {
for (Future<String> future : futures) {
future.get();
}
} catch (InterruptedException | ExecutionException exception) {
throw new RuntimeException(exception);
exceptions.add(exception);
} finally {
tenantUpgradeThreadPoolTaskExecutor.shutdown();
}
log.info("Tenant upgrades have finished");

if (exceptions.isEmpty()) {
log.info("Tenant upgrades have successfully finished");
} else {
exceptions.forEach(e -> log.error("Exception: ", e));
throw new RuntimeException("Tenant upgrades had exceptions");
}
}

private ThreadPoolTaskExecutor createTenantUpgradeThreadPoolTaskExecutor() {
Expand Down Expand Up @@ -193,6 +200,8 @@ private void upgradeIndividualTenant(FineractPlatformTenant tenant) throws Liqui
tenant.getTenantIdentifier());
tenantLiquibase.afterPropertiesSet();
log.info("Upgrade for tenant {} has finished", tenant.getTenantIdentifier());
} catch (Exception e) {
throw new RuntimeException("Exception while upgrading tenant " + tenant.getTenantIdentifier(), e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import org.apache.fineract.infrastructure.core.domain.FineractPlatformTenant;
import org.apache.fineract.infrastructure.core.service.migration.ExtendedSpringLiquibase;
import org.apache.fineract.infrastructure.core.service.migration.ExtendedSpringLiquibaseFactory;
import org.apache.fineract.infrastructure.core.service.migration.SchemaUpgradeNeededException;
import org.apache.fineract.infrastructure.core.service.migration.TenantDataSourceFactory;
import org.apache.fineract.infrastructure.core.service.migration.TenantDatabaseStateVerifier;
import org.apache.fineract.infrastructure.core.service.migration.TenantDatabaseUpgradeService;
Expand All @@ -66,7 +65,7 @@ public class LiquibaseStepDefinitions implements En {
private DataSource tenantStoreDataSource;
private TenantDatabaseUpgradeService tenantDatabaseUpgradeService;
private List<FineractPlatformTenant> allTenants;
private SchemaUpgradeNeededException executionException;
private RuntimeException executionException;
private HikariDataSource defaultTenantDataSource;
private Environment environment;

Expand Down Expand Up @@ -103,10 +102,8 @@ public LiquibaseStepDefinitions() {
When("The database migration process is executed", () -> {
try {
tenantDatabaseUpgradeService.afterPropertiesSet();
} catch (SchemaUpgradeNeededException e) {
executionException = e;
} catch (RuntimeException e) {
executionException = (SchemaUpgradeNeededException) e.getCause().getCause();
executionException = e;
}
});

Expand Down

0 comments on commit 868ba54

Please sign in to comment.