mcvsubbu commented on a change in pull request #4713: Refactoring realtime segment committer URL: https://github.com/apache/incubator-pinot/pull/4713#discussion_r348858149
########## File path: pinot-core/src/main/java/org/apache/pinot/core/data/manager/realtime/SplitSegmentCommitter.java ########## @@ -0,0 +1,84 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.pinot.core.data.manager.realtime; + +import java.io.File; +import org.apache.pinot.common.protocols.SegmentCompletionProtocol; +import org.apache.pinot.core.segment.index.loader.IndexLoadingConfig; +import org.apache.pinot.server.realtime.ServerSegmentCompletionProtocolHandler; +import org.slf4j.Logger; + + +/** + * Sends segmentStart, segmentUpload, & segmentCommitEnd to the controller + * If that succeeds, swap in-memory segment with the one built. + */ +public class SplitSegmentCommitter implements SegmentCommitter { + private final SegmentCompletionProtocol.Request.Params _params; + private final ServerSegmentCompletionProtocolHandler _protocolHandler; + private final String _controllerVipUrl; + private final IndexLoadingConfig _indexLoadingConfig; + + private final Logger _segmentLogger; + + public SplitSegmentCommitter(Logger segmentLogger, ServerSegmentCompletionProtocolHandler protocolHandler, + IndexLoadingConfig indexLoadingConfig, SegmentCompletionProtocol.Request.Params params, String controllerVipUrl) { + _segmentLogger = segmentLogger; + _protocolHandler = protocolHandler; + _indexLoadingConfig = indexLoadingConfig; + _params = new SegmentCompletionProtocol.Request.Params(params); + _controllerVipUrl = controllerVipUrl; + } + + @Override + public SegmentCompletionProtocol.Response commit(long currentOffset, int numRowsConsumed, LLRealtimeSegmentDataManager.SegmentBuildDescriptor segmentBuildDescriptor) { + final File segmentTarFile = new File(segmentBuildDescriptor.getSegmentTarFilePath()); + + SegmentCompletionProtocol.Response segmentCommitStartResponse = _protocolHandler.segmentCommitStart(_params); + if (!segmentCommitStartResponse.getStatus() + .equals(SegmentCompletionProtocol.ControllerResponseStatus.COMMIT_CONTINUE)) { + _segmentLogger.warn("CommitStart failed with response {}", segmentCommitStartResponse.toJsonString()); + return SegmentCompletionProtocol.RESP_FAILED; + } + + SegmentCompletionProtocol.Response segmentCommitUploadResponse = + _protocolHandler.segmentCommitUpload(_params, segmentTarFile, _controllerVipUrl); + if (!segmentCommitUploadResponse.getStatus() + .equals(SegmentCompletionProtocol.ControllerResponseStatus.UPLOAD_SUCCESS)) { + _segmentLogger.warn("Segment upload failed with response {}", segmentCommitUploadResponse.toJsonString()); + return SegmentCompletionProtocol.RESP_FAILED; + } + + _params.withSegmentLocation(segmentCommitUploadResponse.getSegmentLocation()); Review comment: ah, my bad. I did not notice that you were already constructing a new one. thanks. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
