hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From apurt...@apache.org
Subject hbase git commit: HBASE-12715 getLastSequenceId always return -1
Date Fri, 19 Dec 2014 18:46:30 GMT
Repository: hbase
Updated Branches:
  refs/heads/0.98 a4e60c9b5 -> 9fa74b333


HBASE-12715 getLastSequenceId always return -1

Signed-off-by: Andrew Purtell <apurtell@apache.org>


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

Branch: refs/heads/0.98
Commit: 9fa74b333a47a594ed8883b2061b2c78ebe1b9b3
Parents: a4e60c9
Author: zhangduo <zhangduo@wandoujia.com>
Authored: Fri Dec 19 14:18:58 2014 +0800
Committer: Andrew Purtell <apurtell@apache.org>
Committed: Fri Dec 19 10:42:34 2014 -0800

----------------------------------------------------------------------
 .../hadoop/hbase/master/ServerManager.java      | 16 ++--
 .../hbase/regionserver/HRegionServer.java       |  8 +-
 .../hbase/regionserver/LastSequenceId.java      |  6 +-
 .../master/TestGetLastFlushedSequenceId.java    | 97 ++++++++++++++++++++
 4 files changed, 112 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/9fa74b33/hbase-server/src/main/java/org/apache/hadoop/hbase/master/ServerManager.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/ServerManager.java
b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/ServerManager.java
index 9ae374b..697ba8c 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/ServerManager.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/ServerManager.java
@@ -252,7 +252,8 @@ public class ServerManager {
   private void updateLastFlushedSequenceIds(ServerName sn, ServerLoad hsl) {
     Map<byte[], RegionLoad> regionsLoad = hsl.getRegionsLoad();
     for (Entry<byte[], RegionLoad> entry : regionsLoad.entrySet()) {
-      Long existingValue = flushedSequenceIdByRegion.get(entry.getKey());
+      byte[] encodedRegionName = Bytes.toBytes(HRegionInfo.encodeRegionName(entry.getKey()));
+      Long existingValue = flushedSequenceIdByRegion.get(encodedRegionName);
       long l = entry.getValue().getCompleteSequenceId();
       if (existingValue != null) {
         if (l != -1 && l < existingValue) {
@@ -262,11 +263,10 @@ public class ServerManager {
               existingValue + ") for region " +
               Bytes.toString(entry.getKey()) + " Ignoring.");
 
-          continue; // Don't let smaller sequence ids override greater
-          // sequence ids.
+          continue; // Don't let smaller sequence ids override greater sequence ids.
         }
       }
-      flushedSequenceIdByRegion.put(entry.getKey(), l);
+      flushedSequenceIdByRegion.put(encodedRegionName, l);
     }
   }
 
@@ -405,10 +405,10 @@ public class ServerManager {
     this.rsAdmins.remove(serverName);
   }
 
-  public long getLastFlushedSequenceId(byte[] regionName) {
-    long seqId = -1;
-    if (flushedSequenceIdByRegion.containsKey(regionName)) {
-      seqId = flushedSequenceIdByRegion.get(regionName);
+  public long getLastFlushedSequenceId(byte[] encodedRegionName) {
+    long seqId = -1L;
+    if (flushedSequenceIdByRegion.containsKey(encodedRegionName)) {
+      seqId = flushedSequenceIdByRegion.get(encodedRegionName);
     }
     return seqId;
   }

http://git-wip-us.apache.org/repos/asf/hbase/blob/9fa74b33/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
index 2fafcd5..80844a9 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
@@ -2134,15 +2134,15 @@ public class HRegionServer implements ClientProtos.ClientService.BlockingInterfa
   }
 
   @Override
-  public long getLastSequenceId(byte[] region) {
-    Long lastFlushedSequenceId = -1l;
+  public long getLastSequenceId(byte[] encodedRegionName) {
+    long lastFlushedSequenceId = -1L;
     try {
       GetLastFlushedSequenceIdRequest req = RequestConverter
-          .buildGetLastFlushedSequenceIdRequest(region);
+          .buildGetLastFlushedSequenceIdRequest(encodedRegionName);
       lastFlushedSequenceId = rssStub.getLastFlushedSequenceId(null, req)
           .getLastFlushedSequenceId();
     } catch (ServiceException e) {
-      lastFlushedSequenceId = -1l;
+      lastFlushedSequenceId = -1L;
       LOG.warn("Unable to connect to the master to check " + "the last flushed sequence id",
e);
     }
     return lastFlushedSequenceId;

http://git-wip-us.apache.org/repos/asf/hbase/blob/9fa74b33/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/LastSequenceId.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/LastSequenceId.java
b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/LastSequenceId.java
index 51856e3..98f0985 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/LastSequenceId.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/LastSequenceId.java
@@ -26,8 +26,8 @@ import org.apache.hadoop.hbase.classification.InterfaceAudience;
 @InterfaceAudience.Private
 public interface LastSequenceId {
   /**
-   * @param regionName Encoded region name
-   * @return Last flushed sequence Id for regionName or -1 if it can't be determined
+   * @param encodedRegionName Encoded region name
+   * @return Last flushed sequence Id for region or -1 if it can't be determined
    */
-  long getLastSequenceId(byte[] regionName);
+  long getLastSequenceId(byte[] encodedRegionName);
 }

http://git-wip-us.apache.org/repos/asf/hbase/blob/9fa74b33/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestGetLastFlushedSequenceId.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestGetLastFlushedSequenceId.java
b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestGetLastFlushedSequenceId.java
new file mode 100644
index 0000000..4409259
--- /dev/null
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/master/TestGetLastFlushedSequenceId.java
@@ -0,0 +1,97 @@
+/**
+ * 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.master;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.hadoop.hbase.HBaseTestingUtility;
+import org.apache.hadoop.hbase.HConstants;
+import org.apache.hadoop.hbase.MiniHBaseCluster;
+import org.apache.hadoop.hbase.NamespaceDescriptor;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.client.HTable;
+import org.apache.hadoop.hbase.client.Put;
+import org.apache.hadoop.hbase.regionserver.HRegion;
+import org.apache.hadoop.hbase.regionserver.HRegionServer;
+import org.apache.hadoop.hbase.testclassification.MediumTests;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.hadoop.hbase.util.JVMClusterUtil;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+/**
+ * Trivial test to confirm that we can get last flushed sequence id by encodedRegionName.
See
+ * HBASE-12715.
+ */
+@Category(MediumTests.class)
+public class TestGetLastFlushedSequenceId {
+
+  private final HBaseTestingUtility testUtil = new HBaseTestingUtility();
+
+  private final TableName tableName = TableName.valueOf(getClass().getSimpleName(), "test");
+
+  private final byte[] family = Bytes.toBytes("f1");
+
+  private final byte[][] families = new byte[][] { family };
+
+  @Before
+  public void setUp() throws Exception {
+    testUtil.getConfiguration().setInt("hbase.regionserver.msginterval", 1000);
+    testUtil.startMiniCluster(1, 1);
+  }
+
+  @After
+  public void tearDown() throws Exception {
+    testUtil.shutdownMiniCluster();
+  }
+
+  @Test
+  public void test() throws IOException, InterruptedException {
+    testUtil.getHBaseAdmin().createNamespace(
+      NamespaceDescriptor.create(tableName.getNamespaceAsString()).build());
+    HTable table = testUtil.createTable(tableName, families);
+    table.put(new Put(Bytes.toBytes("k")).add(family, Bytes.toBytes("q"), Bytes.toBytes("v")));
+    table.flushCommits();
+    MiniHBaseCluster cluster = testUtil.getMiniHBaseCluster();
+    List<JVMClusterUtil.RegionServerThread> rsts = cluster.getRegionServerThreads();
+    HRegion region = null;
+    for (int i = 0; i < cluster.getRegionServerThreads().size(); i++) {
+      HRegionServer hrs = rsts.get(i).getRegionServer();
+      for (HRegion r : hrs.getOnlineRegions(tableName)) {
+        region = r;
+        break;
+      }
+    }
+    assertNotNull(region);
+    Thread.sleep(2000);
+    assertEquals(HConstants.NO_SEQNUM, testUtil.getHBaseCluster().getMaster().getServerManager()
+        .getLastFlushedSequenceId(region.getRegionInfo().getEncodedNameAsBytes()));
+    testUtil.getHBaseAdmin().flush(tableName.getName());
+    Thread.sleep(2000);
+    assertTrue(testUtil.getHBaseCluster().getMaster().getServerManager()
+        .getLastFlushedSequenceId(region.getRegionInfo().getEncodedNameAsBytes()) > 0);
+    table.close();
+  }
+}


Mime
View raw message