protected void setMasterResult(final MasterContext<MASTER_RESULT, WORKER_RESULT> context, final String appMasterNode, final String appMasterSplitNode) throws KeeperException, InterruptedException { if(context.getCurrentIteration() == GuaguaConstants.GUAGUA_INIT_STEP) { return; } byte[] data = getBytesFromZNode(appMasterNode, appMasterSplitNode); if(data != null && data.length > 0) { MASTER_RESULT lastMasterResult = getMasterSerializer().bytesToObject(data, context.getMasterResultClassName()); context.setMasterResult(lastMasterResult); } }
private boolean isLastMaster(List<String> masterElectionNodes) { return masterElectionNodes == null || masterElectionNodes.size() == 0 || masterElectionNodes.get(masterElectionNodes.size() - 1).equals(getMyBid()); } }.execute();
@Override protected void initialize(Properties props) { super.initialize(props); initIterResults(props); }
GuaguaConstants.DEFAULT_MASTER_NUMBER) > 1) { String masterElectionPath = getBaseMasterElectionNode(appId).toString(); List<String> masterElectionNodes = getZooKeeper().getChildrenExt(masterElectionPath, false, true, true); isLastMaster = isLastMaster(masterElectionNodes); final String endWorkersNode = getWorkerBaseNode(appId, currentIteration).toString(); new RetryCoordinatorCommand(isFixedTime(), getSleepTime()) { @Override public boolean retryExecution() throws KeeperException, InterruptedException { getZooKeeper().deleteExt(appNode, -1, true); } catch (KeeperException.NoNodeException e) { if(System.nanoTime() % 20 == 0) {
updateMasterHaltStatus(context); workerBaseNode = getWorkerBaseNode(context.getAppId(), context.getCurrentIteration() + 1) .toString(); getZooKeeper().createExt(workerBaseNode, null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT, false); } catch (KeeperException.NodeExistsException e) { LOG.warn("Node exists: {}", workerBaseNode); context.getCurrentIteration()).toString(); try { byte[] bytes = getMasterSerializer().objectToBytes(context.getMasterResult()); isSplit = setBytesToZNode(appCurrentMasterNode, appCurrentMasterSplitNode, bytes, CreateMode.PERSISTENT); String znode = getMasterNode(context.getAppId(), context.getCurrentIteration() - 2).toString(); try { getZooKeeper().deleteExt(znode, -1, false); if(isSplit) { znode = getCurrentMasterSplitNode(context.getAppId(), context.getCurrentIteration() - 2) .toString(); getZooKeeper().deleteExt(znode, -1, true);
/** * Check whether GuaguaConstants.GUAGUA_WORKER_HALT_ENABLE) is enabled, if yes, check whether all workers are halted * and update master status. */ protected void updateMasterHaltStatus(final MasterContext<MASTER_RESULT, WORKER_RESULT> context) { MASTER_RESULT result = context.getMasterResult(); // a switch to make all workers have the right to terminate the application if(Boolean.TRUE.toString().equalsIgnoreCase( context.getProps().getProperty(GuaguaConstants.GUAGUA_WORKER_HALT_ENABLE, GuaguaConstants.GUAGUA_WORKER_DEFAULT_HALT_ENABLE))) { if(isAllWorkersHalt(context.getWorkerResults()) && result instanceof HaltBytable) { ((HaltBytable) result).setHalt(true); context.setMasterResult(result); } } }
@Override public void process(WatchedEvent event) { LOG.debug("DEBUG: process: Got a new event, path = {}, type = {}, state = {}", event.getPath(), event.getType(), event.getState()); if((event.getPath() == null) && (event.getType() == EventType.None)) { if(event.getState() == KeeperState.SyncConnected) { LOG.info("process: Asynchronous connection complete."); super.getZkConnLatch().countDown(); } else { LOG.warn("process: Got unknown null path event " + event); } return; } /** * Check lock signal condition. */ String appWorkerBaseNode = getWorkerBaseNode(getAppId(), getCurrentIteration()).toString(); if(event.getPath().equals(appWorkerBaseNode) && (event.getType() == EventType.NodeChildrenChanged)) { if(getCurrentIteration() == 0) { this.workerInitLock.signal(); } else { this.workerIterationLock.signal(); } } }
return; final List<String> workerChildern = getZooKeeper().getChildrenExt(appCurrentWorkersNode, false, false, false);