Skip to content
Closed
Show file tree
Hide file tree
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
23 changes: 11 additions & 12 deletions engine/schema/src/com/cloud/dc/dao/DataCenterIpAddressDaoImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ public void addIpRange(long dcId, long podId, String start, String end) {
String insertSql = "INSERT INTO `cloud`.`op_dc_ip_address_alloc` (ip_address, data_center_id, pod_id, mac_address) " +
"VALUES (?, ?, ?, (select mac_address from `cloud`.`data_center` where id=?))";
String updateSql = "UPDATE `cloud`.`data_center` set mac_address = mac_address+1 where id=?";
PreparedStatement stmt = null;

long startIP = NetUtils.ip2Long(start);
long endIP = NetUtils.ip2Long(end);
Expand All @@ -125,17 +124,17 @@ public void addIpRange(long dcId, long podId, String start, String end) {
txn.start();

while (startIP <= endIP) {
stmt = txn.prepareStatement(insertSql);
stmt.setString(1, NetUtils.long2Ip(startIP++));
stmt.setLong(2, dcId);
stmt.setLong(3, podId);
stmt.setLong(4, dcId);
stmt.executeUpdate();
stmt.close();
stmt = txn.prepareStatement(updateSql);
stmt.setLong(1, dcId);
stmt.executeUpdate();
stmt.close();
try(PreparedStatement insertPstmt = txn.prepareStatement(insertSql);) {
insertPstmt.setString(1, NetUtils.long2Ip(startIP++));
insertPstmt.setLong(2, dcId);
insertPstmt.setLong(3, podId);
insertPstmt.setLong(4, dcId);
insertPstmt.executeUpdate();
}
try(PreparedStatement updatePstmt = txn.prepareStatement(updateSql);) {
updatePstmt.setLong(1, dcId);
updatePstmt.executeUpdate();
}
}
txn.commit();
} catch (SQLException ex) {
Expand Down
31 changes: 10 additions & 21 deletions engine/schema/src/com/cloud/host/dao/HostDaoImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -740,32 +740,21 @@ public void loadHostTags(HostVO host) {
@DB
@Override
public List<HostVO> findLostHosts(long timeout) {
TransactionLegacy txn = TransactionLegacy.currentTxn();
PreparedStatement pstmt = null;
List<HostVO> result = new ArrayList<HostVO>();
ResultSet rs = null;
try {
String sql =
String sql =
"select h.id from host h left join cluster c on h.cluster_id=c.id where h.mgmt_server_id is not null and h.last_ping < ? and h.status in ('Up', 'Updating', 'Disconnected', 'Connecting') and h.type not in ('ExternalFirewall', 'ExternalLoadBalancer', 'TrafficMonitor', 'SecondaryStorage', 'LocalSecondaryStorage', 'L2Networking') and (h.cluster_id is null or c.managed_state = 'Managed') ;";
pstmt = txn.prepareStatement(sql);
try (
TransactionLegacy txn = TransactionLegacy.currentTxn();
PreparedStatement pstmt = txn.prepareStatement(sql);) {
pstmt.setLong(1, timeout);
rs = pstmt.executeQuery();
while (rs.next()) {
long id = rs.getLong(1); //ID column
result.add(findById(id));
}
} catch (Exception e) {
s_logger.warn("Exception: ", e);
} finally {
try {
if (rs != null) {
rs.close();
}
if (pstmt != null) {
pstmt.close();
try (ResultSet rs = pstmt.executeQuery();) {
while (rs.next()) {
long id = rs.getLong(1); //ID column
result.add(findById(id));
}
} catch (SQLException e) {
}
} catch (SQLException e) {
s_logger.warn("Exception: ", e);
}
return result;
}
Expand Down
10 changes: 9 additions & 1 deletion framework/db/src/com/cloud/utils/db/Merovingian2.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,15 @@ private Merovingian2(long msId) {
_concierge = new ConnectionConcierge("LockMaster", conn, true);
} catch (SQLException e) {
s_logger.error("Unable to get a new db connection", e);
throw new CloudRuntimeException("Unable to initialize a connection to the database for locking purposes: ", e);
throw new CloudRuntimeException("Unable to initialize a connection to the database for locking purposes", e);
} finally {
if (_concierge == null && conn != null) {
try {
conn.close();
} catch (SQLException e) {
s_logger.debug("closing connection failed after everything else.", e);
}
}
}
}

Expand Down