Search in sources :

Example 6 with NoSuchColumnFamilyException

use of org.apache.hadoop.hbase.regionserver.NoSuchColumnFamilyException in project hbase by apache.

the class TestFromClientSide5 method testRowMutations.

@Test
public void testRowMutations() throws Exception {
    LOG.info("Starting testRowMutations");
    final TableName tableName = name.getTableName();
    try (Table t = TEST_UTIL.createTable(tableName, FAMILY)) {
        byte[][] QUALIFIERS = new byte[][] { Bytes.toBytes("a"), Bytes.toBytes("b"), Bytes.toBytes("c"), Bytes.toBytes("d") };
        // Test for Put operations
        RowMutations arm = new RowMutations(ROW);
        Put p = new Put(ROW);
        p.addColumn(FAMILY, QUALIFIERS[0], VALUE);
        arm.add(p);
        Result r = t.mutateRow(arm);
        assertTrue(r.getExists());
        assertTrue(r.isEmpty());
        Get g = new Get(ROW);
        r = t.get(g);
        assertEquals(0, Bytes.compareTo(VALUE, r.getValue(FAMILY, QUALIFIERS[0])));
        // Test for Put and Delete operations
        arm = new RowMutations(ROW);
        p = new Put(ROW);
        p.addColumn(FAMILY, QUALIFIERS[1], VALUE);
        arm.add(p);
        Delete d = new Delete(ROW);
        d.addColumns(FAMILY, QUALIFIERS[0]);
        arm.add(d);
        // TODO: Trying mutateRow again. The batch was failing with a one try only.
        r = t.mutateRow(arm);
        assertTrue(r.getExists());
        assertTrue(r.isEmpty());
        r = t.get(g);
        assertEquals(0, Bytes.compareTo(VALUE, r.getValue(FAMILY, QUALIFIERS[1])));
        assertNull(r.getValue(FAMILY, QUALIFIERS[0]));
        // Test for Increment and Append operations
        arm = new RowMutations(ROW);
        arm.add(Arrays.asList(new Put(ROW).addColumn(FAMILY, QUALIFIERS[0], VALUE), new Delete(ROW).addColumns(FAMILY, QUALIFIERS[1]), new Increment(ROW).addColumn(FAMILY, QUALIFIERS[2], 5L), new Append(ROW).addColumn(FAMILY, QUALIFIERS[3], Bytes.toBytes("abc"))));
        r = t.mutateRow(arm);
        assertTrue(r.getExists());
        assertEquals(5L, Bytes.toLong(r.getValue(FAMILY, QUALIFIERS[2])));
        assertEquals("abc", Bytes.toString(r.getValue(FAMILY, QUALIFIERS[3])));
        g = new Get(ROW);
        r = t.get(g);
        assertEquals(0, Bytes.compareTo(VALUE, r.getValue(FAMILY, QUALIFIERS[0])));
        assertNull(r.getValue(FAMILY, QUALIFIERS[1]));
        assertEquals(5L, Bytes.toLong(r.getValue(FAMILY, QUALIFIERS[2])));
        assertEquals("abc", Bytes.toString(r.getValue(FAMILY, QUALIFIERS[3])));
        // Test that we get a region level exception
        try {
            arm = new RowMutations(ROW);
            p = new Put(ROW);
            p.addColumn(new byte[] { 'b', 'o', 'g', 'u', 's' }, QUALIFIERS[0], VALUE);
            arm.add(p);
            t.mutateRow(arm);
            fail("Expected NoSuchColumnFamilyException");
        } catch (NoSuchColumnFamilyException e) {
            return;
        } catch (RetriesExhaustedWithDetailsException e) {
            for (Throwable rootCause : e.getCauses()) {
                if (rootCause instanceof NoSuchColumnFamilyException) {
                    return;
                }
            }
            throw e;
        }
    }
}
Also used : TableName(org.apache.hadoop.hbase.TableName) NoSuchColumnFamilyException(org.apache.hadoop.hbase.regionserver.NoSuchColumnFamilyException) Test(org.junit.Test)

Example 7 with NoSuchColumnFamilyException

use of org.apache.hadoop.hbase.regionserver.NoSuchColumnFamilyException in project hbase by apache.

the class ResourceBase method processException.

protected Response processException(Throwable exp) {
    Throwable curr = exp;
    if (accessDeniedClazz != null) {
        // some access denied exceptions are buried
        while (curr != null) {
            if (accessDeniedClazz.isAssignableFrom(curr.getClass())) {
                throw new WebApplicationException(Response.status(Response.Status.FORBIDDEN).type(MIMETYPE_TEXT).entity("Forbidden" + CRLF + StringUtils.stringifyException(exp) + CRLF).build());
            }
            curr = curr.getCause();
        }
    }
    // TableNotFound may also be buried one level deep
    if (exp instanceof TableNotFoundException || exp.getCause() instanceof TableNotFoundException) {
        throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND).type(MIMETYPE_TEXT).entity("Not found" + CRLF + StringUtils.stringifyException(exp) + CRLF).build());
    }
    if (exp instanceof NoSuchColumnFamilyException) {
        throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND).type(MIMETYPE_TEXT).entity("Not found" + CRLF + StringUtils.stringifyException(exp) + CRLF).build());
    }
    if (exp instanceof RuntimeException) {
        throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST).type(MIMETYPE_TEXT).entity("Bad request" + CRLF + StringUtils.stringifyException(exp) + CRLF).build());
    }
    if (exp instanceof RetriesExhaustedException) {
        RetriesExhaustedException retryException = (RetriesExhaustedException) exp;
        processException(retryException.getCause());
    }
    throw new WebApplicationException(Response.status(Response.Status.SERVICE_UNAVAILABLE).type(MIMETYPE_TEXT).entity("Unavailable" + CRLF + StringUtils.stringifyException(exp) + CRLF).build());
}
Also used : TableNotFoundException(org.apache.hadoop.hbase.TableNotFoundException) WebApplicationException(org.apache.hbase.thirdparty.javax.ws.rs.WebApplicationException) RetriesExhaustedException(org.apache.hadoop.hbase.client.RetriesExhaustedException) NoSuchColumnFamilyException(org.apache.hadoop.hbase.regionserver.NoSuchColumnFamilyException)

Aggregations

NoSuchColumnFamilyException (org.apache.hadoop.hbase.regionserver.NoSuchColumnFamilyException)7 TableName (org.apache.hadoop.hbase.TableName)5 Test (org.junit.Test)5 IOException (java.io.IOException)2 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)2 RestrictedApi (com.google.errorprone.annotations.RestrictedApi)1 InterruptedIOException (java.io.InterruptedIOException)1 Constructor (java.lang.reflect.Constructor)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 InetAddress (java.net.InetAddress)1 InetSocketAddress (java.net.InetSocketAddress)1 UnknownHostException (java.net.UnknownHostException)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 EnumSet (java.util.EnumSet)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1