Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 主机AgentId更新后,小概率出现使用旧AgentId下发任务 #2142 #2178

Merged
merged 3 commits into from Jun 30, 2023

Conversation

jsonwan
Copy link
Collaborator

@jsonwan jsonwan commented Jun 29, 2023

  1. 更新/删除主机前,对比cmdb主机数据获取时间与当前DB数据最后更新时间,防止旧数据覆盖新数据;
  2. 去除批量更新主机长事务;
  3. 去除主机数据更新与主机关系数据更新间的耦合;
  4. 全量更新改为增量更新;
  5. 去除对主机表中拓扑数据的引用,后续去除冗余拓扑字段。

1.更新/删除主机前,对比cmdb主机数据获取时间与当前DB数据最后更新时间,防止旧数据覆盖新数据;
2.去除批量更新主机长事务;
@jsonwan jsonwan force-pushed the github_fix/sync branch 4 times, most recently from b4cfca5 to d893312 Compare June 29, 2023 14:30
1.去除主机数据更新与主机关系数据更新间的耦合;
2.全量更新改为增量更新;
3.去除对主机表中拓扑数据的引用,后续去除冗余拓扑字段。
WHERE TABLE_SCHEMA = db
AND TABLE_NAME = 'host'
AND COLUMN_NAME = 'last_time') THEN
ALTER TABLE host ADD COLUMN last_time BIGINT(20) NOT NULL DEFAULT 0 COMMENT 'CMDB中的数据最后修改时间';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

数据库字段最好不要有中文注释

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已修改

WHERE TABLE_SCHEMA = db
AND TABLE_NAME = 'host_topo'
AND COLUMN_NAME = 'last_time') THEN
ALTER TABLE host_topo ADD COLUMN last_time BIGINT(20) NOT NULL DEFAULT 0 COMMENT 'CMDB中的数据最后修改时间' AFTER `app_id`;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

数据库字段最好不要有中文注释

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已修改

@@ -155,4 +154,14 @@ public static String formatTime(long timeMills, String format) {
DateFormat formatter = new SimpleDateFormat(format);
return formatter.format(date);
}

public static Long parseZonedTime(String zonedTimeStr) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

基础工具需要添加注释以及对应的单元测试代码。另外,如果这个 dateformat 如果只支持 ISO_DATE_TIME 的话,也需要在注释中说明限制

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已添加,方法名称已改为ISO专用

if (CollectionUtils.isEmpty(hostTopoList)) {
return 0;
}
int batchSize = 1000;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

分批可以使用 CollectionUtil.partitionList() 方法

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已修改

return affectedNum;
}

public int updateBeforeLastTime(HostTopoDTO hostTopo) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private ? 如果是继承的话,添加 @OverRide

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已添加

if (CollectionUtils.isEmpty(hostTopoList)) {
return 0;
}
int batchSize = 1000;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上,分批使用工具方法

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已修改

hostInfoList.forEach(hostCache::addOrUpdateHost);
watch.stop();
if (watch.getTotalTimeMillis() < 10_000L) {
log.debug("Performance:batchUpdateHostsBeforeLastTime:{}", watch.prettyPrint());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isDebugEnabled

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已修改

}
log.debug("Performance:insertHostsToApp:appId={},{}", bizId, watch.prettyPrint());
return insertFailHostIds;
log.debug("Performance:insertHosts:{}", watch.prettyPrint());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isDebugEnabled

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已修改

@wangyu096 wangyu096 merged commit 16a8286 into TencentBlueKing:master Jun 30, 2023
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants