Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLOUDSTACK-8606: DB performance impacted due to VM sync. #553

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions engine/schema/src/com/cloud/upgrade/dao/Upgrade452to460.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;

Expand Down Expand Up @@ -59,6 +61,7 @@ public File[] getPrepareScripts() {
@Override
public void performDataMigration(final Connection conn) {
updateVMInstanceUserId(conn);
addIndexForVMInstance(conn);
}

public void updateVMInstanceUserId(final Connection conn) {
Expand Down Expand Up @@ -136,6 +139,22 @@ private void removeBumPriorityColumn(final Connection conn) {
}
}

private void addIndexForVMInstance(Connection conn) {
// Drop index if it exists
List<String> indexList = new ArrayList<String>();
s_logger.debug("Dropping index i_vm_instance__instance_name from vm_instance table if it exists");
indexList.add("i_vm_instance__instance_name");
DbUpgradeUtils.dropKeysIfExist(conn, "vm_instance", indexList, false);

// Now add index
try (PreparedStatement pstmt = conn.prepareStatement("ALTER TABLE `cloud`.`vm_instance` ADD INDEX `i_vm_instance__instance_name`(`instance_name`)");) {
pstmt.executeUpdate();
s_logger.debug("Added index i_vm_instance__instance_name to vm_instance table");
} catch (SQLException e) {
throw new CloudRuntimeException("Unable to add index i_vm_instance__instance_name to vm_instance table for the column instance_name", e);
}
}

@Override
public File[] getCleanupScripts() {
final String script = Script.findScript("", "db/schema-452to460-cleanup.sql");
Expand Down