Skip to content

Commit 5ab6621

Browse files
committed
Add indexes for vm_stats
1 parent a7ec873 commit 5ab6621

File tree

4 files changed

+144
-0
lines changed

4 files changed

+144
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
import javax.inject.Inject;
3535

36+
import com.cloud.upgrade.dao.Upgrade41900to41910;
3637
import com.cloud.utils.FileUtil;
3738
import org.apache.cloudstack.utils.CloudStackVersion;
3839
import org.apache.commons.lang3.StringUtils;
@@ -224,6 +225,7 @@ public DatabaseUpgradeChecker() {
224225
.next("4.17.2.0", new Upgrade41720to41800())
225226
.next("4.18.0.0", new Upgrade41800to41810())
226227
.next("4.18.1.0", new Upgrade41810to41900())
228+
.next("4.19.0.0", new Upgrade41900to41910())
227229
.build();
228230
}
229231

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package com.cloud.upgrade.dao;
18+
19+
import com.cloud.upgrade.SystemVmTemplateRegistration;
20+
import com.cloud.utils.DateUtil;
21+
import com.cloud.utils.crypt.DBEncryptionUtil;
22+
import com.cloud.utils.exception.CloudRuntimeException;
23+
import org.apache.log4j.Logger;
24+
import org.jasypt.exceptions.EncryptionOperationNotPossibleException;
25+
26+
import java.io.InputStream;
27+
import java.sql.Connection;
28+
import java.sql.PreparedStatement;
29+
import java.sql.ResultSet;
30+
import java.sql.SQLException;
31+
import java.text.ParseException;
32+
import java.text.SimpleDateFormat;
33+
import java.util.Date;
34+
import java.util.HashMap;
35+
import java.util.Map;
36+
37+
public class Upgrade41900to41910 implements DbUpgrade, DbUpgradeSystemVmTemplate {
38+
final static Logger LOG = Logger.getLogger(Upgrade41900to41910.class);
39+
private SystemVmTemplateRegistration systemVmTemplateRegistration;
40+
41+
@Override
42+
public String[] getUpgradableVersionRange() {
43+
return new String[] {"4.19.0.0", "4.19.1.0"};
44+
}
45+
46+
@Override
47+
public String getUpgradedVersion() {
48+
return "4.19.1.0";
49+
}
50+
51+
@Override
52+
public boolean supportsRollingUpgrade() {
53+
return false;
54+
}
55+
56+
@Override
57+
public InputStream[] getPrepareScripts() {
58+
final String scriptFile = "META-INF/db/schema-41900to41910.sql";
59+
final InputStream script = Thread.currentThread().getContextClassLoader().getResourceAsStream(scriptFile);
60+
if (script == null) {
61+
throw new CloudRuntimeException("Unable to find " + scriptFile);
62+
}
63+
64+
return new InputStream[] {script};
65+
}
66+
67+
@Override
68+
public void performDataMigration(Connection conn) {
69+
addIndexes(conn);
70+
}
71+
72+
@Override
73+
public InputStream[] getCleanupScripts() {
74+
final String scriptFile = "META-INF/db/schema-41900to41910-cleanup.sql";
75+
final InputStream script = Thread.currentThread().getContextClassLoader().getResourceAsStream(scriptFile);
76+
if (script == null) {
77+
throw new CloudRuntimeException("Unable to find " + scriptFile);
78+
}
79+
80+
return new InputStream[] {script};
81+
}
82+
83+
private void initSystemVmTemplateRegistration() {
84+
systemVmTemplateRegistration = new SystemVmTemplateRegistration("");
85+
}
86+
87+
@Override
88+
public void updateSystemVmTemplates(Connection conn) {
89+
LOG.debug("Updating System Vm template IDs");
90+
initSystemVmTemplateRegistration();
91+
try {
92+
systemVmTemplateRegistration.updateSystemVmTemplates(conn);
93+
} catch (Exception e) {
94+
throw new CloudRuntimeException("Failed to find / register SystemVM template(s)");
95+
}
96+
}
97+
98+
private void addIndexes(Connection conn) {
99+
DbUpgradeUtils.addIndexIfNeeded(conn, "vm_stats", "vm_id", "timestamp");
100+
DbUpgradeUtils.addIndexIfNeeded(conn, "vm_stats", "timestamp");
101+
}
102+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
-- Licensed to the Apache Software Foundation (ASF) under one
2+
-- or more contributor license agreements. See the NOTICE file
3+
-- distributed with this work for additional information
4+
-- regarding copyright ownership. The ASF licenses this file
5+
-- to you under the Apache License, Version 2.0 (the
6+
-- "License"); you may not use this file except in compliance
7+
-- with the License. You may obtain a copy of the License at
8+
--
9+
-- http://www.apache.org/licenses/LICENSE-2.0
10+
--
11+
-- Unless required by applicable law or agreed to in writing,
12+
-- software distributed under the License is distributed on an
13+
-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
-- KIND, either express or implied. See the License for the
15+
-- specific language governing permissions and limitations
16+
-- under the License.
17+
18+
--;
19+
-- Schema upgrade cleanup from 4.19.0.0 to 4.19.1.0
20+
--;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
-- Licensed to the Apache Software Foundation (ASF) under one
2+
-- or more contributor license agreements. See the NOTICE file
3+
-- distributed with this work for additional information
4+
-- regarding copyright ownership. The ASF licenses this file
5+
-- to you under the Apache License, Version 2.0 (the
6+
-- "License"); you may not use this file except in compliance
7+
-- with the License. You may obtain a copy of the License at
8+
--
9+
-- http://www.apache.org/licenses/LICENSE-2.0
10+
--
11+
-- Unless required by applicable law or agreed to in writing,
12+
-- software distributed under the License is distributed on an
13+
-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
-- KIND, either express or implied. See the License for the
15+
-- specific language governing permissions and limitations
16+
-- under the License.
17+
18+
--;
19+
-- Schema upgrade from 4.19.0.0 to 4.19.1.0
20+
--;

0 commit comments

Comments
 (0)