private void procedureFinished(Procedure<TEnvironment> proc) { // call the procedure completion cleanup handler execCompletionCleanup(proc); CompletedProcedureRetainer<TEnvironment> retainer = new CompletedProcedureRetainer<>(proc); // update the executor internal state maps if (!proc.shouldWaitClientAck(getEnvironment())) { retainer.setClientAckTime(0); } completed.put(proc.getProcId(), retainer); rollbackStack.remove(proc.getProcId()); procedures.remove(proc.getProcId()); // call the runnableSet completion cleanup handler try { scheduler.completionCleanup(proc); } catch (Throwable e) { // Catch NullPointerExceptions or similar errors... LOG.error("CODE-BUG: uncatched runtime exception for completion cleanup: {}", proc, e); } // Notify the listeners sendProcedureFinishedNotification(proc.getProcId()); }
public boolean isExpired(long now, long evictTtl, long evictAckTtl) { return (hasClientAckTime() && (now - getClientAckTime()) >= evictAckTtl) || (now - procedure.getLastUpdate()) >= evictTtl; } }
if (retainer == null || retainer.getProcedure() instanceof FailedProcedure) { LOG.debug("No pending procedure with id = {}, skip force updating.", procId); return; if (retainer.isExpired(System.currentTimeMillis(), evictTtl, evictAckTtl)) { LOG.debug("Procedure {} has already been finished and expired, skip force updating", procId); return; proc = retainer.getProcedure();
public Procedure<TEnvironment> getResult(long procId) { CompletedProcedureRetainer<TEnvironment> retainer = completed.get(procId); if (retainer == null) { return null; } else { return retainer.getProcedure(); } }
/** * If the failure failed before submitting it, we may want to give back the * same error to the requests with the same nonceKey. * * @param nonceKey A unique identifier for this operation from the client or process * @param procName name of the procedure, used to inform the user * @param procOwner name of the owner of the procedure, used to inform the user * @param exception the failure to report to the user */ public void setFailureResultForNonce(NonceKey nonceKey, String procName, User procOwner, IOException exception) { if (nonceKey == null) { return; } Long procId = nonceKeysToProcIdsMap.get(nonceKey); if (procId == null || completed.containsKey(procId)) { return; } Procedure<TEnvironment> proc = new FailedProcedure<>(procId.longValue(), procName, procOwner, nonceKey, exception); completed.putIfAbsent(procId, new CompletedProcedureRetainer<>(proc)); }
/** * Mark the specified completed procedure, as ready to remove. * @param procId the ID of the procedure to remove */ public void removeResult(long procId) { CompletedProcedureRetainer<TEnvironment> retainer = completed.get(procId); if (retainer == null) { assert !procedures.containsKey(procId) : "pid=" + procId + " is still running"; LOG.debug("pid={} already removed by the cleaner.", procId); return; } // The CompletedProcedureCleaner will take care of deletion, once the TTL is expired. retainer.setClientAckTime(EnvironmentEdgeManager.currentTime()); }
public Procedure<TEnvironment> getResultOrProcedure(long procId) { CompletedProcedureRetainer<TEnvironment> retainer = completed.get(procId); if (retainer == null) { return procedures.get(procId); } else { return retainer.getProcedure(); } }
completed.put(proc.getProcId(), new CompletedProcedureRetainer<>(proc)); LOG.debug("Completed {}", proc); } else {
/** * Mark the specified completed procedure, as ready to remove. * @param procId the ID of the procedure to remove */ public void removeResult(long procId) { CompletedProcedureRetainer<TEnvironment> retainer = completed.get(procId); if (retainer == null) { assert !procedures.containsKey(procId) : "pid=" + procId + " is still running"; LOG.debug("pid={} already removed by the cleaner.", procId); return; } // The CompletedProcedureCleaner will take care of deletion, once the TTL is expired. retainer.setClientAckTime(EnvironmentEdgeManager.currentTime()); }
final Map.Entry<Long, CompletedProcedureRetainer<TEnvironment>> entry = it.next(); final CompletedProcedureRetainer<TEnvironment> retainer = entry.getValue(); final Procedure<?> proc = retainer.getProcedure(); IdLock.Entry lockEntry; try { if (retainer.isExpired(now, evictTtl, evictAckTtl)) {
public boolean isExpired(long now, long evictTtl, long evictAckTtl) { return (hasClientAckTime() && (now - getClientAckTime()) >= evictAckTtl) || (now - procedure.getLastUpdate()) >= evictTtl; } }
private void procedureFinished(Procedure<TEnvironment> proc) { // call the procedure completion cleanup handler execCompletionCleanup(proc); CompletedProcedureRetainer<TEnvironment> retainer = new CompletedProcedureRetainer<>(proc); // update the executor internal state maps if (!proc.shouldWaitClientAck(getEnvironment())) { retainer.setClientAckTime(0); } completed.put(proc.getProcId(), retainer); rollbackStack.remove(proc.getProcId()); procedures.remove(proc.getProcId()); // call the runnableSet completion cleanup handler try { scheduler.completionCleanup(proc); } catch (Throwable e) { // Catch NullPointerExceptions or similar errors... LOG.error("CODE-BUG: uncatched runtime exception for completion cleanup: {}", proc, e); } // Notify the listeners sendProcedureFinishedNotification(proc.getProcId()); }
/** * Check if the user is this procedure's owner * @param procId the target procedure * @param user the user * @return true if the user is the owner of the procedure, * false otherwise or the owner is unknown. */ public boolean isProcedureOwner(long procId, User user) { if (user == null) { return false; } final Procedure<TEnvironment> runningProc = procedures.get(procId); if (runningProc != null) { return runningProc.getOwner().equals(user.getShortName()); } final CompletedProcedureRetainer<TEnvironment> retainer = completed.get(procId); if (retainer != null) { return retainer.getProcedure().getOwner().equals(user.getShortName()); } // Procedure either does not exist or has already completed and got cleaned up. // At this time, we cannot check the owner of the procedure return false; }
/** * If the failure failed before submitting it, we may want to give back the * same error to the requests with the same nonceKey. * * @param nonceKey A unique identifier for this operation from the client or process * @param procName name of the procedure, used to inform the user * @param procOwner name of the owner of the procedure, used to inform the user * @param exception the failure to report to the user */ public void setFailureResultForNonce(NonceKey nonceKey, String procName, User procOwner, IOException exception) { if (nonceKey == null) { return; } Long procId = nonceKeysToProcIdsMap.get(nonceKey); if (procId == null || completed.containsKey(procId)) { return; } Procedure<TEnvironment> proc = new FailedProcedure<>(procId.longValue(), procName, procOwner, nonceKey, exception); completed.putIfAbsent(procId, new CompletedProcedureRetainer<>(proc)); }
if (retainer == null || retainer.getProcedure() instanceof FailedProcedure) { LOG.debug("No pending procedure with id = {}, skip force updating.", procId); return; if (retainer.isExpired(System.currentTimeMillis(), evictTtl, evictAckTtl)) { LOG.debug("Procedure {} has already been finished and expired, skip force updating", procId); return; proc = retainer.getProcedure();
public Procedure<TEnvironment> getResult(long procId) { CompletedProcedureRetainer<TEnvironment> retainer = completed.get(procId); if (retainer == null) { return null; } else { return retainer.getProcedure(); } }
completed.put(proc.getProcId(), new CompletedProcedureRetainer<>(proc)); LOG.debug("Completed {}", proc); } else {
final Map.Entry<Long, CompletedProcedureRetainer<TEnvironment>> entry = it.next(); final CompletedProcedureRetainer<TEnvironment> retainer = entry.getValue(); final Procedure<?> proc = retainer.getProcedure(); IdLock.Entry lockEntry; try { if (retainer.isExpired(now, evictTtl, evictAckTtl)) {
public Procedure<TEnvironment> getResultOrProcedure(long procId) { CompletedProcedureRetainer<TEnvironment> retainer = completed.get(procId); if (retainer == null) { return procedures.get(procId); } else { return retainer.getProcedure(); } }
/** * Check if the user is this procedure's owner * @param procId the target procedure * @param user the user * @return true if the user is the owner of the procedure, * false otherwise or the owner is unknown. */ public boolean isProcedureOwner(long procId, User user) { if (user == null) { return false; } final Procedure<TEnvironment> runningProc = procedures.get(procId); if (runningProc != null) { return runningProc.getOwner().equals(user.getShortName()); } final CompletedProcedureRetainer<TEnvironment> retainer = completed.get(procId); if (retainer != null) { return retainer.getProcedure().getOwner().equals(user.getShortName()); } // Procedure either does not exist or has already completed and got cleaned up. // At this time, we cannot check the owner of the procedure return false; }