Skip to content

Commit 24d5c45

Browse files
authored
Add indexes for vm_stats (apache#8737)
* Add indexes for vm_stats * Remove index on timestamp * Chnage index from vm_id,timestamp to vm_id
1 parent 308ed13 commit 24d5c45

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

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

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

19+
import com.cloud.upgrade.SystemVmTemplateRegistration;
1920
import com.cloud.utils.exception.CloudRuntimeException;
21+
import org.apache.log4j.Logger;
2022

2123
import java.io.InputStream;
2224
import java.sql.Connection;
2325

24-
public class Upgrade41900to41910 implements DbUpgrade {
26+
public class Upgrade41900to41910 implements DbUpgrade, DbUpgradeSystemVmTemplate {
27+
final static Logger LOG = Logger.getLogger(Upgrade41900to41910.class);
28+
private SystemVmTemplateRegistration systemVmTemplateRegistration;
2529

2630
@Override
2731
public String[] getUpgradableVersionRange() {
28-
return new String[] {"4.19.0.0", "4.19.1.0"};
32+
return new String[]{"4.19.0.0", "4.19.1.0"};
2933
}
3034

3135
@Override
@@ -46,11 +50,12 @@ public InputStream[] getPrepareScripts() {
4650
throw new CloudRuntimeException("Unable to find " + scriptFile);
4751
}
4852

49-
return new InputStream[] {script};
53+
return new InputStream[]{script};
5054
}
5155

5256
@Override
5357
public void performDataMigration(Connection conn) {
58+
addIndexes(conn);
5459
}
5560

5661
@Override
@@ -61,6 +66,25 @@ public InputStream[] getCleanupScripts() {
6166
throw new CloudRuntimeException("Unable to find " + scriptFile);
6267
}
6368

64-
return new InputStream[] {script};
69+
return new InputStream[]{script};
70+
}
71+
72+
private void addIndexes(Connection conn) {
73+
DbUpgradeUtils.addIndexIfNeeded(conn, "vm_stats", "vm_id");
74+
}
75+
76+
@Override
77+
public void updateSystemVmTemplates(Connection conn) {
78+
LOG.debug("Updating System Vm template IDs");
79+
initSystemVmTemplateRegistration();
80+
try {
81+
systemVmTemplateRegistration.updateSystemVmTemplates(conn);
82+
} catch (Exception e) {
83+
throw new CloudRuntimeException("Failed to find / register SystemVM template(s)");
84+
}
85+
}
86+
87+
private void initSystemVmTemplateRegistration() {
88+
systemVmTemplateRegistration = new SystemVmTemplateRegistration("");
6589
}
6690
}

0 commit comments

Comments
 (0)