Search in sources :

Example 11 with TDelete

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

the class TestThriftHBaseServiceHandler method testDeleteFamilyVersion.

@Test
public void testDeleteFamilyVersion() throws Exception {
    ThriftHBaseServiceHandler handler = createHandler();
    byte[] rowName = Bytes.toBytes("testDeleteFamilyVersion");
    ByteBuffer table = wrap(tableAname);
    long timestamp1 = EnvironmentEdgeManager.currentTime() - 10;
    long timestamp2 = EnvironmentEdgeManager.currentTime();
    List<TColumnValue> columnValues = new ArrayList<>();
    TColumnValue columnValueA = new TColumnValue(wrap(familyAname), wrap(qualifierAname), wrap(valueAname));
    columnValueA.setTimestamp(timestamp1);
    columnValues.add(columnValueA);
    TPut put = new TPut(wrap(rowName), columnValues);
    put.setColumnValues(columnValues);
    handler.put(table, put);
    columnValueA.setTimestamp(timestamp2);
    handler.put(table, put);
    TGet get = new TGet(wrap(rowName));
    get.setMaxVersions(2);
    TResult result = handler.get(table, get);
    assertEquals(2, result.getColumnValuesSize());
    TDelete delete = new TDelete(wrap(rowName));
    List<TColumn> deleteColumns = new ArrayList<>();
    TColumn deleteColumn = new TColumn(wrap(familyAname));
    deleteColumn.setTimestamp(timestamp1);
    deleteColumns.add(deleteColumn);
    delete.setColumns(deleteColumns);
    delete.setDeleteType(TDeleteType.DELETE_FAMILY_VERSION);
    handler.deleteSingle(table, delete);
    get = new TGet(wrap(rowName));
    result = handler.get(table, get);
    assertArrayEquals(rowName, result.getRow());
    assertEquals(1, result.getColumnValuesSize());
    assertEquals(timestamp2, result.getColumnValues().get(0).getTimestamp());
}
Also used : TGet(org.apache.hadoop.hbase.thrift2.generated.TGet) TColumn(org.apache.hadoop.hbase.thrift2.generated.TColumn) ArrayList(java.util.ArrayList) TDelete(org.apache.hadoop.hbase.thrift2.generated.TDelete) TColumnValue(org.apache.hadoop.hbase.thrift2.generated.TColumnValue) ByteBuffer(java.nio.ByteBuffer) TResult(org.apache.hadoop.hbase.thrift2.generated.TResult) TPut(org.apache.hadoop.hbase.thrift2.generated.TPut) Test(org.junit.Test)

Example 12 with TDelete

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

the class TestThriftHBaseServiceHandler method testDeleteMultiple.

@Test
public void testDeleteMultiple() throws Exception {
    ThriftHBaseServiceHandler handler = createHandler();
    ByteBuffer table = wrap(tableAname);
    byte[] rowName1 = Bytes.toBytes("testDeleteMultiple1");
    byte[] rowName2 = Bytes.toBytes("testDeleteMultiple2");
    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)));
    List<TPut> puts = new ArrayList<>(2);
    puts.add(new TPut(wrap(rowName1), columnValues));
    puts.add(new TPut(wrap(rowName2), columnValues));
    handler.putMultiple(table, puts);
    List<TDelete> deletes = new ArrayList<>(2);
    deletes.add(new TDelete(wrap(rowName1)));
    deletes.add(new TDelete(wrap(rowName2)));
    List<TDelete> deleteResults = handler.deleteMultiple(table, deletes);
    // 0 means they were all successfully applies
    assertEquals(0, deleteResults.size());
    assertFalse(handler.exists(table, new TGet(wrap(rowName1))));
    assertFalse(handler.exists(table, new TGet(wrap(rowName2))));
}
Also used : TGet(org.apache.hadoop.hbase.thrift2.generated.TGet) ArrayList(java.util.ArrayList) TDelete(org.apache.hadoop.hbase.thrift2.generated.TDelete) 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 13 with TDelete

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

the class TestThriftHBaseServiceHandlerWithReadOnly method testDeleteMultipleWithReadOnly.

@Test
public void testDeleteMultipleWithReadOnly() throws Exception {
    ThriftHBaseServiceHandler handler = createHandler();
    ByteBuffer table = wrap(tableAname);
    byte[] rowName1 = Bytes.toBytes("testDeleteMultiple1");
    byte[] rowName2 = Bytes.toBytes("testDeleteMultiple2");
    List<TDelete> deletes = new ArrayList<>(2);
    deletes.add(new TDelete(wrap(rowName1)));
    deletes.add(new TDelete(wrap(rowName2)));
    boolean exceptionCaught = false;
    try {
        handler.deleteMultiple(table, deletes);
    } 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) TDelete(org.apache.hadoop.hbase.thrift2.generated.TDelete) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 14 with TDelete

use of org.apache.hadoop.hbase.thrift2.generated.TDelete 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 15 with TDelete

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

the class ThriftUtilities method deleteFromHBase.

public static TDelete deleteFromHBase(Delete in) {
    TDelete out = new TDelete(ByteBuffer.wrap(in.getRow()));
    List<TColumn> columns = new ArrayList<>(in.getFamilyCellMap().entrySet().size());
    long rowTimestamp = in.getTimestamp();
    if (rowTimestamp != HConstants.LATEST_TIMESTAMP) {
        out.setTimestamp(rowTimestamp);
    }
    for (Map.Entry<String, byte[]> attribute : in.getAttributesMap().entrySet()) {
        out.putToAttributes(ByteBuffer.wrap(Bytes.toBytes(attribute.getKey())), ByteBuffer.wrap(attribute.getValue()));
    }
    if (in.getDurability() != Durability.USE_DEFAULT) {
        out.setDurability(durabilityFromHBase(in.getDurability()));
    }
    // Delete the whole row
    if (in.getFamilyCellMap().size() == 0) {
        return out;
    }
    TDeleteType type = null;
    for (Map.Entry<byte[], List<Cell>> familyEntry : in.getFamilyCellMap().entrySet()) {
        byte[] family = familyEntry.getKey();
        TColumn column = new TColumn(ByteBuffer.wrap(familyEntry.getKey()));
        for (Cell cell : familyEntry.getValue()) {
            TDeleteType cellDeleteType = deleteTypeFromHBase(cell.getType());
            if (type == null) {
                type = cellDeleteType;
            } else if (type != cellDeleteType) {
                throw new RuntimeException("Only the same delete type is supported, but two delete type " + "is founded, one is " + type + " the other one is " + cellDeleteType);
            }
            byte[] qualifier = CellUtil.cloneQualifier(cell);
            long timestamp = cell.getTimestamp();
            column.setFamily(family);
            if (qualifier != null) {
                column.setQualifier(qualifier);
            }
            if (timestamp != HConstants.LATEST_TIMESTAMP) {
                column.setTimestamp(timestamp);
            }
        }
        columns.add(column);
    }
    out.setColumns(columns);
    out.setDeleteType(type);
    return out;
}
Also used : TColumn(org.apache.hadoop.hbase.thrift2.generated.TColumn) ArrayList(java.util.ArrayList) TDelete(org.apache.hadoop.hbase.thrift2.generated.TDelete) TDeleteType(org.apache.hadoop.hbase.thrift2.generated.TDeleteType) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) Cell(org.apache.hadoop.hbase.Cell)

Aggregations

TDelete (org.apache.hadoop.hbase.thrift2.generated.TDelete)15 Test (org.junit.Test)14 ByteBuffer (java.nio.ByteBuffer)13 ArrayList (java.util.ArrayList)13 TColumnValue (org.apache.hadoop.hbase.thrift2.generated.TColumnValue)11 TPut (org.apache.hadoop.hbase.thrift2.generated.TPut)11 TGet (org.apache.hadoop.hbase.thrift2.generated.TGet)9 TColumn (org.apache.hadoop.hbase.thrift2.generated.TColumn)7 TResult (org.apache.hadoop.hbase.thrift2.generated.TResult)7 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)4 TIOError (org.apache.hadoop.hbase.thrift2.generated.TIOError)4 Delete (org.apache.hadoop.hbase.client.Delete)2 Increment (org.apache.hadoop.hbase.client.Increment)2 Put (org.apache.hadoop.hbase.client.Put)2 TColumnIncrement (org.apache.hadoop.hbase.thrift2.generated.TColumnIncrement)2 TIncrement (org.apache.hadoop.hbase.thrift2.generated.TIncrement)2 TMutation (org.apache.hadoop.hbase.thrift2.generated.TMutation)2 TRowMutations (org.apache.hadoop.hbase.thrift2.generated.TRowMutations)2 HashMap (java.util.HashMap)1 List (java.util.List)1