chenboat commented on a change in pull request #5277:
URL: https://github.com/apache/incubator-pinot/pull/5277#discussion_r414126054



##########
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:
       Done.

##########
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:
       Done.




----------------------------------------------------------------
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]

Reply via email to