|
|
@ -28,49 +28,43 @@ import org.apache.dolphinscheduler.remote.NettyRemotingClient; |
|
|
|
import org.apache.dolphinscheduler.remote.config.NettyClientConfig; |
|
|
|
import org.apache.dolphinscheduler.remote.config.NettyClientConfig; |
|
|
|
import org.apache.dolphinscheduler.server.master.config.MasterConfig; |
|
|
|
import org.apache.dolphinscheduler.server.master.config.MasterConfig; |
|
|
|
import org.apache.dolphinscheduler.server.zk.ZKMasterClient; |
|
|
|
import org.apache.dolphinscheduler.server.zk.ZKMasterClient; |
|
|
|
import org.apache.dolphinscheduler.service.bean.SpringApplicationContext; |
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.service.process.ProcessService; |
|
|
|
import org.apache.dolphinscheduler.service.process.ProcessService; |
|
|
|
import org.apache.dolphinscheduler.service.zk.AbstractZKClient; |
|
|
|
|
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.concurrent.ExecutorService; |
|
|
|
import javax.annotation.PostConstruct; |
|
|
|
|
|
|
|
import javax.annotation.PreDestroy; |
|
|
|
import java.util.concurrent.ThreadPoolExecutor; |
|
|
|
import java.util.concurrent.ThreadPoolExecutor; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* master scheduler thread |
|
|
|
* master scheduler thread |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class MasterSchedulerThread implements Runnable { |
|
|
|
@Service |
|
|
|
|
|
|
|
public class MasterSchedulerService extends Thread { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* logger of MasterSchedulerThread |
|
|
|
* logger of MasterSchedulerThread |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private static final Logger logger = LoggerFactory.getLogger(MasterSchedulerThread.class); |
|
|
|
private static final Logger logger = LoggerFactory.getLogger(MasterSchedulerService.class); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* master exec service |
|
|
|
* master exec service |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private final ExecutorService masterExecService; |
|
|
|
private ThreadPoolExecutor masterExecService; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* dolphinscheduler database interface
|
|
|
|
* dolphinscheduler database interface
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private final ProcessService processService; |
|
|
|
@Autowired |
|
|
|
|
|
|
|
private ProcessService processService; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* zookeeper master client |
|
|
|
* zookeeper master client |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private final ZKMasterClient zkMasterClient ; |
|
|
|
@Autowired |
|
|
|
|
|
|
|
private ZKMasterClient zkMasterClient; |
|
|
|
/** |
|
|
|
|
|
|
|
* master exec thread num |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private int masterExecThreadNum; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* master config |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private MasterConfig masterConfig; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* netty remoting client |
|
|
|
* netty remoting client |
|
|
@ -78,21 +72,25 @@ public class MasterSchedulerThread implements Runnable { |
|
|
|
private NettyRemotingClient nettyRemotingClient; |
|
|
|
private NettyRemotingClient nettyRemotingClient; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
|
|
private MasterConfig masterConfig; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* constructor of MasterSchedulerThread |
|
|
|
* constructor of MasterSchedulerThread |
|
|
|
* @param zkClient zookeeper master client |
|
|
|
|
|
|
|
* @param processService process service |
|
|
|
|
|
|
|
* @param masterExecThreadNum master exec thread num |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public MasterSchedulerThread(ZKMasterClient zkClient, ProcessService processService, int masterExecThreadNum){ |
|
|
|
@PostConstruct |
|
|
|
this.processService = processService; |
|
|
|
public void init(){ |
|
|
|
this.zkMasterClient = zkClient; |
|
|
|
this.masterExecService = (ThreadPoolExecutor)ThreadUtils.newDaemonFixedThreadExecutor("Master-Exec-Thread", masterConfig.getMasterExecThreads()); |
|
|
|
this.masterExecThreadNum = masterExecThreadNum; |
|
|
|
|
|
|
|
this.masterExecService = ThreadUtils.newDaemonFixedThreadExecutor("Master-Exec-Thread",masterExecThreadNum); |
|
|
|
|
|
|
|
this.masterConfig = SpringApplicationContext.getBean(MasterConfig.class); |
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
NettyClientConfig clientConfig = new NettyClientConfig(); |
|
|
|
NettyClientConfig clientConfig = new NettyClientConfig(); |
|
|
|
this.nettyRemotingClient = new NettyRemotingClient(clientConfig); |
|
|
|
this.nettyRemotingClient = new NettyRemotingClient(clientConfig); |
|
|
|
|
|
|
|
super.setName("MasterSchedulerThread"); |
|
|
|
|
|
|
|
super.start(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@PreDestroy |
|
|
|
|
|
|
|
public void close(){ |
|
|
|
|
|
|
|
nettyRemotingClient.close(); |
|
|
|
|
|
|
|
logger.info("master schedule service stopped..."); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -100,15 +98,10 @@ public class MasterSchedulerThread implements Runnable { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void run() { |
|
|
|
public void run() { |
|
|
|
logger.info("master scheduler start successfully..."); |
|
|
|
logger.info("master scheduler started"); |
|
|
|
while (Stopper.isRunning()){ |
|
|
|
while (Stopper.isRunning()){ |
|
|
|
|
|
|
|
|
|
|
|
// process instance
|
|
|
|
|
|
|
|
ProcessInstance processInstance = null; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
InterProcessMutex mutex = null; |
|
|
|
InterProcessMutex mutex = null; |
|
|
|
try { |
|
|
|
try { |
|
|
|
|
|
|
|
|
|
|
|
boolean runCheckFlag = OSUtils.checkResource(masterConfig.getMasterMaxCpuloadAvg(), masterConfig.getMasterReservedMemory()); |
|
|
|
boolean runCheckFlag = OSUtils.checkResource(masterConfig.getMasterMaxCpuloadAvg(), masterConfig.getMasterReservedMemory()); |
|
|
|
if(!runCheckFlag) { |
|
|
|
if(!runCheckFlag) { |
|
|
|
Thread.sleep(Constants.SLEEP_TIME_MILLIS); |
|
|
|
Thread.sleep(Constants.SLEEP_TIME_MILLIS); |
|
|
@ -116,21 +109,16 @@ public class MasterSchedulerThread implements Runnable { |
|
|
|
} |
|
|
|
} |
|
|
|
if (zkMasterClient.getZkClient().getState() == CuratorFrameworkState.STARTED) { |
|
|
|
if (zkMasterClient.getZkClient().getState() == CuratorFrameworkState.STARTED) { |
|
|
|
|
|
|
|
|
|
|
|
// create distributed lock with the root node path of the lock space as /dolphinscheduler/lock/masters
|
|
|
|
mutex = zkMasterClient.blockAcquireMutex(); |
|
|
|
String znodeLock = zkMasterClient.getMasterLockPath(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mutex = new InterProcessMutex(zkMasterClient.getZkClient(), znodeLock); |
|
|
|
int activeCount = masterExecService.getActiveCount(); |
|
|
|
mutex.acquire(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ThreadPoolExecutor poolExecutor = (ThreadPoolExecutor) masterExecService; |
|
|
|
|
|
|
|
int activeCount = poolExecutor.getActiveCount(); |
|
|
|
|
|
|
|
// make sure to scan and delete command table in one transaction
|
|
|
|
// make sure to scan and delete command table in one transaction
|
|
|
|
Command command = processService.findOneCommand(); |
|
|
|
Command command = processService.findOneCommand(); |
|
|
|
if (command != null) { |
|
|
|
if (command != null) { |
|
|
|
logger.info(String.format("find one command: id: %d, type: %s", command.getId(),command.getCommandType().toString())); |
|
|
|
logger.info(String.format("find one command: id: %d, type: %s", command.getId(),command.getCommandType().toString())); |
|
|
|
|
|
|
|
|
|
|
|
try{ |
|
|
|
try{ |
|
|
|
processInstance = processService.handleCommand(logger, OSUtils.getHost(), this.masterExecThreadNum - activeCount, command); |
|
|
|
ProcessInstance processInstance = processService.handleCommand(logger, OSUtils.getHost(), this.masterConfig.getMasterExecThreads() - activeCount, command); |
|
|
|
if (processInstance != null) { |
|
|
|
if (processInstance != null) { |
|
|
|
logger.info("start master exec thread , split DAG ..."); |
|
|
|
logger.info("start master exec thread , split DAG ..."); |
|
|
|
masterExecService.execute(new MasterExecThread(processInstance, processService, nettyRemotingClient)); |
|
|
|
masterExecService.execute(new MasterExecThread(processInstance, processService, nettyRemotingClient)); |
|
|
@ -147,12 +135,8 @@ public class MasterSchedulerThread implements Runnable { |
|
|
|
} catch (Exception e){ |
|
|
|
} catch (Exception e){ |
|
|
|
logger.error("master scheduler thread exception",e); |
|
|
|
logger.error("master scheduler thread exception",e); |
|
|
|
} finally{ |
|
|
|
} finally{ |
|
|
|
AbstractZKClient.releaseMutex(mutex); |
|
|
|
zkMasterClient.releaseMutex(mutex); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
nettyRemotingClient.close(); |
|
|
|
|
|
|
|
logger.info("master server stopped..."); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |