public void reportQueryStatusToQueryMaster(QueryId queryId, TajoProtos.QueryState state) { LOG.info("Send QueryMaster Ready to QueryJobManager:" + queryId); NettyClientBase tmClient = null; try { tmClient = connPool.getConnection( queryMasterContext.getWorkerContext().getTajoMasterAddress(), TajoMasterProtocol.class, true); TajoMasterProtocol.TajoMasterProtocolService masterClientService = tmClient.getStub(); TajoHeartbeat.Builder queryHeartbeatBuilder = TajoHeartbeat.newBuilder() .setTajoWorkerHost( workerContext.getQueryMasterManagerService().getBindAddr().getHostName()) .setTajoQueryMasterPort( workerContext.getQueryMasterManagerService().getBindAddr().getPort()) .setTajoWorkerClientPort( workerContext.getTajoWorkerClientService().getBindAddr().getPort()) .setState(state) .setQueryId(queryId.getProto()); CallFuture<TajoHeartbeatResponse> callBack = new CallFuture<TajoHeartbeatResponse>(); masterClientService.heartbeat( callBack.getController(), queryHeartbeatBuilder.build(), callBack); } catch (Exception e) { LOG.error(e.getMessage(), e); } finally { connPool.releaseConnection(tmClient); } }
public void stopQuery(QueryId queryId) { QueryMasterTask queryMasterTask; queryMasterTask = queryMasterTasks.remove(queryId); finishedQueryMasterTasks.put(queryId, queryMasterTask); if (queryMasterTask != null) { TajoHeartbeat queryHeartbeat = buildTajoHeartBeat(queryMasterTask); CallFuture<TajoHeartbeatResponse> future = new CallFuture<TajoHeartbeatResponse>(); NettyClientBase tmClient = null; try { tmClient = connPool.getConnection( queryMasterContext.getWorkerContext().getTajoMasterAddress(), TajoMasterProtocol.class, true); TajoMasterProtocol.TajoMasterProtocolService masterClientService = tmClient.getStub(); masterClientService.heartbeat(future.getController(), queryHeartbeat, future); } catch (Exception e) { // this function will be closed in new thread. // When tajo do stop cluster, tajo master maybe throw closed connection exception LOG.error(e.getMessage(), e); } finally { connPool.releaseConnection(tmClient); } try { queryMasterTask.stop(); if (!systemConf.get(CommonTestingUtil.TAJO_TEST, "FALSE").equalsIgnoreCase("TRUE") && !workerContext.isYarnContainerMode()) { cleanup(queryId); // TODO We will support yarn mode } } catch (Exception e) { LOG.error(e.getMessage(), e); } } else { LOG.warn("No query info:" + queryId); } if (workerContext.isYarnContainerMode()) { stop(); } }
@Override public void run() { LOG.info("Start QueryMaster heartbeat thread"); while (!queryMasterStop.get()) { List<QueryMasterTask> tempTasks = new ArrayList<QueryMasterTask>(); synchronized (queryMasterTasks) { tempTasks.addAll(queryMasterTasks.values()); } synchronized (queryMasterTasks) { for (QueryMasterTask eachTask : tempTasks) { NettyClientBase tmClient; try { tmClient = connPool.getConnection( queryMasterContext.getWorkerContext().getTajoMasterAddress(), TajoMasterProtocol.class, true); TajoMasterProtocol.TajoMasterProtocolService masterClientService = tmClient.getStub(); CallFuture<TajoHeartbeatResponse> callBack = new CallFuture<TajoHeartbeatResponse>(); TajoHeartbeat queryHeartbeat = buildTajoHeartBeat(eachTask); masterClientService.heartbeat(callBack.getController(), queryHeartbeat, callBack); } catch (Throwable t) { t.printStackTrace(); } } } synchronized (queryMasterStop) { try { queryMasterStop.wait(2000); } catch (InterruptedException e) { break; } } } LOG.info("QueryMaster heartbeat thread stopped"); }