mcvsubbu commented on a change in pull request #5277: URL: https://github.com/apache/incubator-pinot/pull/5277#discussion_r413185035
########## File path: pinot-core/src/main/java/org/apache/pinot/core/data/manager/realtime/SegmentUploader.java ########## @@ -0,0 +1,30 @@ +/** + * 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 java.net.URI; +import java.net.URISyntaxException; + + +public interface SegmentUploader { + // Returns the URI of the uploaded segment. null if the upload fails. + URI uploadSegment(File segmentFile) + throws URISyntaxException; Review comment: Why does this throw URISyntax exception? We are providing a File handle, it does not seem correct to let the upper layer handle the URI syntax failure. The uploader, when constructed, should verify the URIs right? ########## File path: pinot-core/src/main/java/org/apache/pinot/core/util/SegmentCompletionProtocolUtils.java ########## @@ -0,0 +1,103 @@ +/** + * 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.util; + +import java.io.File; +import java.net.URI; +import org.apache.pinot.common.metrics.ServerMeter; +import org.apache.pinot.common.metrics.ServerMetrics; +import org.apache.pinot.common.protocols.SegmentCompletionProtocol; +import org.apache.pinot.common.utils.FileUploadDownloadClient; +import org.apache.pinot.server.realtime.ControllerLeaderLocator; +import org.slf4j.Logger; + + +/** + * Util methods related to low level consumers' segment completion protocols. + */ +public class SegmentCompletionProtocolUtils { + public static SegmentCompletionProtocol.Response uploadSegmentWithFileUploadDownloadClient( Review comment: can we just call this method `uploadSegment`? The file part is implied since the first argument is the `FileUploadDownloadClient` ########## File path: pinot-core/src/main/java/org/apache/pinot/core/util/SegmentCompletionProtocolUtils.java ########## @@ -0,0 +1,103 @@ +/** + * 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.util; + +import java.io.File; +import java.net.URI; +import org.apache.pinot.common.metrics.ServerMeter; +import org.apache.pinot.common.metrics.ServerMetrics; +import org.apache.pinot.common.protocols.SegmentCompletionProtocol; +import org.apache.pinot.common.utils.FileUploadDownloadClient; +import org.apache.pinot.server.realtime.ControllerLeaderLocator; +import org.slf4j.Logger; + + +/** + * Util methods related to low level consumers' segment completion protocols. + */ +public class SegmentCompletionProtocolUtils { + public static SegmentCompletionProtocol.Response uploadSegmentWithFileUploadDownloadClient( + FileUploadDownloadClient fileUploadDownloadClient, File segmentFile, String controllerVipUrl, String segmentName, + int segmentUploadRequestTimeoutMs, Logger logger) { + SegmentCompletionProtocol.Response response; + try { + String responseStr = fileUploadDownloadClient + .uploadSegment(new URI(controllerVipUrl), segmentName, segmentFile, null, null, segmentUploadRequestTimeoutMs) + .getResponse(); + response = SegmentCompletionProtocol.Response.fromJsonString(responseStr); + logger.info("Controller response {} for {}", response.toJsonString(), controllerVipUrl); + if (response.getStatus().equals(SegmentCompletionProtocol.ControllerResponseStatus.NOT_LEADER)) { + ControllerLeaderLocator.getInstance().invalidateCachedControllerLeader(); Review comment: can this logic be moved to the ControllerVip Uploader? ########## File path: pinot-core/src/main/java/org/apache/pinot/core/util/SegmentCompletionProtocolUtils.java ########## @@ -0,0 +1,103 @@ +/** + * 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.util; + +import java.io.File; +import java.net.URI; +import org.apache.pinot.common.metrics.ServerMeter; +import org.apache.pinot.common.metrics.ServerMetrics; +import org.apache.pinot.common.protocols.SegmentCompletionProtocol; +import org.apache.pinot.common.utils.FileUploadDownloadClient; +import org.apache.pinot.server.realtime.ControllerLeaderLocator; +import org.slf4j.Logger; + + +/** + * Util methods related to low level consumers' segment completion protocols. + */ +public class SegmentCompletionProtocolUtils { + public static SegmentCompletionProtocol.Response uploadSegmentWithFileUploadDownloadClient( Review comment: Or, maybe just inline the logic of this method inside the uploader. The logic for a different uploader is going to be different anyway. ########## File path: pinot-core/src/main/java/org/apache/pinot/core/util/SegmentCompletionProtocolUtils.java ########## @@ -0,0 +1,103 @@ +/** + * 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.util; + +import java.io.File; +import java.net.URI; +import org.apache.pinot.common.metrics.ServerMeter; +import org.apache.pinot.common.metrics.ServerMetrics; +import org.apache.pinot.common.protocols.SegmentCompletionProtocol; +import org.apache.pinot.common.utils.FileUploadDownloadClient; +import org.apache.pinot.server.realtime.ControllerLeaderLocator; +import org.slf4j.Logger; + + +/** + * Util methods related to low level consumers' segment completion protocols. + */ +public class SegmentCompletionProtocolUtils { + public static SegmentCompletionProtocol.Response uploadSegmentWithFileUploadDownloadClient( + FileUploadDownloadClient fileUploadDownloadClient, File segmentFile, String controllerVipUrl, String segmentName, + int segmentUploadRequestTimeoutMs, Logger logger) { + SegmentCompletionProtocol.Response response; + try { + String responseStr = fileUploadDownloadClient + .uploadSegment(new URI(controllerVipUrl), segmentName, segmentFile, null, null, segmentUploadRequestTimeoutMs) + .getResponse(); + response = SegmentCompletionProtocol.Response.fromJsonString(responseStr); + logger.info("Controller response {} for {}", response.toJsonString(), controllerVipUrl); + if (response.getStatus().equals(SegmentCompletionProtocol.ControllerResponseStatus.NOT_LEADER)) { + ControllerLeaderLocator.getInstance().invalidateCachedControllerLeader(); + } + } catch (Exception e) { + // Catch all exceptions, we want the protocol to handle the case assuming the request was never sent. + response = SegmentCompletionProtocol.RESP_NOT_SENT; + logger.error("Could not send request {}", controllerVipUrl, e); + // Invalidate controller leader cache, as exception could be because of leader being down (deployment/failure) and hence unable to send {@link SegmentCompletionProtocol.ControllerResponseStatus.NOT_LEADER} + // If cache is not invalidated, we will not recover from exceptions until the controller comes back up + ControllerLeaderLocator.getInstance().invalidateCachedControllerLeader(); Review comment: Can this logic be moved into `ControllerVipBasedSegmentUploader`? ########## File path: pinot-core/src/main/java/org/apache/pinot/core/data/manager/realtime/ControllerVipBasedSegmentUploader.java ########## @@ -0,0 +1,65 @@ +/** + * 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 java.net.URI; +import java.net.URISyntaxException; +import org.apache.pinot.common.metrics.ServerMetrics; +import org.apache.pinot.common.protocols.SegmentCompletionProtocol; +import org.apache.pinot.common.utils.FileUploadDownloadClient; +import org.apache.pinot.core.util.SegmentCompletionProtocolUtils; +import org.slf4j.Logger; + +import static org.apache.pinot.common.protocols.SegmentCompletionProtocol.ControllerResponseStatus.UPLOAD_SUCCESS; + + +// A segment uploader which uploads segments to the controller via the controller's segmentCommitUpload end point +// point. +public class ControllerVipBasedSegmentUploader implements SegmentUploader { Review comment: Maybe call it `Server2ControllerSegmentUploader`? I think we should omit Vip in the name, there is nothing in here that says we should go through vip ########## File path: pinot-core/src/main/java/org/apache/pinot/core/data/manager/realtime/ControllerVipBasedSegmentUploader.java ########## @@ -0,0 +1,65 @@ +/** + * 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 java.net.URI; +import java.net.URISyntaxException; +import org.apache.pinot.common.metrics.ServerMetrics; +import org.apache.pinot.common.protocols.SegmentCompletionProtocol; +import org.apache.pinot.common.utils.FileUploadDownloadClient; +import org.apache.pinot.core.util.SegmentCompletionProtocolUtils; +import org.slf4j.Logger; + +import static org.apache.pinot.common.protocols.SegmentCompletionProtocol.ControllerResponseStatus.UPLOAD_SUCCESS; + + +// A segment uploader which uploads segments to the controller via the controller's segmentCommitUpload end point +// point. +public class ControllerVipBasedSegmentUploader implements SegmentUploader { + private final Logger _segmentLogger; + private final String _controllerVipUrl; + private final FileUploadDownloadClient _fileUploadDownloadClient; + private final String _segmentName; + private final int _segmentUploadRequestTimeoutMs; + private final ServerMetrics _serverMetrics; + + public ControllerVipBasedSegmentUploader(Logger segmentLogger, FileUploadDownloadClient fileUploadDownloadClient, + String controllerVipUrl, String segmentName, int segmentUploadRequestTimeoutMs, ServerMetrics serverMetrics) { + _segmentLogger = segmentLogger; + _fileUploadDownloadClient = fileUploadDownloadClient; + _controllerVipUrl = controllerVipUrl; + _segmentName = segmentName; Review comment: Can construct URI here and throw exception if it fails ---------------------------------------------------------------- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
