Skip to content

Commit 9fd2b90

Browse files
authored
Fix ConfigurationVO load exception after schema change (#10485)
1 parent 96728c5 commit 9fd2b90

File tree

5 files changed

+25
-5
lines changed

5 files changed

+25
-5
lines changed

engine/schema/src/main/java/com/cloud/upgrade/DatabaseUpgradeChecker.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,9 @@ private VersionVO executeUpgrade(DbUpgrade upgrade) {
379379
} finally {
380380
txn.close();
381381
}
382+
if (upgrade.refreshPoolConnectionsAfterUpgrade()) {
383+
TransactionLegacy.refreshConnections(TransactionLegacy.CLOUD_DB);
384+
}
382385
return version;
383386
}
384387

engine/schema/src/main/java/com/cloud/upgrade/dao/DbUpgrade.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,8 @@ public interface DbUpgrade {
3838
void performDataMigration(Connection conn);
3939

4040
InputStream[] getCleanupScripts();
41+
42+
default boolean refreshPoolConnectionsAfterUpgrade() {
43+
return false;
44+
}
4145
}

engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade42010to42100.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@
1616
// under the License.
1717
package com.cloud.upgrade.dao;
1818

19-
import com.cloud.upgrade.SystemVmTemplateRegistration;
20-
import com.cloud.utils.db.TransactionLegacy;
21-
import com.cloud.utils.exception.CloudRuntimeException;
22-
2319
import java.io.InputStream;
2420
import java.sql.Connection;
2521
import java.sql.PreparedStatement;
@@ -32,6 +28,10 @@
3228

3329
import org.apache.cloudstack.framework.config.ConfigKey;
3430

31+
import com.cloud.upgrade.SystemVmTemplateRegistration;
32+
import com.cloud.utils.db.TransactionLegacy;
33+
import com.cloud.utils.exception.CloudRuntimeException;
34+
3535
public class Upgrade42010to42100 extends DbUpgradeAbstractImpl implements DbUpgrade, DbUpgradeSystemVmTemplate {
3636
private SystemVmTemplateRegistration systemVmTemplateRegistration;
3737

@@ -212,4 +212,9 @@ protected void migrateExistingConfigurationScopeValues(Connection conn) {
212212
throw new CloudRuntimeException(String.format("Failed to migrate existing configuration scope values to bitmask due to: %s", e.getMessage()));
213213
}
214214
}
215+
216+
@Override
217+
public boolean refreshPoolConnectionsAfterUpgrade() {
218+
return true;
219+
}
215220
}

framework/config/src/test/java/org/apache/cloudstack/framework/config/impl/ConfigDepotImplTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ private void runTestGetConfigStringValueExpiry(long wait, int configDBRetrieval)
107107
String result = configDepotImpl.getConfigStringValue(key, ConfigKey.Scope.Global, null);
108108
Assert.assertEquals(value, result);
109109
Mockito.verify(_configDao, Mockito.times(configDBRetrieval)).findById(key);
110-
111110
}
112111

113112
@Test

framework/db/src/main/java/com/cloud/utils/db/TransactionLegacy.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,15 @@ public Connection getConnection() throws SQLException {
605605
return _conn;
606606
}
607607

608+
public static void refreshConnections(final short dbId) {
609+
if (dbId != CLOUD_DB) {
610+
return;
611+
}
612+
if (s_ds instanceof HikariDataSource) {
613+
((HikariDataSource)s_ds).getHikariPoolMXBean().softEvictConnections();
614+
}
615+
}
616+
608617
protected boolean takeOver(final String name, final boolean create) {
609618
if (_stack.size() != 0) {
610619
if (!create) {

0 commit comments

Comments
 (0)