From a971aaa39e2662604198e1ded384c0da27534fb1 Mon Sep 17 00:00:00 2001 From: alena Date: Wed, 24 Aug 2011 15:41:55 -0700 Subject: [PATCH] bug 11242: check if db object is already removed before generating the Debug log. It can happen in case when deleteHost command is called many times in parallel for the same host status 11242: resolved fixed --- .../src/com/cloud/host/dao/HostDaoImpl.java | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/server/src/com/cloud/host/dao/HostDaoImpl.java b/server/src/com/cloud/host/dao/HostDaoImpl.java index 8a6f9240738..5b23aa104f8 100755 --- a/server/src/com/cloud/host/dao/HostDaoImpl.java +++ b/server/src/com/cloud/host/dao/HostDaoImpl.java @@ -617,18 +617,26 @@ public class HostDaoImpl extends GenericDaoBase implements HostDao ub.set(host, _pingTimeAttr, ((System.currentTimeMillis() >> 10) - (10 * 60))); } int result = update(ub, sc, null); + assert result <= 1 : "How can this update " + result + " rows? "; + if (result < 1) { + s_logger.warn("Unable to update db record for host id=" + host.getId() + "; it's possible that the host is removed"); + } - if (s_logger.isDebugEnabled() && result == 0) { + if (s_logger.isDebugEnabled() && result == 1) { HostVO vo = findById(host.getId()); - assert vo != null : "How how how? : " + host.getId(); + + if (vo != null) { + StringBuilder str = new StringBuilder("Unable to update host for event:").append(event.toString()); + str.append(". New=[status=").append(newStatus.toString()).append(":msid=").append(newStatus.lostConnection() ? "null" : msId).append(":lastpinged=").append(host.getLastPinged()) + .append("]"); + str.append("; Old=[status=").append(oldStatus.toString()).append(":msid=").append(msId).append(":lastpinged=").append(oldPingTime).append("]"); + str.append("; DB=[status=").append(vo.getStatus().toString()).append(":msid=").append(vo.getManagementServerId()).append(":lastpinged=").append(vo.getLastPinged()).append("]"); + s_logger.debug(str.toString()); + } else { + s_logger.warn("Can't find host db record by id=" + host.getId() + "; host might be already marked as removed"); + } - StringBuilder str = new StringBuilder("Unable to update host for event:").append(event.toString()); - str.append(". New=[status=").append(newStatus.toString()).append(":msid=").append(newStatus.lostConnection() ? "null" : msId).append(":lastpinged=").append(host.getLastPinged()) - .append("]"); - str.append("; Old=[status=").append(oldStatus.toString()).append(":msid=").append(msId).append(":lastpinged=").append(oldPingTime).append("]"); - str.append("; DB=[status=").append(vo.getStatus().toString()).append(":msid=").append(vo.getManagementServerId()).append(":lastpinged=").append(vo.getLastPinged()).append("]"); - s_logger.debug(str.toString()); } return result > 0; }