[
https://issues.apache.org/jira/browse/PHOENIX-3167?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15423770#comment-15423770
]
Samarth Jain commented on PHOENIX-3167:
---------------------------------------
I don't think I have done a good job of explaining this bug :-(. Let me try one
more time.
{code}
@Test
public void testCreateExistingTableRestoreHTableProperties() throws
Exception {
try (Connection conn = DriverManager.getConnection(getUrl())) {
String tableName = generateRandomString();
// Create table statement with REPLICATION_SCOPE = 1
String createTableDDL = "CREATE TABLE " + tableName +" ("
+ " id char(1) NOT NULL,"
+ " col1 integer NOT NULL,"
+ " col2 bigint NOT NULL,"
+ " CONSTRAINT NAME_PK PRIMARY KEY (id, col1, col2)"
+ " ) REPLICATION_SCOPE = 1";
conn.createStatement().execute(createTableDDL);
assertReplicationScopeValue(conn, tableName, 1);
// Alter table to set REPLICATION_SCOPE = 0
String alterDDL = "ALTER TABLE " + tableName + " SET
REPLICATION_SCOPE = 0";
conn.createStatement().execute(alterDDL);
assertReplicationScopeValue(conn, tableName, 0);
try {
// Using the same DDL with REPLICATION_SCOPE = 1 fails which is
good. It also changes
// the HTable metadata of the table too which is NOT good.
conn.createStatement().execute(createTableDDL);
fail(tableName + " already exists");
} catch (TableAlreadyExistsException expected) {}
// This assert fails because of the bug. REPLICATION_SCOPE was
reset to 1 :-(.
assertReplicationScopeValue(conn, tableName, 0);
}
}
private void assertReplicationScopeValue(Connection conn, String tableName,
int expectedValue) throws Exception {
try (HBaseAdmin admin =
conn.unwrap(PhoenixConnection.class).getQueryServices().getAdmin()) {
HTableDescriptor tableDesc =
admin.getTableDescriptor(Bytes.toBytes(tableName));
HColumnDescriptor[] columnFamilies = tableDesc.getColumnFamilies();
assertEquals("0", columnFamilies[0].getNameAsString());
assertEquals(expectedValue, columnFamilies[0].getScope());
}
}
{code}
> CREATE TABLE on an existing table resets the HTableMetadata
> -----------------------------------------------------------
>
> Key: PHOENIX-3167
> URL: https://issues.apache.org/jira/browse/PHOENIX-3167
> Project: Phoenix
> Issue Type: Bug
> Reporter: Samarth Jain
> Assignee: Samarth Jain
> Fix For: 4.8.1
>
> Attachments: PHOENIX-3167.patch
>
>
> {code}
> @Test
> public void testRecreatingExistingTableMaintainsHTableProperties() throws
> Exception {
> Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
> Connection conn = DriverManager.getConnection(getUrl(), props);
> String ddl = "ALTER TABLE SYSTEM.CATALOG SET KEEP_DELETED_CELLS =
> false";
> conn.createStatement().execute(ddl);
> assertDeleteCellsDisabled(conn);
> try {
>
> conn.createStatement().execute(QueryConstants.CREATE_TABLE_METADATA);
> } catch (TableAlreadyExistsException e) {
> }
> assertDeleteCellsDisabled(conn);
> }
>
> private void assertDeleteCellsDisabled(Connection conn) throws
> org.apache.hadoop.hbase.TableNotFoundException,
> IOException, SQLException {
> try (HBaseAdmin admin =
> conn.unwrap(PhoenixConnection.class).getQueryServices().getAdmin()) {
> HTableDescriptor tableDesc =
> admin.getTableDescriptor(Bytes.toBytes("SYSTEM.CATALOG"));
> HColumnDescriptor[] columnFamilies =
> tableDesc.getColumnFamilies();
> assertEquals("0", columnFamilies[0].getNameAsString());
> assertEquals(KeepDeletedCells.FALSE,
> columnFamilies[0].getKeepDeletedCells());
> }
> }
> {code}
> [~jamestaylor], [~apurtell], [~lhofhansl], [~mujtabachohan] - this is likely
> why we saw that the keep deleted cells property always kept flipping to true
> even though we set it to false in hbase shell.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)