@Override public void onException(RetriesExhaustedWithDetailsException e, BufferedMutator mutator) { for (int i = 0; i < e.getNumExceptions(); i++) { LOG.info("Failed to sent put " + e.getRow(i) + "."); } } };
assertNotNull(e.getCause(i)); assertEquals(DoNotRetryIOException.class, e.getCause(i).getClass()); assertEquals("fail", Bytes.toString(e.getRow(i).getRow()));
assertNotNull(e.getCause(i)); assertTrue(e.getCause(i) instanceof IOException); assertEquals("fail", Bytes.toString(e.getRow(i).getRow()));
@Test public void testErrors() throws IOException { ClusterConnection conn = new MyConnectionImpl(CONF); AsyncProcessWithFailure ap = new AsyncProcessWithFailure(conn, CONF, new IOException("test")); BufferedMutatorParams bufferParam = createBufferedMutatorParams(ap, DUMMY_TABLE); BufferedMutatorImpl mutator = new BufferedMutatorImpl(conn, bufferParam, ap); Assert.assertNotNull(ap.createServerErrorTracker()); Put p = createPut(1, true); mutator.mutate(p); try { mutator.flush(); Assert.fail(); } catch (RetriesExhaustedWithDetailsException expected) { assertEquals(1, expected.getNumExceptions()); assertTrue(expected.getRow(0) == p); } // Checking that the ErrorsServers came into play and didn't make us stop immediately Assert.assertEquals(NB_RETRIES + 1, ap.callsCt.get()); }
@Test public void testErrorsServers() throws IOException { Configuration configuration = new Configuration(CONF); ClusterConnection conn = new MyConnectionImpl(configuration); MyAsyncProcess ap = new MyAsyncProcess(conn, configuration); BufferedMutatorParams bufferParam = createBufferedMutatorParams(ap, DUMMY_TABLE); BufferedMutatorImpl mutator = new BufferedMutatorImpl(conn, bufferParam, ap); configuration.setBoolean(ConnectionImplementation.RETRIES_BY_SERVER_KEY, true); Assert.assertNotNull(ap.createServerErrorTracker()); Assert.assertTrue(ap.serverTrackerTimeout > 200L); ap.serverTrackerTimeout = 1L; Put p = createPut(1, false); mutator.mutate(p); try { mutator.flush(); Assert.fail(); } catch (RetriesExhaustedWithDetailsException expected) { assertEquals(1, expected.getNumExceptions()); assertTrue(expected.getRow(0) == p); } // Checking that the ErrorsServers came into play and didn't make us stop immediately Assert.assertEquals(NB_RETRIES + 1, ap.callsCt.get()); }
@Test public void testRetryWithExceptionClearsMetaCache() throws Exception { ClusterConnection conn = createHConnection(); Configuration myConf = conn.getConfiguration(); myConf.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 0); AsyncProcessWithFailure ap = new AsyncProcessWithFailure(conn, myConf, new RegionOpeningException("test")); BufferedMutatorParams bufferParam = createBufferedMutatorParams(ap, DUMMY_TABLE); BufferedMutatorImpl mutator = new BufferedMutatorImpl(conn, bufferParam, ap); Assert.assertNotNull(mutator.getAsyncProcess().createServerErrorTracker()); Assert.assertEquals( conn.locateRegion(DUMMY_TABLE, DUMMY_BYTES_1, true, true).toString(), new RegionLocations(loc1).toString()); Mockito.verify(conn, Mockito.times(0)).clearCaches(Mockito.any()); Put p = createPut(1, true); mutator.mutate(p); try { mutator.flush(); Assert.fail(); } catch (RetriesExhaustedWithDetailsException expected) { assertEquals(1, expected.getNumExceptions()); assertTrue(expected.getRow(0) == p); } Mockito.verify(conn, Mockito.times(1)).clearCaches(loc1.getServerName()); }
@Override public void onException(RetriesExhaustedWithDetailsException e, BufferedMutator mutator) { for (int i = 0; i < e.getNumExceptions(); i++) { // co BufferedMutatorExample-02-OnException Handle callback in case of an exception. LOG.info("Failed to send put: " + e.getRow(i)); // co BufferedMutatorExample-03-PrintRow Generically retrieve the mutation that failed, using the common superclass. } } };
@Test public void testCallQueueTooLarge() throws IOException { ClusterConnection conn = new MyConnectionImpl(CONF); AsyncProcessWithFailure ap = new AsyncProcessWithFailure(conn, CONF, new CallQueueTooBigException()); BufferedMutatorParams bufferParam = createBufferedMutatorParams(ap, DUMMY_TABLE); BufferedMutatorImpl mutator = new BufferedMutatorImpl(conn, bufferParam, ap); Assert.assertNotNull(ap.createServerErrorTracker()); Put p = createPut(1, true); mutator.mutate(p); try { mutator.flush(); Assert.fail(); } catch (RetriesExhaustedWithDetailsException expected) { assertEquals(1, expected.getNumExceptions()); assertTrue(expected.getRow(0) == p); } // Checking that the ErrorsServers came into play and didn't make us stop immediately Assert.assertEquals(NB_RETRIES + 1, ap.callsCt.get()); } /**
@Test public void testFailedPutAndNewPut() throws Exception { ClusterConnection conn = createHConnection(); MyAsyncProcess ap = new MyAsyncProcess(conn, CONF); BufferedMutatorParams bufferParam = createBufferedMutatorParams(ap, DUMMY_TABLE) .writeBufferSize(0); BufferedMutatorImpl mutator = new BufferedMutatorImpl(conn, bufferParam, ap); Put p = createPut(1, false); try { mutator.mutate(p); Assert.fail(); } catch (RetriesExhaustedWithDetailsException expected) { assertEquals(1, expected.getNumExceptions()); assertTrue(expected.getRow(0) == p); } // Let's do all the retries. ap.waitForMaximumCurrentTasks(0, null); Assert.assertEquals(0, mutator.size()); // There is no global error so the new put should not fail mutator.mutate(createPut(1, true)); Assert.assertEquals("the put should not been inserted.", 0, mutator.size()); }
Assert.assertEquals(1, e.getNumExceptions()); Assert.assertEquals(1, e.getCauses().size()); Assert.assertArrayEquals(ROW, e.getRow(0).getRow());
System.out.println("Cause[" + n + "]: " + e.getCause(n)); System.out.println("Hostname[" + n + "]: " + e.getHostnamePort(n)); System.out.println("Row[" + n + "]: " + e.getRow(n)); // co PutListErrorExample3-3-ErrorPut Gain access to the failed operation.
@Test public void testReplicaAllCallsFailForOneRegion() throws Exception { // For one of the region, all 3, main and replica, calls fail. For the other, replica // call fails but its exception should not be visible as it did succeed. MyAsyncProcessWithReplicas ap = createReplicaAp(500, 1000, 0, 0); ap.addFailures(hri1, hri1r1, hri1r2, hri2r1); List<Get> rows = makeTimelineGets(DUMMY_BYTES_1, DUMMY_BYTES_2); AsyncProcessTask task = AsyncProcessTask.newBuilder() .setPool(ap.service) .setRpcTimeout(RPC_TIMEOUT) .setOperationTimeout(OPERATION_TIMEOUT) .setTableName(DUMMY_TABLE) .setRowAccess(rows) .setResults(new Object[2]) .setSubmittedRows(SubmittedRows.ALL) .build(); AsyncRequestFuture ars = ap.submit(task); verifyReplicaResult(ars, RR.FAILED, RR.FALSE); // We should get 3 exceptions, for main + 2 replicas for DUMMY_BYTES_1 Assert.assertEquals(3, ars.getErrors().getNumExceptions()); for (int i = 0; i < ars.getErrors().getNumExceptions(); ++i) { Assert.assertArrayEquals(DUMMY_BYTES_1, ars.getErrors().getRow(i).getRow()); } }
@Test public void testErrors() throws IOException { ClusterConnection conn = new MyConnectionImpl(CONF); AsyncProcessWithFailure ap = new AsyncProcessWithFailure(conn, CONF, new IOException("test")); BufferedMutatorParams bufferParam = createBufferedMutatorParams(ap, DUMMY_TABLE); BufferedMutatorImpl mutator = new BufferedMutatorImpl(conn, bufferParam, ap); Assert.assertNotNull(ap.createServerErrorTracker()); Put p = createPut(1, true); mutator.mutate(p); try { mutator.flush(); Assert.fail(); } catch (RetriesExhaustedWithDetailsException expected) { assertEquals(1, expected.getNumExceptions()); assertTrue(expected.getRow(0) == p); } // Checking that the ErrorsServers came into play and didn't make us stop immediately Assert.assertEquals(NB_RETRIES + 1, ap.callsCt.get()); }
@Override public void onException(RetriesExhaustedWithDetailsException e, BufferedMutator mutator) { for (int i = 0; i < e.getNumExceptions(); i++) { LOG.info("Failed to sent put " + e.getRow(i) + "."); } } };
@Test public void testErrorsServers() throws IOException { Configuration configuration = new Configuration(CONF); ClusterConnection conn = new MyConnectionImpl(configuration); MyAsyncProcess ap = new MyAsyncProcess(conn, configuration); BufferedMutatorParams bufferParam = createBufferedMutatorParams(ap, DUMMY_TABLE); BufferedMutatorImpl mutator = new BufferedMutatorImpl(conn, bufferParam, ap); configuration.setBoolean(ConnectionImplementation.RETRIES_BY_SERVER_KEY, true); Assert.assertNotNull(ap.createServerErrorTracker()); Assert.assertTrue(ap.serverTrackerTimeout > 200L); ap.serverTrackerTimeout = 1L; Put p = createPut(1, false); mutator.mutate(p); try { mutator.flush(); Assert.fail(); } catch (RetriesExhaustedWithDetailsException expected) { assertEquals(1, expected.getNumExceptions()); assertTrue(expected.getRow(0) == p); } // Checking that the ErrorsServers came into play and didn't make us stop immediately Assert.assertEquals(NB_RETRIES + 1, ap.callsCt.get()); }
@Test public void testCallQueueTooLarge() throws IOException { ClusterConnection conn = new MyConnectionImpl(CONF); AsyncProcessWithFailure ap = new AsyncProcessWithFailure(conn, CONF, new CallQueueTooBigException()); BufferedMutatorParams bufferParam = createBufferedMutatorParams(ap, DUMMY_TABLE); BufferedMutatorImpl mutator = new BufferedMutatorImpl(conn, bufferParam, ap); Assert.assertNotNull(ap.createServerErrorTracker()); Put p = createPut(1, true); mutator.mutate(p); try { mutator.flush(); Assert.fail(); } catch (RetriesExhaustedWithDetailsException expected) { assertEquals(1, expected.getNumExceptions()); assertTrue(expected.getRow(0) == p); } // Checking that the ErrorsServers came into play and didn't make us stop immediately Assert.assertEquals(NB_RETRIES + 1, ap.callsCt.get()); } /**
@Test public void testFailedPutAndNewPut() throws Exception { ClusterConnection conn = createHConnection(); MyAsyncProcess ap = new MyAsyncProcess(conn, CONF); BufferedMutatorParams bufferParam = createBufferedMutatorParams(ap, DUMMY_TABLE) .writeBufferSize(0); BufferedMutatorImpl mutator = new BufferedMutatorImpl(conn, bufferParam, ap); Put p = createPut(1, false); try { mutator.mutate(p); Assert.fail(); } catch (RetriesExhaustedWithDetailsException expected) { assertEquals(1, expected.getNumExceptions()); assertTrue(expected.getRow(0) == p); } // Let's do all the retries. ap.waitForMaximumCurrentTasks(0, null); Assert.assertEquals(0, mutator.size()); // There is no global error so the new put should not fail mutator.mutate(createPut(1, true)); Assert.assertEquals("the put should not been inserted.", 0, mutator.size()); }
@Test public void testReplicaAllCallsFailForOneRegion() throws Exception { // For one of the region, all 3, main and replica, calls fail. For the other, replica // call fails but its exception should not be visible as it did succeed. MyAsyncProcessWithReplicas ap = createReplicaAp(500, 1000, 0, 0); ap.addFailures(hri1, hri1r1, hri1r2, hri2r1); List<Get> rows = makeTimelineGets(DUMMY_BYTES_1, DUMMY_BYTES_2); AsyncProcessTask task = AsyncProcessTask.newBuilder() .setPool(ap.service) .setRpcTimeout(RPC_TIMEOUT) .setOperationTimeout(OPERATION_TIMEOUT) .setTableName(DUMMY_TABLE) .setRowAccess(rows) .setResults(new Object[2]) .setSubmittedRows(SubmittedRows.ALL) .build(); AsyncRequestFuture ars = ap.submit(task); verifyReplicaResult(ars, RR.FAILED, RR.FALSE); // We should get 3 exceptions, for main + 2 replicas for DUMMY_BYTES_1 Assert.assertEquals(3, ars.getErrors().getNumExceptions()); for (int i = 0; i < ars.getErrors().getNumExceptions(); ++i) { Assert.assertArrayEquals(DUMMY_BYTES_1, ars.getErrors().getRow(i).getRow()); } }