mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Switched ping to use the same db connection so that running out of db connections won't affect basic operations
This commit is contained in:
parent
5b39a1b620
commit
10ac7753ed
@ -126,8 +126,6 @@ import com.cloud.storage.StoragePoolHostVO;
|
||||
import com.cloud.storage.StoragePoolStatus;
|
||||
import com.cloud.storage.StoragePoolVO;
|
||||
import com.cloud.storage.StorageService;
|
||||
import com.cloud.storage.Volume;
|
||||
import com.cloud.storage.VolumeVO;
|
||||
import com.cloud.storage.dao.StoragePoolDao;
|
||||
import com.cloud.storage.dao.StoragePoolHostDao;
|
||||
import com.cloud.storage.dao.VolumeDao;
|
||||
@ -300,7 +298,7 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, Manager {
|
||||
|
||||
_hostDao.markHostsAsDisconnected(_nodeId);
|
||||
|
||||
_monitor = new AgentMonitor(_nodeId, _hostDao, _vmDao, _dcDao, _podDao, this, _alertMgr, _pingTimeout);
|
||||
_monitor = ComponentLocator.inject(AgentMonitor.class, _nodeId, _hostDao, _vmDao, _dcDao, _podDao, this, _alertMgr, _pingTimeout);
|
||||
registerForHostEvents(_monitor, true, true, false);
|
||||
|
||||
_executor = new ThreadPoolExecutor(threads, threads, 60l, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(), new NamedThreadFactory("AgentTaskPool"));
|
||||
|
||||
@ -17,6 +17,7 @@
|
||||
*/
|
||||
package com.cloud.agent.manager;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
@ -38,21 +39,29 @@ import com.cloud.host.HostVO;
|
||||
import com.cloud.host.Status;
|
||||
import com.cloud.host.Status.Event;
|
||||
import com.cloud.host.dao.HostDao;
|
||||
import com.cloud.utils.db.ConnectionConcierge;
|
||||
import com.cloud.utils.db.DB;
|
||||
import com.cloud.utils.db.GlobalLock;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.vm.VMInstanceVO;
|
||||
import com.cloud.vm.dao.VMInstanceDao;
|
||||
|
||||
public class AgentMonitor extends Thread implements Listener {
|
||||
private static Logger s_logger = Logger.getLogger(AgentMonitor.class);
|
||||
private final long _pingTimeout;
|
||||
private final HostDao _hostDao;
|
||||
private long _pingTimeout;
|
||||
private HostDao _hostDao;
|
||||
private boolean _stop;
|
||||
private final AgentManagerImpl _agentMgr;
|
||||
private final VMInstanceDao _vmDao;
|
||||
private AgentManagerImpl _agentMgr;
|
||||
private VMInstanceDao _vmDao;
|
||||
private DataCenterDao _dcDao = null;
|
||||
private HostPodDao _podDao = null;
|
||||
private final AlertManager _alertMgr;
|
||||
private final long _msId;
|
||||
private AlertManager _alertMgr;
|
||||
private long _msId;
|
||||
private ConnectionConcierge _concierge;
|
||||
|
||||
protected AgentMonitor() {
|
||||
}
|
||||
|
||||
public AgentMonitor(long msId, HostDao hostDao, VMInstanceDao vmDao, DataCenterDao dcDao, HostPodDao podDao, AgentManagerImpl agentMgr, AlertManager alertMgr, long pingTimeout) {
|
||||
super("AgentMonitor");
|
||||
@ -65,6 +74,12 @@ public class AgentMonitor extends Thread implements Listener {
|
||||
_dcDao = dcDao;
|
||||
_podDao = podDao;
|
||||
_alertMgr = alertMgr;
|
||||
Connection conn = Transaction.getStandaloneConnection();
|
||||
if (conn == null) {
|
||||
throw new CloudRuntimeException("Unable to get a db connection.");
|
||||
}
|
||||
|
||||
_concierge = new ConnectionConcierge("AgentMonitor", conn, true, true);
|
||||
}
|
||||
|
||||
// TODO : use host machine time is not safe in clustering environment
|
||||
@ -154,11 +169,14 @@ public class AgentMonitor extends Thread implements Listener {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Override @DB
|
||||
public boolean processCommands(long agentId, long seq, Command[] commands) {
|
||||
boolean processed = false;
|
||||
for (Command cmd : commands) {
|
||||
if (cmd instanceof PingCommand) {
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
txn.transitToUserManagedConnection(_concierge.conn());
|
||||
try {
|
||||
HostVO host = _hostDao.findById(agentId);
|
||||
if( host == null ) {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
@ -168,6 +186,9 @@ public class AgentMonitor extends Thread implements Listener {
|
||||
_hostDao.updateStatus(host, Event.Ping, _msId);
|
||||
}
|
||||
processed = true;
|
||||
} finally {
|
||||
txn.transitToAutoManagedConnection(Transaction.CLOUD_DB);
|
||||
}
|
||||
}
|
||||
}
|
||||
return processed;
|
||||
|
||||
@ -132,7 +132,7 @@ public class Transaction {
|
||||
}
|
||||
|
||||
public void transitToAutoManagedConnection(short dbId) {
|
||||
assert(_stack.size() == 0) : "Can't change to auto managed connection unless your stack is empty";
|
||||
assert(_stack.size() <= 1) : "Can't change to auto managed connection unless your stack is empty";
|
||||
_dbId = dbId;
|
||||
_conn = null;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user