hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdcry...@apache.org
Subject svn commit: r1095532 - in /hbase/branches/0.90: ./ src/main/java/org/apache/hadoop/hbase/ src/main/java/org/apache/hadoop/hbase/master/ src/test/java/org/apache/hadoop/hbase/master/
Date Wed, 20 Apr 2011 21:59:09 GMT
Author: jdcryans
Date: Wed Apr 20 21:59:08 2011
New Revision: 1095532

URL: http://svn.apache.org/viewvc?rev=1095532&view=rev
Log:
HBASE-3580  Remove RS from DeadServer when new instance checks in

Modified:
    hbase/branches/0.90/CHANGES.txt
    hbase/branches/0.90/src/main/java/org/apache/hadoop/hbase/HServerInfo.java
    hbase/branches/0.90/src/main/java/org/apache/hadoop/hbase/master/DeadServer.java
    hbase/branches/0.90/src/main/java/org/apache/hadoop/hbase/master/ServerManager.java
    hbase/branches/0.90/src/test/java/org/apache/hadoop/hbase/master/TestDeadServer.java

Modified: hbase/branches/0.90/CHANGES.txt
URL: http://svn.apache.org/viewvc/hbase/branches/0.90/CHANGES.txt?rev=1095532&r1=1095531&r2=1095532&view=diff
==============================================================================
--- hbase/branches/0.90/CHANGES.txt (original)
+++ hbase/branches/0.90/CHANGES.txt Wed Apr 20 21:59:08 2011
@@ -38,6 +38,7 @@ Release 0.90.3 - Unreleased
    HBASE-3767  Improve how HTable handles threads used for multi actions
    HBASE-3795  Remove the "Cache hit for row" message
    HBASE-3798  [REST] Allow representation to elide row key and column key
+   HBASE-3580  Remove RS from DeadServer when new instance checks in
 
   TASK
    HBASE-3748  Add rolling of thrift/rest daemons to graceful_stop.sh script

Modified: hbase/branches/0.90/src/main/java/org/apache/hadoop/hbase/HServerInfo.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.90/src/main/java/org/apache/hadoop/hbase/HServerInfo.java?rev=1095532&r1=1095531&r2=1095532&view=diff
==============================================================================
--- hbase/branches/0.90/src/main/java/org/apache/hadoop/hbase/HServerInfo.java (original)
+++ hbase/branches/0.90/src/main/java/org/apache/hadoop/hbase/HServerInfo.java Wed Apr 20
21:59:08 2011
@@ -279,4 +279,20 @@ public class HServerInfo implements Writ
     }
     return false;
   }
+
+  /**
+   * Utility method to excise the start code from a server name
+   * @param inServerName full server name
+   * @return server name less its start code
+   */
+  public static String getServerNameLessStartCode(String inServerName) {
+    if (inServerName != null && inServerName.length() > 0) {
+      int index = inServerName.lastIndexOf(SERVERNAME_SEPARATOR);
+      if (index > 0) {
+        return inServerName.substring(0, index);
+      }
+    }
+    return inServerName;
+  }
+
 }

Modified: hbase/branches/0.90/src/main/java/org/apache/hadoop/hbase/master/DeadServer.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.90/src/main/java/org/apache/hadoop/hbase/master/DeadServer.java?rev=1095532&r1=1095531&r2=1095532&view=diff
==============================================================================
--- hbase/branches/0.90/src/main/java/org/apache/hadoop/hbase/master/DeadServer.java (original)
+++ hbase/branches/0.90/src/main/java/org/apache/hadoop/hbase/master/DeadServer.java Wed Apr
20 21:59:08 2011
@@ -42,9 +42,6 @@ public class DeadServer implements Set<S
    */
   private final Set<String> deadServers = new HashSet<String>();
 
-  /** Linked list of dead servers used to bound size of dead server set */
-  private final List<String> deadServerList = new LinkedList<String>();
-
   /** Maximum number of dead servers to keep track of */
   private final int maxDeadServers;
 
@@ -66,6 +63,27 @@ public class DeadServer implements Set<S
   }
 
   /**
+   * A dead server that comes back alive has a different start code.
+   * @param newServerName Servername as either <code>host:port</code> or
+   * <code>host,port,startcode</code>.
+   * @return true if this server was dead before and coming back alive again
+   */
+  public boolean cleanPreviousInstance(final String newServerName) {
+
+    String serverAddress =
+        HServerInfo.getServerNameLessStartCode(newServerName);
+    for (String serverName: deadServers) {
+      String deadServerAddress =
+          HServerInfo.getServerNameLessStartCode(serverName);
+      if (deadServerAddress.equals(serverAddress)) {
+        remove(serverName);
+        return true;
+      }
+    }
+    return false;
+  }
+
+  /**
    * @param serverName Servername as either <code>host:port</code> or
    * <code>host,port,startcode</code>.
    * @param hostAndPortOnly True if <code>serverName</code> is host and
@@ -95,11 +113,6 @@ public class DeadServer implements Set<S
 
   public synchronized boolean add(String e) {
     this.numProcessing++;
-    // Check to see if we are at capacity for dead servers
-    if (deadServerList.size() == this.maxDeadServers) {
-      deadServers.remove(deadServerList.remove(0));
-    }
-    deadServerList.add(e);
     return deadServers.add(e);
   }
 
@@ -132,7 +145,7 @@ public class DeadServer implements Set<S
   }
 
   public synchronized boolean remove(Object o) {
-    throw new UnsupportedOperationException();
+    return this.deadServers.remove(o);
   }
 
   public synchronized boolean containsAll(Collection<?> c) {

Modified: hbase/branches/0.90/src/main/java/org/apache/hadoop/hbase/master/ServerManager.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.90/src/main/java/org/apache/hadoop/hbase/master/ServerManager.java?rev=1095532&r1=1095531&r2=1095532&view=diff
==============================================================================
--- hbase/branches/0.90/src/main/java/org/apache/hadoop/hbase/master/ServerManager.java (original)
+++ hbase/branches/0.90/src/main/java/org/apache/hadoop/hbase/master/ServerManager.java Wed
Apr 20 21:59:08 2011
@@ -183,18 +183,30 @@ public class ServerManager {
   }
 
   /**
-   * If this server is on the dead list, reject it with a LeaseStillHeldException
+   * If this server is on the dead list, reject it with a YouAreDeadException.
+   * If it was dead but came back with a new start code, remove the old entry
+   * from the dead list.
    * @param serverName Server name formatted as host_port_startcode.
    * @param what START or REPORT
-   * @throws LeaseStillHeldException
+   * @throws YouAreDeadException
    */
   private void checkIsDead(final String serverName, final String what)
-  throws YouAreDeadException {
-    if (!this.deadservers.isDeadServer(serverName)) return;
-    String message = "Server " + what + " rejected; currently processing " +
-      serverName + " as dead server";
-    LOG.debug(message);
-    throw new YouAreDeadException(message);
+      throws YouAreDeadException {
+    if (this.deadservers.isDeadServer(serverName)) {
+      // host name, port and start code all match with existing one of the
+      // dead servers. So, this server must be dead.
+      String message = "Server " + what + " rejected; currently processing " +
+          serverName + " as dead server";
+      LOG.debug(message);
+      throw new YouAreDeadException(message);
+    }
+
+    if (this.deadservers.cleanPreviousInstance(serverName)) {
+      // This server has now become alive after we marked it as dead.
+      // We removed it's previous entry from the dead list to reflect it.
+      LOG.debug("Server " + serverName + " came back up, removed it from the" +
+          " dead servers list");
+    }
   }
 
   /**

Modified: hbase/branches/0.90/src/test/java/org/apache/hadoop/hbase/master/TestDeadServer.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.90/src/test/java/org/apache/hadoop/hbase/master/TestDeadServer.java?rev=1095532&r1=1095531&r2=1095532&view=diff
==============================================================================
--- hbase/branches/0.90/src/test/java/org/apache/hadoop/hbase/master/TestDeadServer.java (original)
+++ hbase/branches/0.90/src/test/java/org/apache/hadoop/hbase/master/TestDeadServer.java Wed
Apr 20 21:59:08 2011
@@ -46,13 +46,23 @@ public class TestDeadServer {
     assertFalse(ds.areDeadServersInProgress());
     final String hostname12345 = "127.0.0.2,12345,4";
     ds.add(hostname12345);
-    // hostname123 should now be evicted
-    assertFalse(ds.isDeadServer(hostname123, false));
-    // but others should still be dead
     assertTrue(ds.isDeadServer(hostname1234, false));
     assertTrue(ds.isDeadServer(hostname12345, false));
     assertTrue(ds.areDeadServersInProgress());
     ds.finish(hostname12345);
     assertFalse(ds.areDeadServersInProgress());
+
+    // Already dead =       127.0.0.1,9090,112321
+    // Coming back alive =  127.0.0.1,9090,223341
+
+    final String deadServer = "127.0.0.1,9090,112321";
+    assertFalse(ds.cleanPreviousInstance(deadServer));
+    ds.add(deadServer);
+    assertTrue(ds.isDeadServer(deadServer));
+    final String deadServerHostComingAlive = "127.0.0.1,9090,112321";
+    assertTrue(ds.cleanPreviousInstance(deadServerHostComingAlive));
+    assertFalse(ds.isDeadServer(deadServer));
+    assertFalse(ds.cleanPreviousInstance(deadServerHostComingAlive));
+
   }
 }
\ No newline at end of file



Mime
View raw message