swagle commented on a change in pull request #313: HDDS-2242. Avoid unnecessary 
rpc needed to discover the pipeline leader.
URL: https://github.com/apache/hadoop-ozone/pull/313#discussion_r356410606
 
 

 ##########
 File path: 
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/hdds/scm/TestRatisPipelineLeader.java
 ##########
 @@ -0,0 +1,124 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hadoop.hdds.scm;
+
+import java.util.List;
+import java.util.Optional;
+
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
+import org.apache.hadoop.hdds.scm.pipeline.Pipeline;
+import org.apache.hadoop.ozone.HddsDatanodeService;
+import org.apache.hadoop.ozone.MiniOzoneCluster;
+import 
org.apache.hadoop.ozone.container.common.transport.server.ratis.XceiverServerRatis;
+import org.apache.hadoop.test.GenericTestUtils;
+import org.apache.ratis.grpc.client.GrpcClientProtocolClient;
+import org.apache.ratis.protocol.ClientId;
+import org.apache.ratis.protocol.GroupInfoReply;
+import org.apache.ratis.protocol.GroupInfoRequest;
+import org.apache.ratis.protocol.RaftGroupId;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * Test pipeline leader information is correctly used.
+ */
+public class TestRatisPipelineLeader {
+  private static MiniOzoneCluster cluster;
+  private static OzoneConfiguration conf;
+
+  @BeforeClass
+  public static void setup() throws Exception {
+    conf = new OzoneConfiguration();
+    cluster = MiniOzoneCluster
+        .newBuilder(conf)
+        .setNumDatanodes(3)
+        .build();
+    cluster.waitForClusterToBeReady();
+  }
+
+  @AfterClass
+  public static void shutdown() throws Exception {
+    if (cluster != null) {
+      cluster.shutdown();
+    }
+  }
+
+  @Test
+  public void testLeaderIdUsedOnFirstCall() throws Exception {
+    List<Pipeline> pipelines = cluster.getStorageContainerManager()
+        .getPipelineManager().getPipelines();
+    Optional<Pipeline> ratisPipeline = pipelines.stream().filter(p ->
+        p.getType().equals(HddsProtos.ReplicationType.RATIS)).findFirst();
+    Assert.assertTrue(ratisPipeline.isPresent());
+    Assert.assertTrue(ratisPipeline.get().isHealthy());
+    // Verify correct leader info populated
+    verifyLeaderInfo(ratisPipeline.get());
+    // Verify client connects to Leader without NotLeaderException
+    XceiverClientRatis xceiverClientRatis =
+        XceiverClientRatis.newXceiverClientRatis(ratisPipeline.get(), conf);
+    GenericTestUtils.LogCapturer logCapturer =
+        GenericTestUtils.LogCapturer.captureLogs(GrpcClientProtocolClient.LOG);
+    xceiverClientRatis.connect();
+    logCapturer.stopCapturing();
+    Assert.assertFalse("Client should connect to pipeline leader on first 
try.",
+        logCapturer.getOutput().contains(
+            "org.apache.ratis.protocol.NotLeaderException"));
 
 Review comment:
   Hi @adoroszlai, good catch, this was from memory, it seems we have since 
changed where this gets logged and the level. I have verified by returning 
non-leader on the newly added method that we get failure:
   
   `2019-12-10 21:28:23,433 [ForkJoinPool.commonPool-worker-2] DEBUG 
client.GrpcClientProtocolService 
(GrpcClientProtocolService.java:sendReply(354)) - 
0-OrderedRequestStreamObserver0: sendReply seq=1, 
RaftClientReply:client-C8FCD8002CD8->1f4d9226-afd7-40f5-9dd3-db27236750e8@group-A49D14340303,
 cid=0, FAILED org.apache.ratis.protocol.NotLeaderException: Server 
1f4d9226-afd7-40f5-9dd3-db27236750e8@group-A49D14340303 is not the leader 
f12ee13d-5e47-4dc1-87ca-f330c773f86f:192.168.1.15:50058, logIndex=0, 
commits[1f4d9226-afd7-40f5-9dd3-db27236750e8:c-1, 
f12ee13d-5e47-4dc1-87ca-f330c773f86f:c0, 
6f12f4a3-71e9-41ff-8fdb-714053a8f799:c0]`
   

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: ozone-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: ozone-issues-h...@hadoop.apache.org

Reply via email to