private void fragmentDone(final FragmentStatus status) { final boolean stateChanged = updateFragmentStatus(status); if (stateChanged) { // since we're in the fragment done clause and this was a change from previous final NodeTracker node = nodeMap.get(status.getProfile().getEndpoint()); node.fragmentComplete(); finishedFragments.incrementAndGet(); } }
@Override public void statusUpdate(final FragmentStatus status) { logger.debug("New fragment status was provided to QueryManager of {}", status); switch(status.getProfile().getState()) { case AWAITING_ALLOCATION: case RUNNING: case CANCELLATION_REQUESTED: updateFragmentStatus(status); break; case FAILED: foreman.addToEventQueue(QueryState.FAILED, new UserRemoteException(status.getProfile().getError())); // fall-through. case FINISHED: case CANCELLED: fragmentDone(status); break; default: throw new UnsupportedOperationException(String.format("Received status of %s", status)); } } };
/** * Sends status to remote Foreman node using Control Tunnel or to Local Foreman bypassing * Control Tunnel and using WorkEventBus. * * @param status */ void sendStatus(final FragmentStatus status) { DrillbitEndpoint foremanNode = foremanDrillbit.get(); if (foremanNode == null) { logger.warn("{}: State {} is not reported as {} is closed", QueryIdHelper.getQueryIdentifier(context.getHandle()), status.getProfile().getState(), this); return; } // Send status for both local and remote foreman node via Tunnel. For local there won't be any network connection // created and it will be submitted locally using LocalControlConnectionManager final ControlTunnel tunnel = context.getController().getTunnel(foremanNode); tunnel.sendFragmentStatus(status); }
private boolean updateFragmentStatus(final FragmentStatus fragmentStatus) { final FragmentHandle fragmentHandle = fragmentStatus.getHandle(); final int majorFragmentId = fragmentHandle.getMajorFragmentId(); final int minorFragmentId = fragmentHandle.getMinorFragmentId(); final FragmentData data = fragmentDataMap.get(majorFragmentId).get(minorFragmentId); final FragmentState oldState = data.getState(); final boolean inTerminalState = isTerminal(oldState); final FragmentState currentState = fragmentStatus.getProfile().getState(); if (inTerminalState || (oldState == FragmentState.CANCELLATION_REQUESTED && !isTerminal(currentState))) { // Already in a terminal state, or invalid state transition from CANCELLATION_REQUESTED. This shouldn't happen. logger.warn(String.format("Received status message for fragment %s after fragment was in state %s. New state was %s", QueryIdHelper.getQueryIdentifier(fragmentHandle), oldState, currentState)); return false; } data.setStatus(fragmentStatus); return oldState != currentState; }
public FragmentState getState() { return status.getProfile().getState(); }
private boolean madeProgress(final FragmentStatus prev, final FragmentStatus cur) { final MinorFragmentProfile previous = prev.getProfile(); final MinorFragmentProfile current = cur.getProfile(); if (previous.getState() != current.getState()) { return true; } if (previous.getOperatorProfileCount() != current.getOperatorProfileCount()) { return true; } for(int i =0; i < current.getOperatorProfileCount(); i++){ if (madeProgress(previous.getOperatorProfile(i), current.getOperatorProfile(i))) { return true; } } return false; }
public void writeTo(com.dyuproject.protostuff.Output output, org.apache.drill.exec.proto.BitControl.FragmentStatus message) throws java.io.IOException { if(message.hasProfile()) output.writeObject(1, message.getProfile(), org.apache.drill.exec.proto.SchemaUserBitShared.MinorFragmentProfile.WRITE, false); if(message.hasHandle()) output.writeObject(2, message.getHandle(), org.apache.drill.exec.proto.SchemaExecProtos.FragmentHandle.WRITE, false); } public boolean isInitialized(org.apache.drill.exec.proto.BitControl.FragmentStatus message)
public MinorFragmentProfile getProfile() { return status .getProfile() .toBuilder() .setLastUpdate(lastStatusUpdate) .setLastProgress(lastProgress) .build(); }
public Builder mergeFrom(org.apache.drill.exec.proto.BitControl.FragmentStatus other) { if (other == org.apache.drill.exec.proto.BitControl.FragmentStatus.getDefaultInstance()) return this; if (other.hasProfile()) { mergeProfile(other.getProfile()); } if (other.hasHandle()) { mergeHandle(other.getHandle()); } this.mergeUnknownFields(other.getUnknownFields()); return this; }
public void writeTo(com.dyuproject.protostuff.Output output, org.apache.drill.exec.proto.BitControl.FragmentStatus message) throws java.io.IOException { if(message.hasProfile()) output.writeObject(1, message.getProfile(), org.apache.drill.exec.proto.SchemaUserBitShared.MinorFragmentProfile.WRITE, false); if(message.hasHandle()) output.writeObject(2, message.getHandle(), org.apache.drill.exec.proto.SchemaExecProtos.FragmentHandle.WRITE, false); } public boolean isInitialized(org.apache.drill.exec.proto.BitControl.FragmentStatus message)
public Builder mergeFrom(org.apache.drill.exec.proto.BitControl.FragmentStatus other) { if (other == org.apache.drill.exec.proto.BitControl.FragmentStatus.getDefaultInstance()) return this; if (other.hasProfile()) { mergeProfile(other.getProfile()); } if (other.hasHandle()) { mergeHandle(other.getHandle()); } this.mergeUnknownFields(other.getUnknownFields()); return this; }