hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From apurt...@apache.org
Subject [1/4] hbase git commit: HBASE-18054 log when we add/remove failed servers in client (Ali)
Date Wed, 26 Jul 2017 01:53:16 GMT
Repository: hbase
Updated Branches:
  refs/heads/branch-1 9427d6c73 -> a4e1af1fc
  refs/heads/branch-1.4 b50eb4bed -> df2518241
  refs/heads/branch-2 a5dbaaa56 -> e24f7f467
  refs/heads/master 746d1b181 -> 2fd8e824d


HBASE-18054 log when we add/remove failed servers in client (Ali)

Conflicts:
	hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/FailedServers.java


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/a4e1af1f
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/a4e1af1f
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/a4e1af1f

Branch: refs/heads/branch-1
Commit: a4e1af1fcc5fc4280a044f1b6d1e0d9636e8ee0d
Parents: 9427d6c
Author: Andrew Purtell <apurtell@apache.org>
Authored: Tue Jul 25 18:37:53 2017 -0700
Committer: Andrew Purtell <apurtell@apache.org>
Committed: Tue Jul 25 18:53:01 2017 -0700

----------------------------------------------------------------------
 .../hadoop/hbase/ipc/BlockingRpcConnection.java |  2 +-
 .../apache/hadoop/hbase/ipc/FailedServers.java  | 20 +++--
 .../hadoop/hbase/ipc/NettyRpcConnection.java    |  2 +-
 .../hadoop/hbase/ipc/TestFailedServersLog.java  | 77 ++++++++++++++++++++
 .../hadoop/hbase/ipc/TestHBaseClient.java       | 11 +--
 5 files changed, 100 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/a4e1af1f/hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/BlockingRpcConnection.java
----------------------------------------------------------------------
diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/BlockingRpcConnection.java
b/hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/BlockingRpcConnection.java
index 32c4ab9..6645694 100644
--- a/hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/BlockingRpcConnection.java
+++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/BlockingRpcConnection.java
@@ -480,7 +480,7 @@ class BlockingRpcConnection extends RpcConnection implements Runnable
{
       closeSocket();
       IOException e = ExceptionUtil.asInterrupt(t);
       if (e == null) {
-        this.rpcClient.failedServers.addToFailedServers(remoteId.address);
+        this.rpcClient.failedServers.addToFailedServers(remoteId.address, t);
         if (t instanceof LinkageError) {
           // probably the hbase hadoop version does not match the running hadoop version
           e = new DoNotRetryIOException(t);

http://git-wip-us.apache.org/repos/asf/hbase/blob/a4e1af1f/hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/FailedServers.java
----------------------------------------------------------------------
diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/FailedServers.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/FailedServers.java
index 16ec16c..2ba5a73 100644
--- a/hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/FailedServers.java
+++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/FailedServers.java
@@ -17,15 +17,19 @@
  */
 package org.apache.hadoop.hbase.ipc;
 
+import java.net.InetSocketAddress;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.Map;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.hbase.classification.InterfaceAudience;
 import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
 import org.apache.hadoop.hbase.util.Pair;
 
-import java.net.InetSocketAddress;
-import java.util.Iterator;
-import java.util.LinkedList;
-
 /**
  * A class to manage a list of servers that failed recently.
  */
@@ -34,6 +38,7 @@ public class FailedServers {
   private final LinkedList<Pair<Long, String>> failedServers = new
       LinkedList<Pair<Long, String>>();
   private final int recheckServersTimeout;
+  private static final Log LOG = LogFactory.getLog(FailedServers.class);
 
   public FailedServers(Configuration conf) {
     this.recheckServersTimeout = conf.getInt(
@@ -43,9 +48,14 @@ public class FailedServers {
   /**
    * Add an address to the list of the failed servers list.
    */
-  public synchronized void addToFailedServers(InetSocketAddress address) {
+  public synchronized void addToFailedServers(InetSocketAddress address, Throwable throwable)
{
     final long expiry = EnvironmentEdgeManager.currentTime() + recheckServersTimeout;
     failedServers.addFirst(new Pair<Long, String>(expiry, address.toString()));
+    if (LOG.isDebugEnabled()) {
+      LOG.debug(
+        "Added failed server with address " + address.toString() + " to list caused by "
+            + throwable.toString());
+    }
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/hbase/blob/a4e1af1f/hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/NettyRpcConnection.java
----------------------------------------------------------------------
diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/NettyRpcConnection.java
b/hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/NettyRpcConnection.java
index 1b31182..b5fb7e4 100644
--- a/hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/NettyRpcConnection.java
+++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/ipc/NettyRpcConnection.java
@@ -233,7 +233,7 @@ class NettyRpcConnection extends RpcConnection {
             Channel ch = future.channel();
             if (!future.isSuccess()) {
               failInit(ch, toIOE(future.cause()));
-              rpcClient.failedServers.addToFailedServers(remoteId.address);
+              rpcClient.failedServers.addToFailedServers(remoteId.address, future.cause());
               return;
             }
             ch.writeAndFlush(connectionHeaderPreamble.retainedDuplicate());

http://git-wip-us.apache.org/repos/asf/hbase/blob/a4e1af1f/hbase-client/src/test/java/org/apache/hadoop/hbase/ipc/TestFailedServersLog.java
----------------------------------------------------------------------
diff --git a/hbase-client/src/test/java/org/apache/hadoop/hbase/ipc/TestFailedServersLog.java
b/hbase-client/src/test/java/org/apache/hadoop/hbase/ipc/TestFailedServersLog.java
new file mode 100644
index 0000000..03e3ca5
--- /dev/null
+++ b/hbase-client/src/test/java/org/apache/hadoop/hbase/ipc/TestFailedServersLog.java
@@ -0,0 +1,77 @@
+/**
+ * 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.hadoop.hbase.ipc;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
+
+import java.net.InetSocketAddress;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.testclassification.ClientTests;
+import org.apache.hadoop.hbase.testclassification.SmallTests;
+import org.apache.log4j.Appender;
+import org.apache.log4j.Level;
+import org.apache.log4j.LogManager;
+import org.apache.log4j.spi.LoggingEvent;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+
+@RunWith(MockitoJUnitRunner.class)
+@Category({ ClientTests.class, SmallTests.class })
+public class TestFailedServersLog {
+  static final int TEST_PORT = 9999;
+  private InetSocketAddress addr;
+
+  @Mock
+  private Appender mockAppender;
+
+  @Captor
+  private ArgumentCaptor captorLoggingEvent;
+
+  @Before
+  public void setup() {
+    LogManager.getRootLogger().addAppender(mockAppender);
+  }
+
+  @After
+  public void teardown() {
+    LogManager.getRootLogger().removeAppender(mockAppender);
+  }
+
+  @Test
+  public void testAddToFailedServersLogging() {
+    Throwable nullException = new NullPointerException();
+
+    FailedServers fs = new FailedServers(new Configuration());
+    addr = new InetSocketAddress(TEST_PORT);
+
+    fs.addToFailedServers(addr, nullException);
+
+    Mockito.verify(mockAppender).doAppend((LoggingEvent) captorLoggingEvent.capture());
+    LoggingEvent loggingEvent = (LoggingEvent) captorLoggingEvent.getValue();
+    assertThat(loggingEvent.getLevel(), is(Level.DEBUG));
+    assertEquals("Added failed server with address " + addr.toString() + " to list caused
by "
+        + nullException.toString(),
+      loggingEvent.getRenderedMessage());
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/hbase/blob/a4e1af1f/hbase-server/src/test/java/org/apache/hadoop/hbase/ipc/TestHBaseClient.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/ipc/TestHBaseClient.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/ipc/TestHBaseClient.java
index ec3d761..d6f5c52 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/ipc/TestHBaseClient.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/ipc/TestHBaseClient.java
@@ -36,6 +36,7 @@ public class TestHBaseClient {
     ManualEnvironmentEdge ee = new ManualEnvironmentEdge();
     EnvironmentEdgeManager.injectEdge(  ee );
     FailedServers fs = new FailedServers(new Configuration());
+    Throwable testThrowable = new Throwable();//throwable already tested in TestFailedServers.java
 
     InetSocketAddress ia = InetSocketAddress.createUnresolved("bad", 12);
     InetSocketAddress ia2 = InetSocketAddress.createUnresolved("bad", 12);  // same server
as ia
@@ -45,7 +46,7 @@ public class TestHBaseClient {
 
     Assert.assertFalse( fs.isFailedServer(ia) );
 
-    fs.addToFailedServers(ia);
+    fs.addToFailedServers(ia,testThrowable);
     Assert.assertTrue( fs.isFailedServer(ia) );
     Assert.assertTrue( fs.isFailedServer(ia2) );
 
@@ -57,9 +58,9 @@ public class TestHBaseClient {
     Assert.assertFalse( fs.isFailedServer(ia) );
     Assert.assertFalse( fs.isFailedServer(ia2) );
 
-    fs.addToFailedServers(ia);
-    fs.addToFailedServers(ia3);
-    fs.addToFailedServers(ia4);
+    fs.addToFailedServers(ia,testThrowable);
+    fs.addToFailedServers(ia3,testThrowable);
+    fs.addToFailedServers(ia4,testThrowable);
 
     Assert.assertTrue( fs.isFailedServer(ia) );
     Assert.assertTrue( fs.isFailedServer(ia2) );
@@ -73,7 +74,7 @@ public class TestHBaseClient {
     Assert.assertFalse( fs.isFailedServer(ia4) );
 
 
-    fs.addToFailedServers(ia3);
+    fs.addToFailedServers(ia3,testThrowable);
     Assert.assertFalse( fs.isFailedServer(ia4) );
   }
 }


Mime
View raw message