Skip to content

Commit

Permalink
perf: 主机与主机关系事件处理优化 TencentBlueKing#1145
Browse files Browse the repository at this point in the history
增加主机关系事件处理流水日志。
  • Loading branch information
jsonwan committed Jul 26, 2022
1 parent 3715de0 commit 4970e84
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ void handleEvent(ResourceEvent<HostEventDetail> event) {

private void handleOneEventRelatedToApp(ResourceEvent<HostEventDetail> event) {
try {
log.info("start to handle event:{}", JsonUtils.toJson(event));
log.info("start to handle host event:{}", JsonUtils.toJson(event));
handleOneEventIndeed(event);
} catch (Throwable t) {
log.error(String.format("Fail to handle hostEvent:%s", event), t);
} finally {
log.info("end to handle event");
log.info("end to handle host event");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.tencent.bk.job.common.cc.model.result.HostRelationEventDetail;
import com.tencent.bk.job.common.cc.model.result.ResourceEvent;
import com.tencent.bk.job.common.model.dto.ApplicationHostDTO;
import com.tencent.bk.job.common.util.json.JsonUtils;
import com.tencent.bk.job.manage.dao.ApplicationHostDAO;
import com.tencent.bk.job.manage.dao.HostTopoDAO;
import com.tencent.bk.job.manage.manager.host.HostCache;
Expand Down Expand Up @@ -70,6 +71,7 @@ void handleEvent(ResourceEvent<HostRelationEventDetail> event) {
}

private void handleOneEvent(ResourceEvent<HostRelationEventDetail> event) {
log.info("start to handle host relation event:{}", JsonUtils.toJson(event));
HostTopoDTO hostTopoDTO = HostTopoDTO.fromHostRelationEvent(event.getDetail());
Long appId = hostTopoDTO.getBizId();
try {
Expand All @@ -84,6 +86,8 @@ private void handleOneEvent(ResourceEvent<HostRelationEventDetail> event) {
}
} catch (Throwable t) {
log.error(String.format("Fail to handle hostRelationEvent of appId %d, event:%s", appId, event), t);
} finally {
log.info("end to handle host relation event");
}
}

Expand Down Expand Up @@ -129,9 +133,11 @@ private void handleOneEventIndeed(ResourceEvent<HostRelationEventDetail> event)
private void updateTopoToHost(HostTopoDTO hostTopoDTO) {
// 若主机存在需将拓扑信息同步至主机信息冗余字段
int affectedNum = applicationHostDAO.syncHostTopo(dslContext, hostTopoDTO.getHostId());
if (affectedNum == 0) {
if (affectedNum > 0) {
log.info("host topo synced: affectedNum={}", affectedNum);
} else if (affectedNum == 0) {
log.info("no host topo synced");
} else if (affectedNum < 0) {
} else {
FormattingTuple msg = MessageFormatter.format(
"cannot find hostInfo by hostId:{}, wait for host event or sync",
hostTopoDTO.getHostId()
Expand All @@ -149,6 +155,7 @@ private void updateHostCacheWhenRelCreated(HostTopoDTO hostTopoDTO) {
ApplicationHostDTO host = applicationHostDAO.getHostById(hostTopoDTO.getHostId());
if (host != null && applicationService.existBiz(host.getBizId())) {
hostCache.addOrUpdateHost(host);
log.info("host cached updated: hostId={}", host.getHostId());
}
}

Expand All @@ -174,10 +181,12 @@ private void updateHostCacheWhenRelationDeleted(HostTopoDTO hostTopoDTO) {
if (hostRelationCount == 0) {
// 主机被移除
hostCache.deleteHost(host);
log.info("host cached deleted: hostId={}", host.getHostId());
} else {
// 主机被转移到其他业务下
if (applicationService.existBiz(host.getBizId())) {
hostCache.addOrUpdateHost(host);
log.info("host cached updated: hostId={}", host.getHostId());
}
}
}
Expand Down

0 comments on commit 4970e84

Please sign in to comment.