HBASE-15354 Use same criteria for clearing meta cache for all operations (addendum) (Ashu Pachauri)

This commit is contained in:
Mikhail Antonov 2016-03-07 18:07:10 -08:00
parent d15ae0e6ab
commit e477c143bc
1 changed files with 32 additions and 17 deletions

View File

@ -19,8 +19,6 @@ package org.apache.hadoop.hbase.client;
import com.google.protobuf.RpcController; import com.google.protobuf.RpcController;
import com.google.protobuf.ServiceException; import com.google.protobuf.ServiceException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.*; import org.apache.hadoop.hbase.*;
@ -34,6 +32,7 @@ import org.apache.hadoop.hbase.regionserver.RSRpcServices;
import org.apache.hadoop.hbase.testclassification.ClientTests; import org.apache.hadoop.hbase.testclassification.ClientTests;
import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.JVMClusterUtil;
import org.junit.After; import org.junit.After;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.Before; import org.junit.Before;
@ -45,17 +44,19 @@ import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import static junit.framework.Assert.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
@Category({MediumTests.class, ClientTests.class}) @Category({MediumTests.class, ClientTests.class})
public class TestMetaCache { public class TestMetaCache {
private static final Log LOG = LogFactory.getLog(TestMetaCache.class);
private final static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); private final static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
private static final TableName TABLE_NAME = TableName.valueOf("test_table"); private static final TableName TABLE_NAME = TableName.valueOf("test_table");
private static final byte[] FAMILY = Bytes.toBytes("fam1"); private static final byte[] FAMILY = Bytes.toBytes("fam1");
private static final byte[] QUALIFIER = Bytes.toBytes("qual"); private static final byte[] QUALIFIER = Bytes.toBytes("qual");
private ConnectionImplementation conn; private ConnectionImplementation conn;
private HRegionServer badRS;
/** /**
* @throws java.lang.Exception * @throws java.lang.Exception
@ -64,8 +65,9 @@ public class TestMetaCache {
public static void setUpBeforeClass() throws Exception { public static void setUpBeforeClass() throws Exception {
Configuration conf = TEST_UTIL.getConfiguration(); Configuration conf = TEST_UTIL.getConfiguration();
conf.set("hbase.client.retries.number", "1"); conf.set("hbase.client.retries.number", "1");
conf.setStrings(HConstants.REGION_SERVER_IMPL, RegionServerWithFakeRpcServices.class.getName());
TEST_UTIL.startMiniCluster(1); TEST_UTIL.startMiniCluster(1);
TEST_UTIL.getHBaseCluster().waitForActiveAndReadyMaster();
TEST_UTIL.waitUntilAllRegionsAssigned(TABLE_NAME.META_TABLE_NAME);
} }
@ -82,8 +84,21 @@ public class TestMetaCache {
*/ */
@Before @Before
public void setup() throws Exception { public void setup() throws Exception {
conn = (ConnectionImplementation)ConnectionFactory.createConnection( MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
TEST_UTIL.getConfiguration());
cluster.getConfiguration().setStrings(HConstants.REGION_SERVER_IMPL,
RegionServerWithFakeRpcServices.class.getName());
JVMClusterUtil.RegionServerThread rsThread = cluster.startRegionServer();
rsThread.waitForServerOnline();
badRS = rsThread.getRegionServer();
assertTrue(badRS.getRSRpcServices() instanceof FakeRSRpcServices);
cluster.getConfiguration().setStrings(HConstants.REGION_SERVER_IMPL,
HRegionServer.class.getName());
assertEquals(2, cluster.getRegionServerThreads().size());
conn = (ConnectionImplementation) ConnectionFactory.createConnection(
TEST_UTIL.getConfiguration());
HTableDescriptor table = new HTableDescriptor(TABLE_NAME); HTableDescriptor table = new HTableDescriptor(TABLE_NAME);
HColumnDescriptor fam = new HColumnDescriptor(FAMILY); HColumnDescriptor fam = new HColumnDescriptor(FAMILY);
fam.setMaxVersions(2); fam.setMaxVersions(2);
@ -105,7 +120,7 @@ public class TestMetaCache {
@Test @Test
public void testPreserveMetaCacheOnException() throws Exception { public void testPreserveMetaCacheOnException() throws Exception {
Table table = conn.getTable(TABLE_NAME); Table table = conn.getTable(TABLE_NAME);
byte [] row = HBaseTestingUtility.KEYS[2]; byte[] row = badRS.getOnlineRegions().get(0).getRegionInfo().getStartKey();
Put put = new Put(row); Put put = new Put(row);
put.addColumn(FAMILY, QUALIFIER, Bytes.toBytes(10)); put.addColumn(FAMILY, QUALIFIER, Bytes.toBytes(10));
@ -151,19 +166,19 @@ public class TestMetaCache {
public static List<Throwable> metaCachePreservingExceptions() { public static List<Throwable> metaCachePreservingExceptions() {
return new ArrayList<Throwable>() {{ return new ArrayList<Throwable>() {{
add(new RegionOpeningException(" ")); add(new RegionOpeningException(" "));
add(new RegionTooBusyException()); add(new RegionTooBusyException());
add(new ThrottlingException(" ")); add(new ThrottlingException(" "));
add(new MultiActionResultTooLarge(" ")); add(new MultiActionResultTooLarge(" "));
add(new RetryImmediatelyException(" ")); add(new RetryImmediatelyException(" "));
add(new CallQueueTooBigException()); add(new CallQueueTooBigException());
}}; }};
} }
protected static class RegionServerWithFakeRpcServices extends HRegionServer { protected static class RegionServerWithFakeRpcServices extends HRegionServer {
public RegionServerWithFakeRpcServices(Configuration conf, CoordinatedStateManager cp) public RegionServerWithFakeRpcServices(Configuration conf, CoordinatedStateManager cp)
throws IOException, InterruptedException { throws IOException, InterruptedException {
super(conf, cp); super(conf, cp);
} }
@ -185,7 +200,7 @@ public class TestMetaCache {
@Override @Override
public GetResponse get(final RpcController controller, public GetResponse get(final RpcController controller,
final ClientProtos.GetRequest request) throws ServiceException { final ClientProtos.GetRequest request) throws ServiceException {
throwSomeExceptions(); throwSomeExceptions();
return super.get(controller, request); return super.get(controller, request);
} }
@ -224,7 +239,7 @@ public class TestMetaCache {
// single Gets. // single Gets.
expCount++; expCount++;
Throwable t = metaCachePreservingExceptions.get( Throwable t = metaCachePreservingExceptions.get(
expCount % metaCachePreservingExceptions.size()); expCount % metaCachePreservingExceptions.size());
throw new ServiceException(t); throw new ServiceException(t);
} }
} }