bug 11217: add db upgrade script, if sechost_id is missing of a snapshot, add one got from presnapshot_id

status 11217: resovled fixed

Conflicts:

	server/src/com/cloud/upgrade/dao/Upgrade229to2210.java
This commit is contained in:
Edison Su 2011-08-29 15:27:53 -07:00
parent 41be3716e3
commit 60cbef1fb8

View File

@ -60,13 +60,52 @@ public class Upgrade229to2210 implements DbUpgrade {
@Override
public void performDataMigration(Connection conn) {
updateFirewallRules(conn);
updateSnapshots(conn);
}
@Override
public File[] getCleanupScripts() {
return null;
}
private void updateSnapshots(Connection conn) {
PreparedStatement pstmt = null;
ResultSet rs = null;
long currentSnapshotId = 0;
try {
pstmt = conn.prepareStatement("select id, prev_snap_id from snapshots where sechost_id is NULL and prev_snap_id is not NULL order by id");
rs = pstmt.executeQuery();
while (rs.next()) {
long id = rs.getLong(1);
long preSnapId = rs.getLong(2);
currentSnapshotId = id;
pstmt = conn.prepareStatement("select sechost_id from snapshots where id=? and sechost_id is not NULL");
pstmt.setLong(1, preSnapId);
ResultSet sechost = pstmt.executeQuery();
if (sechost.next()) {
long secHostId = sechost.getLong(1);
pstmt = conn.prepareStatement("update snapshots set sechost_id=? where id=?");
pstmt.setLong(1, secHostId);
pstmt.setLong(2, id);
pstmt.executeUpdate();
}
}
} catch (SQLException e) {
throw new CloudRuntimeException("Unable to update snapshots id=" + currentSnapshotId, e);
} finally {
try {
if (rs != null) {
rs.close();
}
if (pstmt != null) {
pstmt.close();
}
} catch (SQLException e) {
}
}
}
private void updateFirewallRules(Connection conn) {
PreparedStatement pstmt = null;
ResultSet rs = null;