[ 
https://issues.apache.org/jira/browse/HBASE-22806?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16901683#comment-16901683
 ] 

Huon Wilson edited comment on HBASE-22806 at 8/7/19 4:18 AM:
-------------------------------------------------------------

Here's a complete code example:

{code:java}
TableName tableName = TableName.valueOf("table");
byte[] family1 = Bytes.toBytes("family1");
byte[] family2 = Bytes.toBytes("family2");
byte[] row = Bytes.toBytes("row");
byte[] qualifier = Bytes.toBytes("qualifier");
byte[] value = Bytes.toBytes("value");

ColumnFamilyDescriptor familyDesc1 =
        ColumnFamilyDescriptorBuilder
        .newBuilder(family1)
        .build();
ColumnFamilyDescriptor familyDesc2 =
        ColumnFamilyDescriptorBuilder
                .newBuilder(family2)
                .build();


TableDescriptor tableDesc = TableDescriptorBuilder
        .newBuilder(tableName)
        .setColumnFamily(familyDesc1)
        .setColumnFamily(familyDesc2)
        .build();

try {
    Connection conn = ConnectionFactory.createConnection();
    Admin admin = conn.getAdmin();

    // step 1
    admin.createTable(tableDesc);

    // step 2
    Table table = conn.getTable(tableName);
    table.put(new Put(row).addColumn(family2, qualifier, value));
    TableDescriptor currentDesc = table.getDescriptor();
    table.close();

    // step 3 (addition): uncommenting this no-op modification makes this work
    // admin.modifyTable(currentDesc);

    // read the data before deleting and recreating (it should exist)
    table = conn.getTable(tableName);
    Result resultGood = table.get(new Get(row));
    System.out.println("should be 'value': " + 
Bytes.toStringBinary(resultGood.value()));
    table.close();

    // step 3
    admin.deleteColumnFamily(tableName, family2);

    // step 4
    admin.addColumnFamily(tableName, familyDesc2);

    /*
    // also occurs with two modify tables
    TableDescriptor removedDesc =
      
TableDescriptorBuilder.newBuilder(tableDesc).removeColumnFamily(family2).build();
    // step 3
    admin.modifyTable(removedDesc);
    // step 4
    admin.modifyTable(tableDesc);
    */

    // read the data after deleting and recreating (it should exist)
    table = conn.getTable(tableName);
    Result resultBad = table.get(new Get(row));
    System.out.println("should be null: " + 
Bytes.toStringBinary(resultBad.value()));
    table.close();

    // cleanup
    admin.disableTable(tableName);
    admin.deleteTable(tableName);
} catch (IOException e) {
    System.err.println(e);
}
{code}

The output looks like:

{code:none}
should be 'value': value
should be null: value
{code}

If the no-op {{modifyTable}} is uncommented, the output is:

{code:none}
should be 'value': value
should be null: null
{code}

I've (tried to...?) attached a project that should compile and run against a 
{{localhost}} HBase. (I was running it in IntelliJ.)


was (Author: huonw):
Here's a complete code example:

{code:java}
TableName tableName = TableName.valueOf("table");
byte[] family1 = Bytes.toBytes("family1");
byte[] family2 = Bytes.toBytes("family2");
byte[] row = Bytes.toBytes("row");
byte[] qualifier = Bytes.toBytes("qualifier");
byte[] value = Bytes.toBytes("value");

ColumnFamilyDescriptor familyDesc1 =
        ColumnFamilyDescriptorBuilder
        .newBuilder(family1)
        .build();
ColumnFamilyDescriptor familyDesc2 =
        ColumnFamilyDescriptorBuilder
                .newBuilder(family2)
                .build();


TableDescriptor tableDesc = TableDescriptorBuilder
        .newBuilder(tableName)
        .setColumnFamily(familyDesc1)
        .setColumnFamily(familyDesc2)
        .build();

try {
    Connection conn = ConnectionFactory.createConnection();
    Admin admin = conn.getAdmin();

    // step 1
    admin.createTable(tableDesc);

    // step 2
    Table table = conn.getTable(tableName);
    table.put(new Put(row).addColumn(family2, qualifier, value));
    TableDescriptor currentDesc = table.getDescriptor();
    table.close();

    // step 3 (addition): uncommenting this no-op modification makes this work
    // admin.modifyTable(currentDesc);

    // read the data before deleting and recreating (it should exist)
    table = conn.getTable(tableName);
    Result resultGood = table.get(new Get(row));
    System.out.println("should be 'value': " + 
Bytes.toStringBinary(resultGood.value()));
    table.close();

    // step 3
    admin.deleteColumnFamily(tableName, family2);

    // step 4
    admin.addColumnFamily(tableName, familyDesc2);

    /*
    // also occurs with two modify tables
    TableDescriptor removedDesc =
      
TableDescriptorBuilder.newBuilder(tableDesc).removeColumnFamily(family2).build();
    // step 3
    admin.modifyTable(removedDesc);
    // step 4
    admin.modifyTable(tableDesc);
    */

    // read the data after deleting and recreating (it should exist)
    table = conn.getTable(tableName);
    Result resultBad = table.get(new Get(row));
    System.out.println("should be null: " + 
Bytes.toStringBinary(resultBad.value()));
    table.close();

    // cleanup
    admin.disableTable(tableName);
    admin.deleteTable(tableName);
} catch (IOException e) {
    System.err.println(e);
}
{code}

The output looks like:

{code:none}
should be 'value': value
should be null: value
{code}

I've attached a project that should compile and run against a {{localhost}} 
HBase. (I was running it in IntelliJ.)

> Recreating a deleted column family brings back the deleted cells
> ----------------------------------------------------------------
>
>                 Key: HBASE-22806
>                 URL: https://issues.apache.org/jira/browse/HBASE-22806
>             Project: HBase
>          Issue Type: Bug
>          Components: API
>    Affects Versions: 2.1.3
>         Environment: Scala
> HBase Java Client
> Mac/Linux
>            Reporter: Chao
>            Priority: Major
>
> Steps to reproduce the bug:
>  # Create a table with column family CF
>  # Add some cells C1, C2 in CF
>  # Remove CF using either:
>  ** TableDescriptorBuilder.removeColumnFamily() and Admin.modifyTable()
>  ** Admin.deleteColumnFamily()
>  # Create CF again
> Expected: no cells (all cells marked as deleted) in CF
> Actual: C1, C2 shows up automatically in CF
> Extra information: in step 3, if doing Admin.modifyColumnFamily() without 
> actually changing anything, then after step 4 the cells won't come back.



--
This message was sent by Atlassian JIRA
(v7.6.14#76016)

Reply via email to