bug 9493: fixed the bug in Basic zone when nic_count was updated incorrectly due to multiple domRs per network

status 9493: resolved fixed
This commit is contained in:
alena 2011-04-18 16:49:12 -07:00
parent 996d0edbc9
commit 7d0528d693
2 changed files with 62 additions and 5 deletions

View File

@ -474,7 +474,7 @@ public class Upgrade218to22 implements DbUpgrade {
insertNic(conn, networkId, (Long) vm[0], running, (String) vm[1], (String) vm[2], (String) vm[3], "Start", gateway, vnet, "ExternalGuestNetworkGuru", true, 0, "Dhcp", null);
}
pstmt = conn.prepareStatement("SELECT state FROm vm_instance WHERE id=?");
pstmt = conn.prepareStatement("SELECT state FROM vm_instance WHERE id=?");
pstmt.setLong(1, domainRouterId);
rs = pstmt.executeQuery();
rs.next();
@ -525,7 +525,10 @@ public class Upgrade218to22 implements DbUpgrade {
boolean running = false;
if (state.equals("Running") || state.equals("Starting") || state.equals("Stopping")) {
running = true;
count++;
String type = (String) vm[5];
if (type.equalsIgnoreCase("User")) {
count++;
}
}
insertNic(conn, networkId, (Long) vm[0], running, (String) vm[1], (String) vm[2], (String) vm[3], "Start", gateway, vnet, "DirectPodBasedNetworkGuru", true, 0, "Dhcp", null);
}
@ -541,8 +544,21 @@ public class Upgrade218to22 implements DbUpgrade {
rs.close();
pstmt.close();
Long originalNicsCount = 0L;
pstmt = conn.prepareStatement("SELECT nics_count from op_networks where id=?");
pstmt.setLong(1, networkId);
ResultSet originalCountRs = pstmt.executeQuery();
if (originalCountRs.next()) {
originalNicsCount = originalCountRs.getLong(1);
}
Long resultCount = originalNicsCount + count;
originalCountRs.close();
pstmt.close();
pstmt = conn.prepareStatement("UPDATE op_networks SET nics_count=?, check_for_gc=? WHERE id=?");
pstmt.setLong(1, count);
pstmt.setLong(1, resultCount);
if (count == 0) {
pstmt.setBoolean(2, false);
} else {
@ -1113,7 +1129,6 @@ public class Upgrade218to22 implements DbUpgrade {
pstmt = conn.prepareStatement("SELECT id from vm_instance where account_id=? AND data_center_id=? AND type='DomainRouter'");
pstmt.setLong(1, accountId);
pstmt.setLong(2, dataCenterId);
s_logger.debug("Query is " + pstmt);
ResultSet rs1 = pstmt.executeQuery();
if (!rs1.next()) {
@ -1137,7 +1152,6 @@ public class Upgrade218to22 implements DbUpgrade {
pstmt = conn.prepareStatement("UPDATE user_statistics SET device_id=? where id=?");
pstmt.setLong(1, deviceId);
pstmt.setLong(2, id);
s_logger.debug("Query is " + pstmt);
pstmt.executeUpdate();
pstmt = conn.prepareStatement("");

View File

@ -65,6 +65,7 @@ public class Upgrade222to224 implements DbUpgrade {
updateNicsWithMode(conn);
updateUserStatsWithNetwork(conn);
dropIndexIfExists(conn);
fixBasicZoneNicCount(conn);
}
@Override
@ -245,6 +246,48 @@ public class Upgrade222to224 implements DbUpgrade {
} catch (SQLException e) {
throw new CloudRuntimeException("Unable to drop 'path' index for 'domain' table due to:", e);
}
}
private void fixBasicZoneNicCount(Connection conn) {
try {
PreparedStatement pstmt = conn.prepareStatement("SELECT id from data_center where networktype='Basic'");
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
Long zoneId = rs.getLong(1);
Long networkId = null;
Long vmCount = 0L;
s_logger.debug("Updating basic zone id=" + zoneId + " with correct nic count");
pstmt = conn.prepareStatement("SELECT id from networks where data_center_id=? AND guest_type='Direct'");
pstmt.setLong(1, zoneId);
rs = pstmt.executeQuery();
if (rs.next()) {
networkId = rs.getLong(1);
} else {
continue;
}
pstmt = conn.prepareStatement("SELECT count(*) from vm_instance where name like 'i-%' and (state='Running' or state='Starting' or state='Stopping')");
rs = pstmt.executeQuery();
if (rs.next()) {
vmCount = rs.getLong(1);
}
pstmt = conn.prepareStatement("UPDATE op_networks set nics_count=? where id=?");
pstmt.setLong(1, vmCount);
pstmt.setLong(2, networkId);
pstmt.executeUpdate();
}
s_logger.debug("Basic zones are updated with correct nic counts successfully");
rs.close();
pstmt.close();
} catch (SQLException e) {
throw new CloudRuntimeException("Unable to drop 'path' index for 'domain' table due to:", e);
}
}
}