HBASE-19900 Region-level exception destroy the result of batch
This commit is contained in:
parent
5fa64fb72e
commit
0cbb19201c
@ -1357,6 +1357,10 @@ class AsyncProcess {
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
long getActionsInProgress() {
|
||||
return actionsInProgress.get();
|
||||
}
|
||||
/**
|
||||
* Called when we receive the result of a server query.
|
||||
*
|
||||
@ -1378,32 +1382,47 @@ class AsyncProcess {
|
||||
List<Action<Row>> toReplay = new ArrayList<Action<Row>>();
|
||||
Throwable throwable = null;
|
||||
int failureCount = 0;
|
||||
boolean canRetry = true;
|
||||
Retry retry = null;
|
||||
|
||||
Map<byte[], MultiResponse.RegionResult> results = responses.getResults();
|
||||
updateStats(server, results);
|
||||
|
||||
int failed = 0, stopped = 0;
|
||||
int failed = 0;
|
||||
int stopped = 0;
|
||||
// Go by original action.
|
||||
for (Map.Entry<byte[], List<Action<Row>>> regionEntry : multiAction.actions.entrySet()) {
|
||||
byte[] regionName = regionEntry.getKey();
|
||||
Map<Integer, Object> regionResults = results.get(regionName) == null
|
||||
? null : results.get(regionName).result;
|
||||
if (regionResults == null) {
|
||||
if (!responses.getExceptions().containsKey(regionName)) {
|
||||
LOG.error("Server sent us neither results nor exceptions for "
|
||||
+ Bytes.toStringBinary(regionName));
|
||||
responses.getExceptions().put(regionName, new RuntimeException("Invalid response"));
|
||||
}
|
||||
continue;
|
||||
Throwable regionException = responses.getExceptions().get(regionName);
|
||||
if (tableName == null && ClientExceptionsUtil.isMetaClearingException(regionException)) {
|
||||
// For multi-actions, we don't have a table name, but we want to make sure to clear the
|
||||
// cache in case there were location-related exceptions. We don't to clear the cache
|
||||
// for every possible exception that comes through, however.
|
||||
connection.clearCaches(server);
|
||||
}
|
||||
Map<Integer, Object> regionResults;
|
||||
if (results.containsKey(regionName)) {
|
||||
regionResults = results.get(regionName).result;
|
||||
} else {
|
||||
regionResults = Collections.emptyMap();
|
||||
}
|
||||
boolean regionFailureRegistered = false;
|
||||
for (Action<Row> sentAction : regionEntry.getValue()) {
|
||||
Object result = regionResults.get(sentAction.getOriginalIndex());
|
||||
if (result == null) {
|
||||
if (regionException == null) {
|
||||
LOG.error("Server sent us neither results nor exceptions for " + Bytes
|
||||
.toStringBinary(regionName) + ", numAttempt:" + numAttempt);
|
||||
regionException = new RuntimeException("Invalid response");
|
||||
}
|
||||
// If the row operation encounters the region-lever error, the exception of action
|
||||
// may be null.
|
||||
result = regionException;
|
||||
}
|
||||
// Failure: retry if it's make sense else update the errors lists
|
||||
if (result == null || result instanceof Throwable) {
|
||||
if (result instanceof Throwable) {
|
||||
Row row = sentAction.getAction();
|
||||
throwable = ClientExceptionsUtil.findException(result);
|
||||
throwable = regionException != null ? regionException
|
||||
: ClientExceptionsUtil.findException(result);
|
||||
// Register corresponding failures once per server/once per region.
|
||||
if (!regionFailureRegistered) {
|
||||
regionFailureRegistered = true;
|
||||
@ -1416,20 +1435,24 @@ class AsyncProcess {
|
||||
LOG.error("Couldn't update cached region locations: " + ex);
|
||||
}
|
||||
}
|
||||
if (failureCount == 0) {
|
||||
if (retry == null) {
|
||||
errorsByServer.reportServerError(server);
|
||||
// We determine canRetry only once for all calls, after reporting server failure.
|
||||
canRetry = errorsByServer.canRetryMore(numAttempt);
|
||||
retry =
|
||||
errorsByServer.canRetryMore(numAttempt) ? Retry.YES : Retry.NO_RETRIES_EXHAUSTED;
|
||||
}
|
||||
++failureCount;
|
||||
Retry retry = manageError(sentAction.getOriginalIndex(), row,
|
||||
canRetry ? Retry.YES : Retry.NO_RETRIES_EXHAUSTED, (Throwable) result, server);
|
||||
if (retry == Retry.YES) {
|
||||
toReplay.add(sentAction);
|
||||
} else if (retry == Retry.NO_OTHER_SUCCEEDED) {
|
||||
++stopped;
|
||||
} else {
|
||||
++failed;
|
||||
switch (manageError(sentAction.getOriginalIndex(), row, retry, (Throwable) result,
|
||||
server)) {
|
||||
case YES:
|
||||
toReplay.add(sentAction);
|
||||
break;
|
||||
case NO_OTHER_SUCCEEDED:
|
||||
++stopped;
|
||||
break;
|
||||
default:
|
||||
++failed;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if (callback != null) {
|
||||
@ -1446,52 +1469,6 @@ class AsyncProcess {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The failures global to a region. We will use for multiAction we sent previously to find the
|
||||
// actions to replay.
|
||||
for (Map.Entry<byte[], Throwable> throwableEntry : responses.getExceptions().entrySet()) {
|
||||
throwable = throwableEntry.getValue();
|
||||
byte[] region = throwableEntry.getKey();
|
||||
List<Action<Row>> actions = multiAction.actions.get(region);
|
||||
if (actions == null || actions.isEmpty()) {
|
||||
throw new IllegalStateException("Wrong response for the region: " +
|
||||
HRegionInfo.encodeRegionName(region));
|
||||
}
|
||||
|
||||
if (failureCount == 0) {
|
||||
errorsByServer.reportServerError(server);
|
||||
canRetry = errorsByServer.canRetryMore(numAttempt);
|
||||
}
|
||||
if (null == tableName && ClientExceptionsUtil.isMetaClearingException(throwable)) {
|
||||
// For multi-actions, we don't have a table name, but we want to make sure to clear the
|
||||
// cache in case there were location-related exceptions. We don't to clear the cache
|
||||
// for every possible exception that comes through, however.
|
||||
connection.clearCaches(server);
|
||||
} else {
|
||||
try {
|
||||
connection.updateCachedLocations(
|
||||
tableName, region, actions.get(0).getAction().getRow(), throwable, server);
|
||||
} catch (Throwable ex) {
|
||||
// That should never happen, but if it did, we want to make sure
|
||||
// we still process errors
|
||||
LOG.error("Couldn't update cached region locations: " + ex);
|
||||
}
|
||||
}
|
||||
failureCount += actions.size();
|
||||
|
||||
for (Action<Row> action : actions) {
|
||||
Row row = action.getAction();
|
||||
Retry retry = manageError(action.getOriginalIndex(), row,
|
||||
canRetry ? Retry.YES : Retry.NO_RETRIES_EXHAUSTED, throwable, server);
|
||||
if (retry == Retry.YES) {
|
||||
toReplay.add(action);
|
||||
} else if (retry == Retry.NO_OTHER_SUCCEEDED) {
|
||||
++stopped;
|
||||
} else {
|
||||
++failed;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (toReplay.isEmpty()) {
|
||||
logNoResubmit(server, numAttempt, failureCount, throwable, failed, stopped);
|
||||
} else {
|
||||
|
@ -0,0 +1,238 @@
|
||||
/**
|
||||
* 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.client;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InterruptedIOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Executors;
|
||||
import org.apache.hadoop.conf.Configuration;
|
||||
import org.apache.hadoop.hbase.HConstants;
|
||||
import org.apache.hadoop.hbase.HRegionInfo;
|
||||
import org.apache.hadoop.hbase.HRegionLocation;
|
||||
import org.apache.hadoop.hbase.RegionLocations;
|
||||
import org.apache.hadoop.hbase.ServerName;
|
||||
import org.apache.hadoop.hbase.TableName;
|
||||
import org.apache.hadoop.hbase.ipc.RpcControllerFactory;
|
||||
import org.apache.hadoop.hbase.testclassification.ClientTests;
|
||||
import org.apache.hadoop.hbase.testclassification.SmallTests;
|
||||
import org.apache.hadoop.hbase.util.Bytes;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
/**
|
||||
* The purpose of this test is to make sure the region exception won't corrupt the results
|
||||
* of batch. The prescription is shown below.
|
||||
* 1) honor the action result rather than region exception. If the action have both of true result
|
||||
* and region exception, the action is fine as the exception is caused by other actions
|
||||
* which are in the same region.
|
||||
* 2) honor the action exception rather than region exception. If the action have both of action
|
||||
* exception and region exception, we deal with the action exception only. If we also
|
||||
* handle the region exception for the same action, it will introduce the negative count of
|
||||
* actions in progress. The AsyncRequestFuture#waitUntilDone will block forever.
|
||||
*
|
||||
* This bug can be reproduced by real use case. see TestMalformedCellFromClient(in branch-1.4+).
|
||||
* It uses the batch of RowMutations to present the bug. Given that the batch of RowMutations is
|
||||
* only supported by branch-1.4+, perhaps the branch-1.3 and branch-1.2 won't encounter this issue.
|
||||
* We still backport the fix to branch-1.3 and branch-1.2 in case we ignore some write paths.
|
||||
*/
|
||||
@Category({ ClientTests.class, SmallTests.class })
|
||||
public class TestAsyncProcessWithRegionException {
|
||||
|
||||
private static final Result EMPTY_RESULT = Result.create(null, true);
|
||||
private static final IOException IOE = new IOException("YOU CAN'T PASS");
|
||||
private static final Configuration CONF = new Configuration();
|
||||
private static final TableName DUMMY_TABLE = TableName.valueOf("DUMMY_TABLE");
|
||||
private static final byte[] GOOD_ROW = Bytes.toBytes("GOOD_ROW");
|
||||
private static final byte[] BAD_ROW = Bytes.toBytes("BAD_ROW");
|
||||
private static final byte[] BAD_ROW_WITHOUT_ACTION_EXCEPTION =
|
||||
Bytes.toBytes("BAD_ROW_WITHOUT_ACTION_EXCEPTION");
|
||||
private static final byte[] FAMILY = Bytes.toBytes("FAMILY");
|
||||
private static final ServerName SERVER_NAME = ServerName.valueOf("s1,1,1");
|
||||
private static final HRegionInfo REGION_INFO
|
||||
= new HRegionInfo(DUMMY_TABLE, HConstants.EMPTY_START_ROW, HConstants.EMPTY_END_ROW);
|
||||
|
||||
private static final HRegionLocation REGION_LOCATION =
|
||||
new HRegionLocation(REGION_INFO, SERVER_NAME);
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() {
|
||||
// disable the retry
|
||||
CONF.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 1);
|
||||
}
|
||||
|
||||
@Test(timeout=20000)
|
||||
public void testSuccessivePut() throws Exception {
|
||||
MyAsyncProcess ap = new MyAsyncProcess(createHConnection(), CONF);
|
||||
|
||||
List<Put> puts = new ArrayList<>(1);
|
||||
puts.add(new Put(GOOD_ROW).addColumn(FAMILY, FAMILY, FAMILY));
|
||||
final int expectedSize = puts.size();
|
||||
AsyncProcess.AsyncRequestFuture arf = ap.submit(DUMMY_TABLE, puts);
|
||||
arf.waitUntilDone();
|
||||
Object[] result = arf.getResults();
|
||||
assertEquals(expectedSize, result.length);
|
||||
for (Object r : result) {
|
||||
assertEquals(Result.class, r.getClass());
|
||||
}
|
||||
assertTrue(puts.isEmpty());
|
||||
assertActionsInProgress(arf);
|
||||
}
|
||||
|
||||
@Test(timeout=20000)
|
||||
public void testFailedPut() throws Exception {
|
||||
MyAsyncProcess ap = new MyAsyncProcess(createHConnection(), CONF);
|
||||
|
||||
List<Put> puts = new ArrayList<>(2);
|
||||
puts.add(new Put(GOOD_ROW).addColumn(FAMILY, FAMILY, FAMILY));
|
||||
// this put should fail
|
||||
puts.add(new Put(BAD_ROW).addColumn(FAMILY, FAMILY, FAMILY));
|
||||
final int expectedSize = puts.size();
|
||||
|
||||
AsyncProcess.AsyncRequestFuture arf = ap.submit(DUMMY_TABLE, puts);
|
||||
arf.waitUntilDone();
|
||||
// There is a failed puts
|
||||
assertError(arf, 1);
|
||||
Object[] result = arf.getResults();
|
||||
assertEquals(expectedSize, result.length);
|
||||
assertEquals(Result.class, result[0].getClass());
|
||||
assertTrue(result[1] instanceof IOException);
|
||||
assertTrue(puts.isEmpty());
|
||||
assertActionsInProgress(arf);
|
||||
}
|
||||
|
||||
@Test(timeout=20000)
|
||||
public void testFailedPutWithoutActionException() throws Exception {
|
||||
MyAsyncProcess ap = new MyAsyncProcess(createHConnection(), CONF);
|
||||
|
||||
List<Put> puts = new ArrayList<>(3);
|
||||
puts.add(new Put(GOOD_ROW).addColumn(FAMILY, FAMILY, FAMILY));
|
||||
// this put should fail
|
||||
puts.add(new Put(BAD_ROW).addColumn(FAMILY, FAMILY, FAMILY));
|
||||
// this put should fail, and it won't have action exception
|
||||
puts.add(new Put(BAD_ROW_WITHOUT_ACTION_EXCEPTION).addColumn(FAMILY, FAMILY, FAMILY));
|
||||
final int expectedSize = puts.size();
|
||||
|
||||
AsyncProcess.AsyncRequestFuture arf = ap.submit(DUMMY_TABLE, puts);
|
||||
arf.waitUntilDone();
|
||||
// There are two failed puts
|
||||
assertError(arf, 2);
|
||||
Object[] result = arf.getResults();
|
||||
assertEquals(expectedSize, result.length);
|
||||
assertEquals(Result.class, result[0].getClass());
|
||||
assertTrue(result[1] instanceof IOException);
|
||||
assertTrue(result[2] instanceof IOException);
|
||||
assertTrue(puts.isEmpty());
|
||||
assertActionsInProgress(arf);
|
||||
}
|
||||
|
||||
private static void assertError(AsyncProcess.AsyncRequestFuture arf, int expectedCountOfFailure) {
|
||||
assertTrue(arf.hasError());
|
||||
RetriesExhaustedWithDetailsException e = arf.getErrors();
|
||||
List<Throwable> errors = e.getCauses();
|
||||
assertEquals(expectedCountOfFailure, errors.size());
|
||||
for (Throwable t : errors) {
|
||||
assertTrue(t instanceof IOException);
|
||||
}
|
||||
}
|
||||
|
||||
private static void assertActionsInProgress(AsyncProcess.AsyncRequestFuture arf) {
|
||||
if (arf instanceof AsyncProcess.AsyncRequestFutureImpl) {
|
||||
assertEquals(0, ((AsyncProcess.AsyncRequestFutureImpl) arf).getActionsInProgress());
|
||||
}
|
||||
}
|
||||
|
||||
private static ClusterConnection createHConnection() throws IOException {
|
||||
ClusterConnection hc = Mockito.mock(ClusterConnection.class);
|
||||
NonceGenerator ng = Mockito.mock(NonceGenerator.class);
|
||||
Mockito.when(ng.getNonceGroup()).thenReturn(HConstants.NO_NONCE);
|
||||
Mockito.when(hc.getNonceGenerator()).thenReturn(ng);
|
||||
Mockito.when(hc.getConfiguration()).thenReturn(CONF);
|
||||
Mockito.when(hc.getConnectionConfiguration()).thenReturn(new ConnectionConfiguration(CONF));
|
||||
setMockLocation(hc, GOOD_ROW, new RegionLocations(REGION_LOCATION));
|
||||
setMockLocation(hc, BAD_ROW, new RegionLocations(REGION_LOCATION));
|
||||
Mockito
|
||||
.when(hc.locateRegions(Mockito.eq(DUMMY_TABLE), Mockito.anyBoolean(), Mockito.anyBoolean()))
|
||||
.thenReturn(Collections.singletonList(REGION_LOCATION));
|
||||
return hc;
|
||||
}
|
||||
|
||||
private static void setMockLocation(ClusterConnection hc, byte[] row, RegionLocations result)
|
||||
throws IOException {
|
||||
Mockito.when(hc.locateRegion(Mockito.eq(DUMMY_TABLE), Mockito.eq(row), Mockito.anyBoolean(),
|
||||
Mockito.anyBoolean(), Mockito.anyInt())).thenReturn(result);
|
||||
Mockito.when(hc.locateRegion(Mockito.eq(DUMMY_TABLE), Mockito.eq(row), Mockito.anyBoolean(),
|
||||
Mockito.anyBoolean())).thenReturn(result);
|
||||
}
|
||||
|
||||
private static class MyAsyncProcess extends AsyncProcess {
|
||||
|
||||
MyAsyncProcess(ClusterConnection hc, Configuration conf) {
|
||||
super(hc, conf, Executors.newFixedThreadPool(5),
|
||||
new RpcRetryingCallerFactory(conf), false, new RpcControllerFactory(conf),
|
||||
HConstants.DEFAULT_HBASE_RPC_TIMEOUT);
|
||||
}
|
||||
|
||||
public AsyncRequestFuture submit(TableName tableName, List<? extends Row> rows)
|
||||
throws InterruptedIOException {
|
||||
return super.submit(tableName, rows, true, null, true);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected RpcRetryingCaller<MultiResponse> createCaller(PayloadCarryingServerCallable callable,
|
||||
int rpcTimeout) {
|
||||
MultiServerCallable<Row> callable1 = (MultiServerCallable<Row>) callable;
|
||||
final MultiResponse mr = new MultiResponse();
|
||||
for (Map.Entry<byte[], List<Action<Row>>> entry : callable1.getMulti().actions.entrySet()) {
|
||||
byte[] regionName = entry.getKey();
|
||||
for (Action<Row> action : entry.getValue()) {
|
||||
if (Bytes.equals(action.getAction().getRow(), GOOD_ROW)) {
|
||||
mr.add(regionName, action.getOriginalIndex(), EMPTY_RESULT);
|
||||
} else if (Bytes.equals(action.getAction().getRow(), BAD_ROW)) {
|
||||
mr.add(regionName, action.getOriginalIndex(), IOE);
|
||||
}
|
||||
}
|
||||
}
|
||||
mr.addException(REGION_INFO.getRegionName(), IOE);
|
||||
|
||||
return new RpcRetryingCaller<MultiResponse>(100, 500, 0, 0) {
|
||||
@Override
|
||||
public MultiResponse callWithoutRetries(RetryingCallable<MultiResponse> callable,
|
||||
int callTimeout) {
|
||||
try {
|
||||
// sleep one second in order for threadpool to start another thread instead of reusing
|
||||
// existing one.
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
// pass
|
||||
}
|
||||
return mr;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,134 @@
|
||||
/**
|
||||
* 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.client;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.apache.hadoop.hbase.Cell;
|
||||
import org.apache.hadoop.hbase.CellUtil;
|
||||
import org.apache.hadoop.hbase.HBaseTestingUtility;
|
||||
import org.apache.hadoop.hbase.HColumnDescriptor;
|
||||
import org.apache.hadoop.hbase.HConstants;
|
||||
import org.apache.hadoop.hbase.HTableDescriptor;
|
||||
import org.apache.hadoop.hbase.TableName;
|
||||
import org.apache.hadoop.hbase.regionserver.HRegion;
|
||||
import org.apache.hadoop.hbase.testclassification.ClientTests;
|
||||
import org.apache.hadoop.hbase.testclassification.MediumTests;
|
||||
import org.apache.hadoop.hbase.util.Bytes;
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.experimental.categories.Category;
|
||||
|
||||
/**
|
||||
* The purpose of this test is to make sure the region exception won't corrupt the results
|
||||
* of batch. The prescription is shown below.
|
||||
* 1) honor the action result rather than region exception. If the action have both of true result
|
||||
* and region exception, the action is fine as the exception is caused by other actions
|
||||
* which are in the same region.
|
||||
* 2) honor the action exception rather than region exception. If the action have both of action
|
||||
* exception and region exception, we deal with the action exception only. If we also
|
||||
* handle the region exception for the same action, it will introduce the negative count of
|
||||
* actions in progress. The AsyncRequestFuture#waitUntilDone will block forever.
|
||||
*
|
||||
* The no-cluster test is in TestAsyncProcessWithRegionException.
|
||||
*/
|
||||
@Category({ MediumTests.class, ClientTests.class })
|
||||
public class TestMalformedCellFromClient {
|
||||
|
||||
private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
|
||||
private static final byte[] FAMILY = Bytes.toBytes("testFamily");
|
||||
private static final int CELL_SIZE = 100;
|
||||
private static final TableName TABLE_NAME = TableName.valueOf("TestMalformedCellFromClient");
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
// disable the retry
|
||||
TEST_UTIL.getConfiguration().setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 1);
|
||||
TEST_UTIL.startMiniCluster(1);
|
||||
}
|
||||
|
||||
@Before
|
||||
public void before() throws Exception {
|
||||
HTableDescriptor desc = new HTableDescriptor(TABLE_NAME)
|
||||
.addFamily(new HColumnDescriptor(FAMILY))
|
||||
.setValue(HRegion.HBASE_MAX_CELL_SIZE_KEY, String.valueOf(CELL_SIZE));
|
||||
TEST_UTIL.getConnection().getAdmin().createTable(desc);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
for (HTableDescriptor htd : TEST_UTIL.getHBaseAdmin().listTables()) {
|
||||
TEST_UTIL.deleteTable(htd.getTableName());
|
||||
}
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDownAfterClass() throws Exception {
|
||||
TEST_UTIL.shutdownMiniCluster();
|
||||
}
|
||||
|
||||
/**
|
||||
* The purpose of this ut is to check the consistency between the exception and results.
|
||||
* If the RetriesExhaustedWithDetailsException contains the whole batch,
|
||||
* each result should be of IOE. Otherwise, the row operation which is not in the exception
|
||||
* should have a true result.
|
||||
*/
|
||||
@Test(timeout=60000)
|
||||
public void testRegionException() throws InterruptedException, IOException {
|
||||
List<Row> batches = new ArrayList<>();
|
||||
batches.add(new Put(Bytes.toBytes("good")).addColumn(FAMILY, null, new byte[10]));
|
||||
// the rm is used to prompt the region exception.
|
||||
// see RSRpcServices#multi
|
||||
RowMutations rm = new RowMutations(Bytes.toBytes("fail"));
|
||||
rm.add(new Put(rm.getRow()).addColumn(FAMILY, null, new byte[CELL_SIZE]));
|
||||
batches.add(rm);
|
||||
Object[] results = new Object[batches.size()];
|
||||
|
||||
try (Table table = TEST_UTIL.getConnection().getTable(TABLE_NAME)) {
|
||||
Throwable exceptionByCaught = null;
|
||||
try {
|
||||
table.batch(batches, results);
|
||||
fail("Where is the exception? We put the malformed cells!!!");
|
||||
} catch (RetriesExhaustedWithDetailsException e) {
|
||||
for (Throwable throwable : e.getCauses()) {
|
||||
assertNotNull(throwable);
|
||||
}
|
||||
assertEquals(1, e.getNumExceptions());
|
||||
exceptionByCaught = e.getCause(0);
|
||||
}
|
||||
for (Object obj : results) {
|
||||
assertNotNull(obj);
|
||||
}
|
||||
assertEquals(Result.class, results[0].getClass());
|
||||
assertEquals(exceptionByCaught.getClass(), results[1].getClass());
|
||||
Result result = table.get(new Get(Bytes.toBytes("good")));
|
||||
assertEquals(1, result.size());
|
||||
Cell cell = result.getColumnLatestCell(FAMILY, null);
|
||||
assertTrue(Bytes.equals(CellUtil.cloneValue(cell), new byte[10]));
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user