From 0355c26f03ff91c2800923a9ad7b9fb5a36f1952 Mon Sep 17 00:00:00 2001 From: alena Date: Wed, 24 Aug 2011 15:48:18 -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 | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/server/src/com/cloud/host/dao/HostDaoImpl.java b/server/src/com/cloud/host/dao/HostDaoImpl.java index 891c4551854..988dfc4c231 100755 --- a/server/src/com/cloud/host/dao/HostDaoImpl.java +++ b/server/src/com/cloud/host/dao/HostDaoImpl.java @@ -634,20 +634,29 @@ 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; + } @Override