/** * This method is to be called when a server reports that it has stopped consuming a real-time segment. * * @return */ public SegmentCompletionProtocol.Response segmentStoppedConsuming( SegmentCompletionProtocol.Request.Params reqParams) { if (!isLeader() || !_helixManager.isConnected()) { _controllerMetrics.addMeteredGlobalValue(ControllerMeter.CONTROLLER_NOT_LEADER, 1L); return SegmentCompletionProtocol.RESP_NOT_LEADER; } final String segmentNameStr = reqParams.getSegmentName(); final String instanceId = reqParams.getInstanceId(); final long offset = reqParams.getOffset(); final String reason = reqParams.getReason(); LLCSegmentName segmentName = new LLCSegmentName(segmentNameStr); SegmentCompletionFSM fsm = null; SegmentCompletionProtocol.Response response = SegmentCompletionProtocol.RESP_FAILED; try { fsm = lookupOrCreateFsm(segmentName, SegmentCompletionProtocol.MSG_TYPE_STOPPED_CONSUMING); response = fsm.stoppedConsuming(instanceId, offset, reason); } catch (Exception e) { LOGGER.error("Caught exception in segmentStoppedConsuming for segment {}", segmentNameStr, e); } if (fsm != null && fsm.isDone()) { LOGGER.info("Removing FSM (if present):{}", fsm.toString()); _fsmMap.remove(segmentNameStr); } return response; }
/** * This method is to be called when a server calls in with the segmentConsumed() API, reporting an offset in the stream * that it currently has (i.e. next offset that it will consume, if it continues to consume). */ public SegmentCompletionProtocol.Response segmentConsumed(SegmentCompletionProtocol.Request.Params reqParams) { if (!isLeader() || !_helixManager.isConnected()) { _controllerMetrics.addMeteredGlobalValue(ControllerMeter.CONTROLLER_NOT_LEADER, 1L); return SegmentCompletionProtocol.RESP_NOT_LEADER; } final String segmentNameStr = reqParams.getSegmentName(); final String instanceId = reqParams.getInstanceId(); final String stopReason = reqParams.getReason(); final long offset = reqParams.getOffset(); LLCSegmentName segmentName = new LLCSegmentName(segmentNameStr); SegmentCompletionProtocol.Response response = SegmentCompletionProtocol.RESP_FAILED; SegmentCompletionFSM fsm = null; try { fsm = lookupOrCreateFsm(segmentName, SegmentCompletionProtocol.MSG_TYPE_CONSUMED); response = fsm.segmentConsumed(instanceId, offset, stopReason); } catch (Exception e) { // Return failed response } if (fsm != null && fsm.isDone()) { LOGGER.info("Removing FSM (if present):{}", fsm.toString()); _fsmMap.remove(segmentNameStr); } return response; }
public String getUrl(String hostPort, String protocol) { return protocol + "://" + hostPort + "/" + _msgType + "?" + PARAM_SEGMENT_NAME + "=" + _params.getSegmentName() + "&" + PARAM_OFFSET + "=" + _params.getOffset() + "&" + PARAM_INSTANCE_ID + "=" + _params.getInstanceId() + ( _params.getReason() == null ? "" : ("&" + PARAM_REASON + "=" + _params.getReason())) + ( _params.getBuildTimeMillis() <= 0 ? "" : ("&" + PARAM_BUILD_TIME_MILLIS + "=" + _params.getBuildTimeMillis())) + (_params.getWaitTimeMillis() <= 0 ? "" : ("&" + PARAM_WAIT_TIME_MILLIS + "=" + _params.getWaitTimeMillis())) + (_params.getExtraTimeSec() <= 0 ? "" : ("&" + PARAM_EXTRA_TIME_SEC + "=" + _params.getExtraTimeSec())) + ( _params.getMemoryUsedBytes() <= 0 ? "" : ("&" + PARAM_MEMORY_USED_BYTES + "=" + _params.getMemoryUsedBytes())) + (_params.getSegmentSizeBytes() <= 0 ? "" : ("&" + PARAM_SEGMENT_SIZE_BYTES + "=" + _params.getSegmentSizeBytes())) + (_params.getNumRows() <= 0 ? "" : ("&" + PARAM_ROW_COUNT + "=" + _params.getNumRows())) + (_params.getSegmentLocation() == null ? "" : ("&" + PARAM_SEGMENT_LOCATION + "=" + _params.getSegmentLocation())); }