Skip to content

Commit 893f2af

Browse files
committed
CLOUDSTACK-7853: Fix ping timeout edge case and refactor code
Refresh InaccurateClock every 10seconds, refactor code to get ping timeout and ping interval. Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
1 parent bb96564 commit 893f2af

2 files changed

Lines changed: 9 additions & 9 deletions

File tree

engine/orchestration/src/com/cloud/agent/manager/AgentManagerImpl.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ public boolean configure(final String name, final Map<String, Object> params) th
213213
_nodeId = ManagementServerNode.getManagementServerId();
214214
s_logger.info("Configuring AgentManagerImpl. management server node id(msid): " + _nodeId);
215215

216-
final long lastPing = (System.currentTimeMillis() >> 10) - (long) (PingTimeout.value() * PingInterval.value());
216+
final long lastPing = (System.currentTimeMillis() >> 10) - getTimeout();
217217
_hostDao.markHostsAsDisconnected(_nodeId, lastPing);
218218

219219
registerForHostEvents(new BehindOnPingListener(), true, true, false);
@@ -241,8 +241,12 @@ public boolean configure(final String name, final Map<String, Object> params) th
241241
return true;
242242
}
243243

244+
protected int getPingInterval() {
245+
return PingInterval.value();
246+
}
247+
244248
protected long getTimeout() {
245-
return (long) (PingTimeout.value() * PingInterval.value());
249+
return (long) (Math.ceil(PingTimeout.value() * PingInterval.value()));
246250
}
247251

248252
@Override
@@ -358,10 +362,6 @@ public Answer sendTo(final Long dcId, final HypervisorType type, final Command c
358362
return null;
359363
}
360364

361-
protected int getPingInterval() {
362-
return PingInterval.value();
363-
}
364-
365365
@Override
366366
public Answer send(final Long hostId, final Command cmd) throws AgentUnavailableException, OperationTimedoutException {
367367
final Commands cmds = new Commands(Command.OnError.Stop);
@@ -623,7 +623,7 @@ public boolean start() {
623623
}
624624
}
625625

626-
_monitorExecutor.scheduleWithFixedDelay(new MonitorTask(), PingInterval.value(), PingInterval.value(), TimeUnit.SECONDS);
626+
_monitorExecutor.scheduleWithFixedDelay(new MonitorTask(), getPingInterval(), getPingInterval(), TimeUnit.SECONDS);
627627

628628
return true;
629629
}
@@ -1515,7 +1515,7 @@ public boolean handleDirectConnectAgent(final Host host, final StartupCommand[]
15151515
attache = createAttacheForDirectConnect(host, resource);
15161516
final StartupAnswer[] answers = new StartupAnswer[cmds.length];
15171517
for (int i = 0; i < answers.length; i++) {
1518-
answers[i] = new StartupAnswer(cmds[i], attache.getId(), PingInterval.value());
1518+
answers[i] = new StartupAnswer(cmds[i], attache.getId(), getPingInterval());
15191519
}
15201520
attache.process(answers);
15211521

utils/src/main/java/com/cloud/utils/time/InaccurateClock.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public long[] getCurrentTimes() {
6363
public synchronized String restart() {
6464
turnOff();
6565
s_executor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("InaccurateClock"));
66-
s_executor.scheduleAtFixedRate(new SetTimeTask(), 0, 60, TimeUnit.SECONDS);
66+
s_executor.scheduleAtFixedRate(new SetTimeTask(), 0, 10, TimeUnit.SECONDS);
6767
return "Restarted";
6868
}
6969

0 commit comments

Comments
 (0)