/** * Put a new record into the record queue for this {@link Fork} to process. * * <p> * This method is used by the {@link Task} that creates this {@link Fork}. * </p> * * @param record the new record * @return whether the record has been successfully put into the queue * @throws InterruptedException */ public boolean putRecord(Object record) throws InterruptedException { if (this.forkState.compareAndSet(ForkState.FAILED, ForkState.FAILED)) { ForkThrowableHolder holder = Task.getForkThrowableHolder(this.broker); Optional<Throwable> forkThrowable = holder.getThrowable(this.index); if (forkThrowable.isPresent()) { throw new IllegalStateException( String.format("Fork %d of task %s has failed and is no longer running", this.index, this.taskId), forkThrowable.get()); } else { throw new IllegalStateException( String.format("Fork %d of task %s has failed and is no longer running", this.index, this.taskId)); } } return this.putRecordImpl(record); }
@Override public void run() { compareAndSetForkState(ForkState.PENDING, ForkState.RUNNING); try { processRecords(); compareAndSetForkState(ForkState.RUNNING, ForkState.SUCCEEDED); } catch (Throwable t) { // Set throwable to holder first because AsynchronousFork::putRecord can pull the throwable when it detects ForkState.FAILED status. ForkThrowableHolder holder = Task.getForkThrowableHolder(this.broker); holder.setThrowable(this.getIndex(), t); this.forkState.set(ForkState.FAILED); this.logger.error(String.format("Fork %d of task %s failed to process data records. Set throwable in holder %s", this.index, this.taskId, holder), t); } finally { this.cleanup(); } }
ForkThrowableHolder holder = Task.getForkThrowableHolder(this.taskState.getTaskBroker()); LOG.info("Holder for this task {} is {}", this.taskId, holder); if (!holder.isEmpty()) {
/** * Put a new record into the record queue for this {@link Fork} to process. * * <p> * This method is used by the {@link Task} that creates this {@link Fork}. * </p> * * @param record the new record * @return whether the record has been successfully put into the queue * @throws InterruptedException */ public boolean putRecord(Object record) throws InterruptedException { if (this.forkState.compareAndSet(ForkState.FAILED, ForkState.FAILED)) { ForkThrowableHolder holder = Task.getForkThrowableHolder(this.broker); Optional<Throwable> forkThrowable = holder.getThrowable(this.index); if (forkThrowable.isPresent()) { throw new IllegalStateException( String.format("Fork %d of task %s has failed and is no longer running", this.index, this.taskId), forkThrowable.get()); } else { throw new IllegalStateException( String.format("Fork %d of task %s has failed and is no longer running", this.index, this.taskId)); } } return this.putRecordImpl(record); }
@Override public void run() { compareAndSetForkState(ForkState.PENDING, ForkState.RUNNING); try { processRecords(); compareAndSetForkState(ForkState.RUNNING, ForkState.SUCCEEDED); } catch (Throwable t) { // Set throwable to holder first because AsynchronousFork::putRecord can pull the throwable when it detects ForkState.FAILED status. ForkThrowableHolder holder = Task.getForkThrowableHolder(this.broker); holder.setThrowable(this.getIndex(), t); this.forkState.set(ForkState.FAILED); this.logger.error(String.format("Fork %d of task %s failed to process data records. Set throwable in holder %s", this.index, this.taskId, holder), t); } finally { this.cleanup(); } }
ForkThrowableHolder holder = Task.getForkThrowableHolder(this.taskState.getTaskBroker()); LOG.info("Holder for this task {} is {}", this.taskId, holder); if (!holder.isEmpty()) {