Ejemplo n.º 1
0
  public void resetForNewExecution() {
    if (!(numSubtasksInFinalState == 0 || numSubtasksInFinalState == parallelism)) {
      throw new IllegalStateException("Cannot reset vertex that is not in final state");
    }

    synchronized (stateMonitor) {
      // check and reset the sharing groups with scheduler hints
      if (slotSharingGroup != null) {
        slotSharingGroup.clearTaskAssignment();
      }

      // reset vertices one by one. if one reset fails, the "vertices in final state"
      // fields will be consistent to handle triggered cancel calls
      for (int i = 0; i < parallelism; i++) {
        taskVertices[i].resetForNewExecution();
        if (finishedSubtasks[i]) {
          finishedSubtasks[i] = false;
          numSubtasksInFinalState--;
        }
      }

      if (numSubtasksInFinalState != 0) {
        throw new RuntimeException("Bug: resetting the execution job vertex failed.");
      }

      // set up the input splits again
      try {
        if (this.inputSplits != null) {
          // lazy assignment
          @SuppressWarnings("unchecked")
          InputSplitSource<InputSplit> splitSource =
              (InputSplitSource<InputSplit>) jobVertex.getInputSplitSource();
          this.splitAssigner = splitSource.getInputSplitAssigner(this.inputSplits);
        }
      } catch (Throwable t) {
        throw new RuntimeException(
            "Re-creating the input split assigner failed: " + t.getMessage(), t);
      }

      // Reset intermediate results
      for (IntermediateResult result : producedDataSets) {
        result.resetForNewExecution();
      }
    }
  }