HBASE-12715 getLastSequenceId always returns -1 (Duo Zhang)

This commit is contained in:
tedyu 2014-12-19 06:58:16 -08:00
parent d436559378
commit cfd7584eef
5 changed files with 116 additions and 19 deletions

View File

@ -22,7 +22,6 @@ import java.io.IOException;
import java.net.InetAddress;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@ -270,8 +269,8 @@ public class MasterRpcServices extends RSRpcServices
} catch (IOException ioe) {
throw new ServiceException(ioe);
}
byte[] regionName = request.getRegionName().toByteArray();
long seqId = master.serverManager.getLastFlushedSequenceId(regionName);
byte[] encodedRegionName = request.getRegionName().toByteArray();
long seqId = master.serverManager.getLastFlushedSequenceId(encodedRegionName);
return ResponseConverter.buildGetLastFlushedSequenceIdResponse(seqId);
}

View File

@ -93,7 +93,6 @@ import com.google.protobuf.ServiceException;
* and has completed the handling.
*/
@InterfaceAudience.Private
@SuppressWarnings("deprecation")
public class ServerManager {
public static final String WAIT_ON_REGIONSERVERS_MAXTOSTART =
"hbase.master.wait.on.regionservers.maxtostart";
@ -255,7 +254,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) {
@ -265,11 +265,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);
}
}
@ -408,10 +407,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;
}

View File

@ -2161,11 +2161,11 @@ public class HRegionServer extends HasThread implements
}
@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);
RegionServerStatusService.BlockingInterface rss = rssStub;
if (rss == null) { // Try to connect one more time
createRegionServerStatusStub();
@ -2174,7 +2174,7 @@ public class HRegionServer extends HasThread implements
// Still no luck, we tried
LOG.warn("Unable to connect to the master to check "
+ "the last flushed sequence id");
return -1l;
return -1L;
}
}
lastFlushedSequenceId = rss.getLastFlushedSequenceId(null, req)

View File

@ -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);
}

View File

@ -0,0 +1,99 @@
/**
* 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()
.getLastSequenceId(region.getRegionInfo().getEncodedNameAsBytes()));
testUtil.getHBaseAdmin().flush(tableName);
Thread.sleep(2000);
assertTrue(testUtil.getHBaseCluster().getMaster()
.getLastSequenceId(region.getRegionInfo().getEncodedNameAsBytes()) > 0);
table.close();
}
}