diff --git a/engine/schema/src/main/java/com/cloud/upgrade/DatabaseUpgradeChecker.java b/engine/schema/src/main/java/com/cloud/upgrade/DatabaseUpgradeChecker.java index 1e3b3a7e5ece..827b8f547574 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/DatabaseUpgradeChecker.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/DatabaseUpgradeChecker.java @@ -379,6 +379,9 @@ private VersionVO executeUpgrade(DbUpgrade upgrade) { } finally { txn.close(); } + if (upgrade.refreshPoolConnectionsAfterUpgrade()) { + TransactionLegacy.refreshConnections(TransactionLegacy.CLOUD_DB); + } return version; } diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/DbUpgrade.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/DbUpgrade.java index 02c401c81558..6001f940b2cf 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/DbUpgrade.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/DbUpgrade.java @@ -38,4 +38,8 @@ public interface DbUpgrade { void performDataMigration(Connection conn); InputStream[] getCleanupScripts(); + + default boolean refreshPoolConnectionsAfterUpgrade() { + return false; + } } diff --git a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade42010to42100.java b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade42010to42100.java index fd52782e57cb..786ee5afbc8e 100644 --- a/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade42010to42100.java +++ b/engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade42010to42100.java @@ -16,10 +16,6 @@ // under the License. package com.cloud.upgrade.dao; -import com.cloud.upgrade.SystemVmTemplateRegistration; -import com.cloud.utils.db.TransactionLegacy; -import com.cloud.utils.exception.CloudRuntimeException; - import java.io.InputStream; import java.sql.Connection; import java.sql.PreparedStatement; @@ -32,6 +28,10 @@ import org.apache.cloudstack.framework.config.ConfigKey; +import com.cloud.upgrade.SystemVmTemplateRegistration; +import com.cloud.utils.db.TransactionLegacy; +import com.cloud.utils.exception.CloudRuntimeException; + public class Upgrade42010to42100 extends DbUpgradeAbstractImpl implements DbUpgrade, DbUpgradeSystemVmTemplate { private SystemVmTemplateRegistration systemVmTemplateRegistration; @@ -212,4 +212,9 @@ protected void migrateExistingConfigurationScopeValues(Connection conn) { throw new CloudRuntimeException(String.format("Failed to migrate existing configuration scope values to bitmask due to: %s", e.getMessage())); } } + + @Override + public boolean refreshPoolConnectionsAfterUpgrade() { + return true; + } } diff --git a/framework/config/src/test/java/org/apache/cloudstack/framework/config/impl/ConfigDepotImplTest.java b/framework/config/src/test/java/org/apache/cloudstack/framework/config/impl/ConfigDepotImplTest.java index a6e62902e15c..f4012b43fa8d 100644 --- a/framework/config/src/test/java/org/apache/cloudstack/framework/config/impl/ConfigDepotImplTest.java +++ b/framework/config/src/test/java/org/apache/cloudstack/framework/config/impl/ConfigDepotImplTest.java @@ -107,7 +107,6 @@ private void runTestGetConfigStringValueExpiry(long wait, int configDBRetrieval) String result = configDepotImpl.getConfigStringValue(key, ConfigKey.Scope.Global, null); Assert.assertEquals(value, result); Mockito.verify(_configDao, Mockito.times(configDBRetrieval)).findById(key); - } @Test diff --git a/framework/db/src/main/java/com/cloud/utils/db/TransactionLegacy.java b/framework/db/src/main/java/com/cloud/utils/db/TransactionLegacy.java index 88af397c06a9..18a90749e49c 100644 --- a/framework/db/src/main/java/com/cloud/utils/db/TransactionLegacy.java +++ b/framework/db/src/main/java/com/cloud/utils/db/TransactionLegacy.java @@ -605,6 +605,15 @@ public Connection getConnection() throws SQLException { return _conn; } + public static void refreshConnections(final short dbId) { + if (dbId != CLOUD_DB) { + return; + } + if (s_ds instanceof HikariDataSource) { + ((HikariDataSource)s_ds).getHikariPoolMXBean().softEvictConnections(); + } + } + protected boolean takeOver(final String name, final boolean create) { if (_stack.size() != 0) { if (!create) {