Search in sources :

Example 21 with TIOError

use of org.apache.hadoop.hbase.thrift2.generated.TIOError in project hbase by apache.

the class TestThriftHBaseServiceHandlerWithReadOnly method testPutWithReadOnly.

@Test
public void testPutWithReadOnly() throws Exception {
    ThriftHBaseServiceHandler handler = createHandler();
    ByteBuffer table = wrap(tableAname);
    byte[] rowName = Bytes.toBytes("testPut");
    List<TColumnValue> columnValues = new ArrayList<>(2);
    columnValues.add(new TColumnValue(wrap(familyAname), wrap(qualifierAname), wrap(valueAname)));
    columnValues.add(new TColumnValue(wrap(familyBname), wrap(qualifierBname), wrap(valueBname)));
    TPut put = new TPut(wrap(rowName), columnValues);
    boolean exceptionCaught = false;
    try {
        handler.put(table, put);
    } catch (TIOError e) {
        exceptionCaught = true;
        assertTrue(e.getCause() instanceof DoNotRetryIOException);
        assertEquals("Thrift Server is in Read-only mode.", e.getMessage());
    } finally {
        assertTrue(exceptionCaught);
    }
}
Also used : TIOError(org.apache.hadoop.hbase.thrift2.generated.TIOError) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) ArrayList(java.util.ArrayList) TColumnValue(org.apache.hadoop.hbase.thrift2.generated.TColumnValue) TPut(org.apache.hadoop.hbase.thrift2.generated.TPut) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 22 with TIOError

use of org.apache.hadoop.hbase.thrift2.generated.TIOError in project hbase by apache.

the class TestThriftHBaseServiceHandlerWithReadOnly method testAppendWithReadOnly.

@Test
public void testAppendWithReadOnly() throws Exception {
    ThriftHBaseServiceHandler handler = createHandler();
    byte[] rowName = Bytes.toBytes("testAppend");
    ByteBuffer table = wrap(tableAname);
    byte[] v1 = Bytes.toBytes("42");
    List<TColumnValue> appendColumns = new ArrayList<>(1);
    appendColumns.add(new TColumnValue(wrap(familyAname), wrap(qualifierAname), wrap(v1)));
    TAppend append = new TAppend(wrap(rowName), appendColumns);
    boolean exceptionCaught = false;
    try {
        handler.append(table, append);
    } catch (TIOError e) {
        exceptionCaught = true;
        assertTrue(e.getCause() instanceof DoNotRetryIOException);
        assertEquals("Thrift Server is in Read-only mode.", e.getMessage());
    } finally {
        assertTrue(exceptionCaught);
    }
}
Also used : TIOError(org.apache.hadoop.hbase.thrift2.generated.TIOError) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) ArrayList(java.util.ArrayList) TAppend(org.apache.hadoop.hbase.thrift2.generated.TAppend) TColumnValue(org.apache.hadoop.hbase.thrift2.generated.TColumnValue) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 23 with TIOError

use of org.apache.hadoop.hbase.thrift2.generated.TIOError in project hbase by apache.

the class TestThriftHBaseServiceHandlerWithReadOnly method testScanWithReadOnly.

@Test
public void testScanWithReadOnly() throws Exception {
    ThriftHBaseServiceHandler handler = createHandler();
    ByteBuffer table = wrap(tableAname);
    TScan scan = new TScan();
    boolean exceptionCaught = false;
    try {
        int scanId = handler.openScanner(table, scan);
        handler.getScannerRows(scanId, 10);
        handler.closeScanner(scanId);
    } catch (TIOError e) {
        exceptionCaught = true;
    } finally {
        assertFalse(exceptionCaught);
    }
}
Also used : TIOError(org.apache.hadoop.hbase.thrift2.generated.TIOError) TScan(org.apache.hadoop.hbase.thrift2.generated.TScan) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 24 with TIOError

use of org.apache.hadoop.hbase.thrift2.generated.TIOError in project hbase by apache.

the class TestThriftHBaseServiceHandlerWithReadOnly method testDeleteWithReadOnly.

@Test
public void testDeleteWithReadOnly() throws Exception {
    ThriftHBaseServiceHandler handler = createHandler();
    byte[] rowName = Bytes.toBytes("testDelete");
    ByteBuffer table = wrap(tableAname);
    TDelete delete = new TDelete(wrap(rowName));
    boolean exceptionCaught = false;
    try {
        handler.deleteSingle(table, delete);
    } catch (TIOError e) {
        exceptionCaught = true;
        assertTrue(e.getCause() instanceof DoNotRetryIOException);
        assertEquals("Thrift Server is in Read-only mode.", e.getMessage());
    } finally {
        assertTrue(exceptionCaught);
    }
}
Also used : TIOError(org.apache.hadoop.hbase.thrift2.generated.TIOError) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) TDelete(org.apache.hadoop.hbase.thrift2.generated.TDelete) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 25 with TIOError

use of org.apache.hadoop.hbase.thrift2.generated.TIOError in project hbase by apache.

the class ThriftHBaseServiceHandler method getRegionLocation.

@Override
public THRegionLocation getRegionLocation(ByteBuffer table, ByteBuffer row, boolean reload) throws TIOError, TException {
    RegionLocator locator = null;
    try {
        locator = getLocator(table);
        byte[] rowBytes = byteBufferToByteArray(row);
        HRegionLocation hrl = locator.getRegionLocation(rowBytes, reload);
        return ThriftUtilities.regionLocationFromHBase(hrl);
    } catch (IOException e) {
        throw getTIOError(e);
    } finally {
        if (locator != null) {
            try {
                locator.close();
            } catch (IOException e) {
                LOG.warn("Couldn't close the locator.", e);
            }
        }
    }
}
Also used : RegionLocator(org.apache.hadoop.hbase.client.RegionLocator) THRegionLocation(org.apache.hadoop.hbase.thrift2.generated.THRegionLocation) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) IOException(java.io.IOException)

Aggregations

DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)29 IOException (java.io.IOException)18 ByteBuffer (java.nio.ByteBuffer)17 Test (org.junit.Test)17 TIOError (org.apache.hadoop.hbase.thrift2.generated.TIOError)16 ArrayList (java.util.ArrayList)12 TableName (org.apache.hadoop.hbase.TableName)9 TTableName (org.apache.hadoop.hbase.thrift2.generated.TTableName)9 TColumnValue (org.apache.hadoop.hbase.thrift2.generated.TColumnValue)8 TPut (org.apache.hadoop.hbase.thrift2.generated.TPut)7 TGet (org.apache.hadoop.hbase.thrift2.generated.TGet)6 TableDescriptor (org.apache.hadoop.hbase.client.TableDescriptor)4 TDelete (org.apache.hadoop.hbase.thrift2.generated.TDelete)4 TTableDescriptor (org.apache.hadoop.hbase.thrift2.generated.TTableDescriptor)4 Pattern (java.util.regex.Pattern)2 NamespaceDescriptor (org.apache.hadoop.hbase.NamespaceDescriptor)2 ColumnFamilyDescriptor (org.apache.hadoop.hbase.client.ColumnFamilyDescriptor)2 ResultScanner (org.apache.hadoop.hbase.client.ResultScanner)2 TColumnFamilyDescriptor (org.apache.hadoop.hbase.thrift2.generated.TColumnFamilyDescriptor)2 TNamespaceDescriptor (org.apache.hadoop.hbase.thrift2.generated.TNamespaceDescriptor)2