@Override protected Procedure<MasterProcedureEnv>[] execute(MasterProcedureEnv env) throws ProcedureYieldException, ProcedureSuspendedException, InterruptedException { if (dispatched) { if (succ) { return null; } dispatched = false; } try { env.getRemoteDispatcher().addOperationToNode(targetServer, this); } catch (FailedRemoteDispatchException frde) { LOG.warn("Can not add remote operation for switching rpc throttle to {} on {}", rpcThrottleEnabled, targetServer); return null; } dispatched = true; event = new ProcedureEvent<>(this); event.suspendIfNotReady(this); throw new ProcedureSuspendedException(); }
public void suspend(Procedure<?> proc) { event.suspend(); event.suspendIfNotReady(proc); }
@Test public void testSuspendedProcedure() throws Exception { final TableName tableName = TableName.valueOf(name.getMethodName()); queue.addBack( new TestTableProcedure(1, tableName, TableProcedureInterface.TableOperationType.READ)); queue.addBack( new TestTableProcedure(2, tableName, TableProcedureInterface.TableOperationType.READ)); Procedure<?> proc = queue.poll(); assertEquals(1, proc.getProcId()); // suspend ProcedureEvent<?> event = new ProcedureEvent<>("testSuspendedProcedureEvent"); assertEquals(true, event.suspendIfNotReady(proc)); proc = queue.poll(); assertEquals(2, proc.getProcId()); assertEquals(null, queue.poll(0)); // resume event.wake(queue); proc = queue.poll(); assertEquals(1, proc.getProcId()); assertEquals(null, queue.poll(0)); }
private void complete(MasterProcedureEnv env, Throwable error) { if (error != null) { LOG.warn("Failed to switch rpc throttle to {} on server {}", rpcThrottleEnabled, targetServer, error); this.succ = false; } else { this.succ = true; } event.wake(env.getProcedureScheduler()); event = null; }
assertEquals(false, event.isReady()); assertEquals(0, event.getSuspendedProcedures().size()); while (event.getSuspendedProcedures().size() < 1) Thread.sleep(25); LOG.debug("checking " + event + " size=" + event.getSuspendedProcedures().size()); assertEquals(false, event.isReady()); assertEquals(1, event.getSuspendedProcedures().size()); event.wake(procSched); assertEquals(true, event.isReady()); assertEquals(true, event.isReady()); assertEquals(0, event.getSuspendedProcedures().size()); LOG.debug("completed execution of " + proc + " pollCalls=" + (procSched.getPollCalls() - startPollCalls) +
LOG.debug("WAKE BATCH " + ev[i] + " total=" + wakeCount.get()); ProcedureEvent.wakeEvents((AbstractProcedureScheduler) sched, ev); wakeCount.addAndGet(ev.length); } else { while (size-- > 0) { ProcedureEvent ev = waitQueue.pollFirst().getEvent(); ev.wake(procSched); LOG.debug("WAKE " + ev + " total=" + wakeCount.get()); wakeCount.incrementAndGet();
public UsedReplayWorkersForPeer(String peerId) { this.event = new ProcedureEvent<>(peerId); }
/** * Return whether AM finishes the meta loading, i.e, the region states rebuilding. * @see #isMetaAssigned() * @see #waitMetaLoaded(Procedure) */ public boolean isMetaLoaded() { return metaLoadEvent.isReady(); }
/** * Wait until AM finishes the meta loading, i.e, the region states rebuilding. * @see #isMetaLoaded() * @see #waitMetaAssigned(Procedure, RegionInfo) */ public boolean waitMetaLoaded(Procedure<?> proc) { return metaLoadEvent.suspendIfNotReady(proc); }
@Override public Void answer(InvocationOnMock invocation) throws Throwable { ProcedureEvent<?> event = ((ProcedureEvent<?>[]) invocation.getArgument(0))[0]; event.wakeInternal(new MasterProcedureScheduler(pid -> null) { @Override public void addFront(Iterator<Procedure> procedureIterator) { procedureIterator.forEachRemaining(wokenProcedures::add); } }); return null; } }).when(scheduler).wakeEvents(any(ProcedureEvent[].class));
/** Mark the event as not ready. */ public synchronized void suspend() { ready = false; if (LOG.isTraceEnabled()) { LOG.trace("Suspend " + toString()); } }
/** * Add the assign operation to the assignment queue. * The pending assignment operation will be processed, * and each region will be assigned by a server using the balancer. */ protected void queueAssign(final RegionStateNode regionNode) { regionNode.getProcedureEvent().suspend(); // TODO: quick-start for meta and the other sys-tables? assignQueueLock.lock(); try { pendingAssignQueue.add(regionNode); if (regionNode.isSystemTable() || pendingAssignQueue.size() == 1 || pendingAssignQueue.size() >= assignDispatchWaitQueueMaxSize) { assignQueueFullCond.signal(); } } finally { assignQueueLock.unlock(); } }
private void acceptPlan(final HashMap<RegionInfo, RegionStateNode> regions, final Map<ServerName, List<RegionInfo>> plan) throws HBaseIOException { final ProcedureEvent<?>[] events = new ProcedureEvent[regions.size()]; final long st = System.currentTimeMillis(); if (plan == null) { throw new HBaseIOException("unable to compute plans for regions=" + regions.size()); } if (plan.isEmpty()) return; int evcount = 0; for (Map.Entry<ServerName, List<RegionInfo>> entry: plan.entrySet()) { final ServerName server = entry.getKey(); for (RegionInfo hri: entry.getValue()) { final RegionStateNode regionNode = regions.get(hri); regionNode.setRegionLocation(server); events[evcount++] = regionNode.getProcedureEvent(); } } ProcedureEvent.wakeEvents(getProcedureScheduler(), events); final long et = System.currentTimeMillis(); if (LOG.isTraceEnabled()) { LOG.trace("ASSIGN ACCEPT " + events.length + " -> " + StringUtils.humanTimeDiff(et - st)); } }
@Test public void testSuspendedProcedure() throws Exception { final TableName tableName = TableName.valueOf(name.getMethodName()); queue.addBack( new TestTableProcedure(1, tableName, TableProcedureInterface.TableOperationType.READ)); queue.addBack( new TestTableProcedure(2, tableName, TableProcedureInterface.TableOperationType.READ)); Procedure<?> proc = queue.poll(); assertEquals(1, proc.getProcId()); // suspend ProcedureEvent<?> event = new ProcedureEvent<>("testSuspendedProcedureEvent"); assertEquals(true, event.suspendIfNotReady(proc)); proc = queue.poll(); assertEquals(2, proc.getProcId()); assertEquals(null, queue.poll(0)); // resume event.wake(queue); proc = queue.poll(); assertEquals(1, proc.getProcId()); assertEquals(null, queue.poll(0)); }
private void complete(MasterProcedureEnv env, Throwable error) { if (event == null) { LOG.warn("procedure event for {} is null, maybe the procedure is created when recovery", getProcId()); return; } if (error != null) { LOG.warn("Refresh peer {} for {} on {} failed", peerId, type, targetServer, error); this.succ = false; } else { LOG.info("Refresh peer {} for {} on {} suceeded", peerId, type, targetServer); this.succ = true; } event.wake(env.getProcedureScheduler()); event = null; }
assertEquals(false, event.isReady()); assertEquals(0, event.getSuspendedProcedures().size()); while (event.getSuspendedProcedures().size() < 1) Thread.sleep(25); LOG.debug("checking " + event + " size=" + event.getSuspendedProcedures().size()); assertEquals(false, event.isReady()); assertEquals(1, event.getSuspendedProcedures().size()); event.wake(procSched); assertEquals(true, event.isReady()); assertEquals(true, event.isReady()); assertEquals(0, event.getSuspendedProcedures().size()); LOG.debug("completed execution of " + proc + " pollCalls=" + (procSched.getPollCalls() - startPollCalls) +
LOG.debug("WAKE BATCH " + ev[i] + " total=" + wakeCount.get()); ProcedureEvent.wakeEvents((AbstractProcedureScheduler) sched, ev); wakeCount.addAndGet(ev.length); } else { while (size-- > 0) { ProcedureEvent ev = waitQueue.pollFirst().getEvent(); ev.wake(procSched); LOG.debug("WAKE " + ev + " total=" + wakeCount.get()); wakeCount.incrementAndGet();
public TestTableProcedureWithEvent(long procId, TableName tableName, TableOperationType opType) { super(procId, tableName, opType); event = new ProcedureEvent<>(tableName + " procId=" + procId); }