Skip to content

Commit 1883afe

Browse files
author
frank
committed
Bug 11522 - New agent manager
add update count into host table in order to make agent status update atomic
1 parent 30f95e6 commit 1883afe

3 files changed

Lines changed: 28 additions & 10 deletions

File tree

core/src/com/cloud/host/HostVO.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ public class HostVO implements Host {
134134

135135
@Column(name="hypervisor_version")
136136
private String hypervisorVersion;
137+
138+
@Column(name="update_count", updatable = true, nullable=false)
139+
protected long updated; // This field should be updated everytime the state is updated. There's no set method in the vo object because it is done with in the dao code.
137140

138141
// This is a delayed load value. If the value is null,
139142
// then this field has not been loaded yet.
@@ -705,5 +708,14 @@ public void setResourceState(ResourceState state) {
705708
public boolean isInMaintenanceStates() {
706709
return (getResourceState() == ResourceState.Maintenance || getResourceState() == ResourceState.ErrorInMaintenance
707710
|| getResourceState() == ResourceState.PrepareForMaintenance);
708-
}
711+
}
712+
713+
public long getUpdated() {
714+
return updated;
715+
}
716+
717+
public long incrUpdated() {
718+
updated++;
719+
return updated;
720+
}
709721
}

server/src/com/cloud/host/dao/HostDaoImpl.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,7 @@ public boolean updateState(Status oldStatus, Event event, Status newStatus, Host
591591
SearchBuilder<HostVO> sb = createSearchBuilder();
592592
sb.and("status", sb.entity().getStatus(), SearchCriteria.Op.EQ);
593593
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
594+
sb.and("update", sb.entity().getUpdated(), SearchCriteria.Op.EQ);
594595
if (newStatus.checkManagementServer()) {
595596
sb.and("ping", sb.entity().getLastPinged(), SearchCriteria.Op.EQ);
596597
sb.and().op("nullmsid", sb.entity().getManagementServerId(), SearchCriteria.Op.NULL);
@@ -603,11 +604,14 @@ public boolean updateState(Status oldStatus, Event event, Status newStatus, Host
603604

604605
sc.setParameters("status", oldStatus);
605606
sc.setParameters("id", host.getId());
607+
sc.setParameters("update", host.getUpdated());
608+
long oldUpdateCount = host.getUpdated();
606609
if (newStatus.checkManagementServer()) {
607610
sc.setParameters("ping", oldPingTime);
608611
sc.setParameters("msid", host.getManagementServerId());
609612
}
610613

614+
long newUpdateCount = host.incrUpdated();
611615
UpdateBuilder ub = getUpdateBuilder(host);
612616
ub.set(host, _statusAttr, newStatus);
613617
if (newStatus.updateManagementServer()) {
@@ -636,17 +640,19 @@ public boolean updateState(Status oldStatus, Event event, Status newStatus, Host
636640
str.append("; Old=[status=").append(oldStatus.toString()).append(":msid=").append(host.getManagementServerId()).append(":lastpinged=")
637641
.append(oldPingTime).append("]");
638642
str.append("; DB=[status=").append(vo.getStatus().toString()).append(":msid=").append(vo.getManagementServerId()).append(":lastpinged=")
639-
.append(vo.getLastPinged()).append("]");
643+
.append(vo.getLastPinged()).append(":old update count=").append(oldUpdateCount).append("]");
640644
status_logger.debug(str.toString());
645+
} else {
646+
StringBuilder msg = new StringBuilder("Agent status update: [");
647+
msg.append("hostId = " + host.getId());
648+
msg.append("; old status = " + oldStatus);
649+
msg.append("; event = " + event);
650+
msg.append("; new status = " + newStatus);
651+
msg.append("; old update count = " + oldUpdateCount);
652+
msg.append("; new update count = " + newUpdateCount + "]");
653+
status_logger.debug(msg.toString());
641654
}
642655

643-
StringBuilder msg = new StringBuilder("Agent status update: [");
644-
msg.append("hostId = " + host.getId());
645-
msg.append("; old status = " + oldStatus);
646-
msg.append("; event = " + event);
647-
msg.append("; new status = " + newStatus + "]");
648-
status_logger.debug(msg.toString());
649-
650656
return result > 0;
651657
}
652658

setup/db/create-schema.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ CREATE TABLE `cloud`.`host` (
698698
`disconnected` datetime COMMENT 'Time this was disconnected',
699699
`created` datetime COMMENT 'date the host first signed on',
700700
`removed` datetime COMMENT 'date removed if not null',
701-
`allocation_state` varchar(32) NOT NULL DEFAULT 'Enabled' COMMENT 'Is this host enabled for allocation for new resources',
701+
`update_count` bigint unsigned NOT NULL DEFAULT 0 COMMENT 'atomic increase count making status update operation atomical',
702702
`resource_state` varchar(32) NOT NULL DEFAULT 'Disabled' COMMENT 'Is this host enabled for allocation for new resources',
703703
PRIMARY KEY (`id`),
704704
INDEX `i_host__removed`(`removed`),

0 commit comments

Comments
 (0)