Skip to content

Commit

Permalink
optimize router code
Browse files Browse the repository at this point in the history
  • Loading branch information
wangyapu committed Mar 6, 2019
1 parent ba7da59 commit f875ff1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ private String buildRouterInfo(String ip, String domain, RouterConfig config) {
return buildServerStr(servers);
}

private double buildSampleInfo(String domain, double defaultValue) {
private double buildSampleInfo(String domain) {
double defaultValue = 1.0;
com.dianping.cat.sample.entity.Domain domainConfig = m_sampleConfigManager.getConfig().findDomain(domain);

if (domainConfig != null) {
Expand Down Expand Up @@ -178,7 +179,7 @@ private Map<String, String> buildKvs(RouterConfig report, String domain, String

kvs.put("block", String.valueOf(m_configManager.shouldBlock(ip)));
kvs.put("routers", buildRouterInfo(ip, domain, report));
kvs.put("sample", String.valueOf(buildSampleInfo(domain, 1.0)));
kvs.put("sample", String.valueOf(buildSampleInfo(domain)));
kvs.put("startTransactionTypes", m_filterManager.getAtomicStartTypes());
kvs.put("matchTransactionTypes", m_filterManager.getAtomicMatchTypes());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ private List<String> findNearGapData(long gap, Map<String, Long> datas) {
private Map<Server, Long> processGroupMachines(Map<String, Machine> machines) {
Map<Server, Long> results = new HashMap<Server, Long>();
long total = calculateTotal(machines);
Long minGap = total / 100;
long minGap = total / 100;
long avg = total / machines.size();

for (Machine machine : machines.values()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,8 @@ private void refreshConfigInfo() throws DalException, SAXException, IOException
synchronized (this) {
if (modifyTime > m_modifyTime) {
String content = config.getContent();
RouterConfig routerConfig = DefaultSaxParser.parse(content);

m_routerConfig = routerConfig;
m_routerConfig = DefaultSaxParser.parse(content);
m_modifyTime = modifyTime;
refreshNetInfo();
}
Expand Down Expand Up @@ -340,25 +339,25 @@ private void refreshReportInfo() throws Exception {
long time = period.getTime();

try {
DailyReport report = m_dailyReportDao
.findByDomainNamePeriod(Constants.CAT, RouterConfigBuilder.ID, period, DailyReportEntity.READSET_FULL);
DailyReport report = m_dailyReportDao.findByDomainNamePeriod(Constants.CAT, RouterConfigBuilder.ID, period,
DailyReportEntity.READSET_FULL);
long modifyTime = report.getCreationDate().getTime();
Pair<RouterConfig, Long> pair = m_routerConfigs.get(time);

if (pair == null || modifyTime > pair.getValue()) {
try {
DailyReportContent reportContent = m_dailyReportContentDao
.findByPK(report.getId(), DailyReportContentEntity.READSET_FULL);
DailyReportContent reportContent = m_dailyReportContentDao.findByPK(report.getId(),
DailyReportContentEntity.READSET_FULL);
RouterConfig routerConfig = DefaultNativeParser.parse(reportContent.getContent());

m_routerConfigs.put(time, new Pair<RouterConfig, Long>(routerConfig, modifyTime));
Cat.logEvent("ReloadConfig", "router");
} catch (DalNotFoundException ignored) {

}
}
} catch (DalNotFoundException ignored) {

}
}

Expand Down

0 comments on commit f875ff1

Please sign in to comment.