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
Conversation
jsonwan
commented
Jun 29, 2023
- 更新/删除主机前,对比cmdb主机数据获取时间与当前DB数据最后更新时间,防止旧数据覆盖新数据;
- 去除批量更新主机长事务;
- 去除主机数据更新与主机关系数据更新间的耦合;
- 全量更新改为增量更新;
- 去除对主机表中拓扑数据的引用,后续去除冗余拓扑字段。
1.更新/删除主机前,对比cmdb主机数据获取时间与当前DB数据最后更新时间,防止旧数据覆盖新数据; 2.去除批量更新主机长事务;
b4cfca5
to
d893312
Compare
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中的数据最后修改时间'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
数据库字段最好不要有中文注释
There was a problem hiding this comment.
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`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
数据库字段最好不要有中文注释
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
基础工具需要添加注释以及对应的单元测试代码。另外,如果这个 dateformat 如果只支持 ISO_DATE_TIME 的话,也需要在注释中说明限制
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
分批可以使用 CollectionUtil.partitionList() 方法
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private ? 如果是继承的话,添加 @OverRide
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上,分批使用工具方法
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isDebugEnabled
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isDebugEnabled
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已修改