hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdcry...@apache.org
Subject svn commit: r1513677 - in /hbase/branches/0.95: hbase-client/src/main/java/org/apache/hadoop/hbase/client/replication/ hbase-client/src/main/java/org/apache/hadoop/hbase/replication/ hbase-server/src/main/ruby/hbase/ hbase-server/src/test/java/org/apac...
Date Tue, 13 Aug 2013 22:32:06 GMT
Author: jdcryans
Date: Tue Aug 13 22:32:05 2013
New Revision: 1513677

URL: http://svn.apache.org/r1513677
Log:
HBASE-9173 replication_admin#get_peer_state(id) in ruby script pointing to
           undefined method `getPeerState'

Modified:
    hbase/branches/0.95/hbase-client/src/main/java/org/apache/hadoop/hbase/client/replication/ReplicationAdmin.java
    hbase/branches/0.95/hbase-client/src/main/java/org/apache/hadoop/hbase/replication/ReplicationPeer.java
    hbase/branches/0.95/hbase-client/src/main/java/org/apache/hadoop/hbase/replication/ReplicationPeers.java
    hbase/branches/0.95/hbase-client/src/main/java/org/apache/hadoop/hbase/replication/ReplicationPeersZKImpl.java
    hbase/branches/0.95/hbase-server/src/main/ruby/hbase/replication_admin.rb
    hbase/branches/0.95/hbase-server/src/test/java/org/apache/hadoop/hbase/client/replication/TestReplicationAdmin.java
    hbase/branches/0.95/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationStateBasic.java

Modified: hbase/branches/0.95/hbase-client/src/main/java/org/apache/hadoop/hbase/client/replication/ReplicationAdmin.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.95/hbase-client/src/main/java/org/apache/hadoop/hbase/client/replication/ReplicationAdmin.java?rev=1513677&r1=1513676&r2=1513677&view=diff
==============================================================================
--- hbase/branches/0.95/hbase-client/src/main/java/org/apache/hadoop/hbase/client/replication/ReplicationAdmin.java
(original)
+++ hbase/branches/0.95/hbase-client/src/main/java/org/apache/hadoop/hbase/client/replication/ReplicationAdmin.java
Tue Aug 13 22:32:05 2013
@@ -175,6 +175,16 @@ public class ReplicationAdmin implements
     return this.replicationPeers.getAllPeerClusterKeys();
   }
 
+  /**
+   * Get the state of the specified peer cluster
+   * @param id String format of the Short that identifies the peer, an IllegalArgumentException
+   *           is thrown if it doesn't exist
+   * @return true if replication is enabled to that peer, false if it isn't
+   */
+  public boolean getPeerState(String id) throws IOException {
+    return this.replicationPeers.getStatusOfPeerFromBackingStore(id);
+  }
+
   @Override
   public void close() throws IOException {
     if (this.connection != null) {

Modified: hbase/branches/0.95/hbase-client/src/main/java/org/apache/hadoop/hbase/replication/ReplicationPeer.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.95/hbase-client/src/main/java/org/apache/hadoop/hbase/replication/ReplicationPeer.java?rev=1513677&r1=1513676&r2=1513677&view=diff
==============================================================================
--- hbase/branches/0.95/hbase-client/src/main/java/org/apache/hadoop/hbase/replication/ReplicationPeer.java
(original)
+++ hbase/branches/0.95/hbase-client/src/main/java/org/apache/hadoop/hbase/replication/ReplicationPeer.java
Tue Aug 13 22:32:05 2013
@@ -200,11 +200,12 @@ public class ReplicationPeer implements 
   }
 
   /**
-   * @param bytes
+   * Parse the raw data from ZK to get a peer's state
+   * @param bytes raw ZK data
    * @return True if the passed in <code>bytes</code> are those of a pb serialized
ENABLED state.
    * @throws DeserializationException
    */
-  private static boolean isStateEnabled(final byte[] bytes) throws DeserializationException
{
+  public static boolean isStateEnabled(final byte[] bytes) throws DeserializationException
{
     ZooKeeperProtos.ReplicationState.State state = parseStateFrom(bytes);
     return ZooKeeperProtos.ReplicationState.State.ENABLED == state;
   }

Modified: hbase/branches/0.95/hbase-client/src/main/java/org/apache/hadoop/hbase/replication/ReplicationPeers.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.95/hbase-client/src/main/java/org/apache/hadoop/hbase/replication/ReplicationPeers.java?rev=1513677&r1=1513676&r2=1513677&view=diff
==============================================================================
--- hbase/branches/0.95/hbase-client/src/main/java/org/apache/hadoop/hbase/replication/ReplicationPeers.java
(original)
+++ hbase/branches/0.95/hbase-client/src/main/java/org/apache/hadoop/hbase/replication/ReplicationPeers.java
Tue Aug 13 22:32:05 2013
@@ -76,12 +76,24 @@ public interface ReplicationPeers {
 
   /**
    * Get the replication status for the specified connected remote slave cluster.
+   * The value might be read from cache, so it is recommended to
+   * use {@link #getStatusOfPeerFromBackingStore(String)}
+   * if reading the state after enabling or disabling it.
    * @param peerId a short that identifies the cluster
    * @return true if replication is enabled, false otherwise.
    */
   boolean getStatusOfConnectedPeer(String peerId);
 
   /**
+   * Get the replication status for the specified remote slave cluster, which doesn't
+   * have to be connected. The state is read directly from the backing store.
+   * @param peerId a short that identifies the cluster
+   * @return true if replication is enabled, false otherwise.
+   * @throws IOException Throws if there's an error contacting the store
+   */
+  boolean getStatusOfPeerFromBackingStore(String peerId) throws IOException;
+
+  /**
    * Get a set of all connected remote slave clusters.
    * @return set of peer ids
    */

Modified: hbase/branches/0.95/hbase-client/src/main/java/org/apache/hadoop/hbase/replication/ReplicationPeersZKImpl.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.95/hbase-client/src/main/java/org/apache/hadoop/hbase/replication/ReplicationPeersZKImpl.java?rev=1513677&r1=1513676&r2=1513677&view=diff
==============================================================================
--- hbase/branches/0.95/hbase-client/src/main/java/org/apache/hadoop/hbase/replication/ReplicationPeersZKImpl.java
(original)
+++ hbase/branches/0.95/hbase-client/src/main/java/org/apache/hadoop/hbase/replication/ReplicationPeersZKImpl.java
Tue Aug 13 22:32:05 2013
@@ -138,6 +138,21 @@ public class ReplicationPeersZKImpl exte
   }
 
   @Override
+  public boolean getStatusOfPeerFromBackingStore(String id) throws IOException {
+    if (!this.getAllPeerIds().contains(id)) {
+      throw new IllegalArgumentException("peer " + id + " doesn't exist");
+    }
+    String peerStateZNode = getPeerStateNode(id);
+    try {
+      return ReplicationPeer.isStateEnabled(ZKUtil.getData(this.zookeeper, peerStateZNode));
+    } catch (KeeperException e) {
+      throw new IOException(e);
+    } catch (DeserializationException e) {
+      throw new IOException(e);
+    }
+  }
+
+  @Override
   public boolean connectToPeer(String peerId) throws IOException, KeeperException {
     if (peerClusters == null) {
       return false;

Modified: hbase/branches/0.95/hbase-server/src/main/ruby/hbase/replication_admin.rb
URL: http://svn.apache.org/viewvc/hbase/branches/0.95/hbase-server/src/main/ruby/hbase/replication_admin.rb?rev=1513677&r1=1513676&r2=1513677&view=diff
==============================================================================
--- hbase/branches/0.95/hbase-server/src/main/ruby/hbase/replication_admin.rb (original)
+++ hbase/branches/0.95/hbase-server/src/main/ruby/hbase/replication_admin.rb Tue Aug 13 22:32:05
2013
@@ -58,7 +58,7 @@ module Hbase
     #----------------------------------------------------------------------------------------------
     # Get peer cluster state
     def get_peer_state(id)
-      @replication_admin.getPeerState(id)
+      @replication_admin.getPeerState(id) ? "ENABLED" : "DISABLED"
     end
 
     #----------------------------------------------------------------------------------------------

Modified: hbase/branches/0.95/hbase-server/src/test/java/org/apache/hadoop/hbase/client/replication/TestReplicationAdmin.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.95/hbase-server/src/test/java/org/apache/hadoop/hbase/client/replication/TestReplicationAdmin.java?rev=1513677&r1=1513676&r2=1513677&view=diff
==============================================================================
--- hbase/branches/0.95/hbase-server/src/test/java/org/apache/hadoop/hbase/client/replication/TestReplicationAdmin.java
(original)
+++ hbase/branches/0.95/hbase-server/src/test/java/org/apache/hadoop/hbase/client/replication/TestReplicationAdmin.java
Tue Aug 13 22:32:05 2013
@@ -27,6 +27,8 @@ import org.junit.experimental.categories
 
 import static org.junit.Assert.fail;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertFalse;
 
 /**
  * Unit testing of ReplicationAdmin
@@ -86,12 +88,33 @@ public class TestReplicationAdmin {
       admin.addPeer(ID_SECOND, KEY_SECOND);
     } catch (IllegalStateException iae) {
       fail();
-      // OK!
     }
     assertEquals(2, admin.getPeersCount());
     // Remove the first peer we added
     admin.removePeer(ID_ONE);
     assertEquals(1, admin.getPeersCount());
+    admin.removePeer(ID_SECOND);
+    assertEquals(0, admin.getPeersCount());
+  }
+
+  /**
+   * basic checks that when we add a peer that it is enabled, and that we can disable
+   * @throws Exception
+   */
+  @Test
+  public void testEnableDisable() throws Exception {
+    admin.addPeer(ID_ONE, KEY_ONE);
+    assertEquals(1, admin.getPeersCount());
+    assertTrue(admin.getPeerState(ID_ONE));
+    admin.disablePeer(ID_ONE);
+
+    assertFalse(admin.getPeerState(ID_ONE));
+    try {
+      admin.getPeerState(ID_SECOND);
+    } catch (IllegalArgumentException iae) {
+      // OK!
+    }
+    admin.removePeer(ID_ONE);
   }
 
 }

Modified: hbase/branches/0.95/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationStateBasic.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.95/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationStateBasic.java?rev=1513677&r1=1513676&r2=1513677&view=diff
==============================================================================
--- hbase/branches/0.95/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationStateBasic.java
(original)
+++ hbase/branches/0.95/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationStateBasic.java
Tue Aug 13 22:32:05 2013
@@ -231,6 +231,10 @@ public abstract class TestReplicationSta
   }
 
   protected void assertConnectedPeerStatus(boolean status, String peerId) throws Exception
{
+    // we can first check if the value was changed in the store, if it wasn't then fail right
away
+    if (status != rp.getStatusOfPeerFromBackingStore(peerId)) {
+      fail("ConnectedPeerStatus was " + !status + " but expected " + status + " in ZK");
+    }
     while (true) {
       if (status == rp.getStatusOfConnectedPeer(peerId)) {
         return;



Mime
View raw message