/** {@inheritDoc} */ @Override public void callcc() { if (jobCtx != null) jobCtx.callcc(); }
/** {@inheritDoc} */ @Override public Serializable execute() { UUID locNodeId = ignite.configuration().getNodeId(); jobCtx.setAttribute("nodeId", locNodeId); jobCtx.setAttribute("jobId", jobCtx.getJobId()); Map<String, String> attrs = new HashMap<>(10); for (int i = 0; i < 10; i++) { String s = jobCtx.getJobId().toString() + i; attrs.put(s, s); } jobCtx.setAttributes(attrs); assert jobCtx.getAttribute("nodeId").equals(locNodeId); assert jobCtx.getAttributes().get("nodeId").equals(locNodeId); assert jobCtx.getAttributes().keySet().containsAll(attrs.keySet()); assert jobCtx.getAttributes().values().containsAll(attrs.values()); return null; } });
/** {@inheritDoc} */ @Nullable @Override public <T> T holdcc(long timeout) { return jobCtx == null ? null : jobCtx.<T>holdcc(timeout); } }
/** {@inheritDoc} */ @Override protected ResultT run(VisorIdleVerifyTaskArg arg) throws IgniteException { if (fut == null) { fut = ignite.compute().executeAsync(taskCls, arg); if (!fut.isDone()) { jobCtx.holdcc(); fut.listen((IgniteInClosure<IgniteFuture<ResultT>>)f -> jobCtx.callcc()); return null; } } return fut.get(); }
/** {@inheritDoc} */ @Override public Object reduce(List<ComputeJobResult> results) { for (ComputeJobResult res : results) { ComputeJobContext jobCtx = res.getJobContext(); assert jobCtx.getAttribute("nodeId").equals(res.getNode().id()); assert jobCtx.getAttributes().get("nodeId").equals(res.getNode().id()); assert jobCtx.getAttribute("jobId").equals(jobCtx.getJobId()); for (int i = 0; i < 10; i++) { String s = jobCtx.getJobId().toString() + i; assert jobCtx.getAttribute(s).equals(s); assert jobCtx.getAttributes().get(s).equals(s); } } return null; } }
/** {@inheritDoc} */ @Override public void run() { Integer attempt = jobCtx.getAttribute(ATTR_ATTEMPT); if (attempt == null) attempt = 1; assertEquals(ignite.affinity(NON_DFLT_CACHE_NAME).mapKeyToNode(key), ignite.cluster().localNode()); jobCtx.setAttribute(ATTR_ATTEMPT, attempt + 1); if (attempt < callAttempt) throw new ComputeJobFailoverException("Failover exception."); else assertEquals(callAttempt, attempt); } }
if (fut.isDone() || F.eq(jobCtx.getAttribute(ATTR_HELD), true)) return hadoop.status(jobId); else { jobCtx.setAttribute(ATTR_HELD, true); return jobCtx.holdcc(pollDelay);
/** * Gets job priority from task context. If job has no priority default one will be used. * * @param ctx Job context. * @return Job priority. */ private int getJobPriority(ComputeJobContext ctx) { assert ctx != null; Integer p; try { p = ctx.getAttribute(STEALING_PRIORITY_ATTR); } catch (ClassCastException e) { U.error(log, "Type of job context priority attribute '" + STEALING_PRIORITY_ATTR + "' is not java.lang.Integer (will use default priority) [type=" + ctx.getAttribute(STEALING_PRIORITY_ATTR).getClass() + ", dfltPriority=" + DFLT_JOB_PRIORITY + ']', e); p = DFLT_JOB_PRIORITY; } if (p == null) p = DFLT_JOB_PRIORITY; return p; }
/** * Increases priority if job has bumped down. * * @param jobs Ordered collection of collision contexts for jobs that are currently waiting * for execution. */ private void bumpPriority(List<GridCollisionJobContextWrapper> jobs) { int starvationInc = this.starvationInc; for (int i = 0; i < jobs.size(); i++) { GridCollisionJobContextWrapper wrapper = jobs.get(i); if (i > wrapper.originalIndex()) wrapper.getContext().getJobContext() .setAttribute(jobPriAttrKey, getJobPriority(wrapper.getContext()) + starvationInc); } }
/** {@inheritDoc} */ @Override public void cancel() { synchronized (mux) { isCancelled = true; cancelCnt++; mux.notifyAll(); } log.warning("Job cancelled: " + jobCtx.getJobId()); } }
U.warn(log, "Failed to send job request because remote node left grid (if fail-over is enabled, " + "will attempt fail-over to another node) [node=" + node + ", taskName=" + ses.getTaskName() + ", taskSesId=" + ses.getId() + ", jobSesId=" + res.getJobContext().getJobId() + ']'); res.getJobContext().getJobId(), null, null, null, null, null, null, false, null); (Map<? extends Serializable, ? extends Serializable>)res.getJobContext().getAttributes(); res.getJobContext().getJobId(), ses.getTaskName(), ses.getUserVersion(), U.warn(log, "Failed to send job request because remote node left grid (if failover is enabled, " + "will attempt fail-over to another node) [node=" + node + ", taskName=" + ses.getTaskName() + ", taskSesId=" + ses.getId() + ", jobSesId=" + res.getJobContext().getJobId() + ']'); log.debug("Failed to send job request, client disconnected [node=" + node + ", taskName=" + ses.getTaskName() + ", taskSesId=" + ses.getId() + ", jobSesId=" + res.getJobContext().getJobId() + ']'); res.getJobContext().getJobId(), null, null, null, null, null, null, false, null);
/** {@inheritDoc} */ @Override public boolean heldcc() { return jobCtx != null && jobCtx.heldcc(); }
/** {@inheritDoc} */ @Override public Object call() throws IgniteCheckedException { Integer attempt = jobCtx.getAttribute(ATTR_ATTEMPT); if (attempt == null) attempt = 1; assertEquals(ignite.affinity(NON_DFLT_CACHE_NAME).mapKeyToNode(key), ignite.cluster().localNode()); jobCtx.setAttribute(ATTR_ATTEMPT, attempt + 1); if (attempt < callAttempt) throw new ComputeJobFailoverException("Failover exception."); else return attempt; } }
/** * @param ctx Failed job context. * @param failed Failed node. * @param failCnt Failover count. */ private void checkAttributes(ComputeJobContext ctx, ClusterNode failed, int failCnt) { assert (Integer)ctx.getAttribute(FAILOVER_ATTEMPT_COUNT_ATTR) == failCnt; if (failed != null) { Collection<UUID> failedSet = (Collection<UUID>)ctx.getAttribute(FAILED_NODE_LIST_ATTR); assert failedSet.contains(failed.id()); } } }
/** * @throws Exception If test failed. */ @Test public void testFailover() throws Exception { ClusterNode rmt = getSpiContext().remoteNodes().iterator().next(); GridTestJobResult failed = new GridTestJobResult(rmt); failed.getJobContext().setAttribute(JobStealingCollisionSpi.THIEF_NODE_ATTR, getSpiContext().localNode().id()); ClusterNode other = getSpi().failover(new GridFailoverTestContext(new GridTestTaskSession(), failed), Collections.singletonList(getSpiContext().remoteNodes().iterator().next())); assert other == rmt : "Invalid failed-over node: " + other; }
/** {@inheritDoc} */ @Override public Serializable execute() { Integer i = argument(0); int arg = i != null ? i : 0; ses.setAttribute("sendJob" + ctx.getJobId(), 1 + arg); return arg; } }
U.warn(log, "Failed to send job request because remote node left grid (if fail-over is enabled, " + "will attempt fail-over to another node) [node=" + node + ", taskName=" + ses.getTaskName() + ", taskSesId=" + ses.getId() + ", jobSesId=" + res.getJobContext().getJobId() + ']'); res.getJobContext().getJobId(), null, null, null, null, null, null, false, null); (Map<? extends Serializable, ? extends Serializable>)res.getJobContext().getAttributes(); res.getJobContext().getJobId(), ses.getTaskName(), ses.getUserVersion(), U.warn(log, "Failed to send job request because remote node left grid (if failover is enabled, " + "will attempt fail-over to another node) [node=" + node + ", taskName=" + ses.getTaskName() + ", taskSesId=" + ses.getId() + ", jobSesId=" + res.getJobContext().getJobId() + ']'); log.debug("Failed to send job request, client disconnected [node=" + node + ", taskName=" + ses.getTaskName() + ", taskSesId=" + ses.getId() + ", jobSesId=" + res.getJobContext().getJobId() + ']'); res.getJobContext().getJobId(), null, null, null, null, null, null, false, null);
/** {@inheritDoc} */ @Override public boolean heldcc() { return jobCtx != null && jobCtx.heldcc(); }
Integer stealingCnt = waitCtx.getJobContext().getAttribute(STEALING_ATTEMPT_COUNT_ATTR); break; Integer pri = waitCtx.getJobContext().getAttribute(STEALING_PRIORITY_ATTR); boolean cancel = waitCtx.getJobContext().getAttribute(THIEF_NODE_ATTR) == null; waitCtx.getJobContext().setAttribute(THIEF_NODE_ATTR, nodeId); waitCtx.getJobContext().setAttribute(STEALING_ATTEMPT_COUNT_ATTR, stealingCnt + 1); waitCtx.getJobContext().setAttribute(STEALING_PRIORITY_ATTR, pri + 1); log.debug("Failed to reject job [i=" + i + ']'); waitCtx.getJobContext().setAttribute(THIEF_NODE_ATTR, null); waitCtx.getJobContext().setAttribute(STEALING_ATTEMPT_COUNT_ATTR, stealingCnt); waitCtx.getJobContext().setAttribute(STEALING_PRIORITY_ATTR, pri);
@Override public void apply(IgniteFuture<Map<PartitionHashRecord, List<PartitionEntryHashRecord>>> f) { jobCtx.callcc(); } });