Skip to content

Commit c75ac2a

Browse files
author
Kishan Kavala
committed
CLOUDSTACK-4146, CLOUDSTACK-4147: Fix KVM snapshot upgrade.
when migrating KVM snapshot path, CONCAT is not required. back_snap_id is complete path for KVM snapshots
1 parent 281abef commit c75ac2a

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

engine/schema/src/com/cloud/upgrade/dao/Upgrade410to420.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,7 +1291,7 @@ private void fix22xKVMSnapshots(Connection conn) {
12911291
// Above path should change to /snapshots/1/2/6/i-2-6-VM_ROOT-6_20121219072022
12921292
int index = backUpPath.indexOf("snapshots"+File.separator);
12931293
if (index > 1){
1294-
String correctedPath = File.separator + backUpPath.substring(index);
1294+
String correctedPath = backUpPath.substring(index);
12951295
s_logger.debug("Updating Snapshot with id: "+id+" original backup path: "+backUpPath+ " updated backup path: "+correctedPath);
12961296
pstmt = conn.prepareStatement("UPDATE `cloud`.`snapshots` set backup_snap_id=? where id = ?");
12971297
pstmt.setString(1, correctedPath);
@@ -1958,10 +1958,17 @@ private void migrateSnapshotStoreRef(Connection conn) {
19581958

19591959
s_logger.debug("Updating snapshot_store_ref table from snapshots table");
19601960
try {
1961+
//Update all snapshots except KVM snapshots
19611962
snapshotStoreInsert = conn
1962-
.prepareStatement("INSERT INTO `cloud`.`snapshot_store_ref` (store_id, snapshot_id, created, size, parent_snapshot_id, install_path, volume_id, update_count, ref_cnt, store_role, state) select sechost_id, id, created, size, prev_snap_id, CONCAT('snapshots', '/', account_id, '/', volume_id, '/', backup_snap_id), volume_id, 0, 0, 'Image', 'Ready' from `cloud`.`snapshots` where status = 'BackedUp' and sechost_id is not null and removed is null");
1963+
.prepareStatement("INSERT INTO `cloud`.`snapshot_store_ref` (store_id, snapshot_id, created, size, parent_snapshot_id, install_path, volume_id, update_count, ref_cnt, store_role, state) select sechost_id, id, created, size, prev_snap_id, CONCAT('snapshots', '/', account_id, '/', volume_id, '/', backup_snap_id), volume_id, 0, 0, 'Image', 'Ready' from `cloud`.`snapshots` where status = 'BackedUp' and hypervisor_type <> 'KVM' and sechost_id is not null and removed is null");
19631964
int rowCount = snapshotStoreInsert.executeUpdate();
1964-
s_logger.debug("Insert modified " + rowCount + " rows");
1965+
s_logger.debug("Inserted " + rowCount + " snapshots into snapshot_store_ref");
1966+
1967+
//backsnap_id for KVM snapshots is complate path. CONCAT is not required
1968+
snapshotStoreInsert = conn
1969+
.prepareStatement("INSERT INTO `cloud`.`snapshot_store_ref` (store_id, snapshot_id, created, size, parent_snapshot_id, install_path, volume_id, update_count, ref_cnt, store_role, state) select sechost_id, id, created, size, prev_snap_id, backup_snap_id, volume_id, 0, 0, 'Image', 'Ready' from `cloud`.`snapshots` where status = 'BackedUp' and hypervisor_type = 'KVM' and sechost_id is not null and removed is null");
1970+
rowCount = snapshotStoreInsert.executeUpdate();
1971+
s_logger.debug("Inserted " + rowCount + " KVM snapshots into snapshot_store_ref");
19651972
}
19661973
catch (SQLException e) {
19671974
String msg = "Unable to migrate snapshot_store_ref." + e.getMessage();

0 commit comments

Comments
 (0)