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

James Taylor commented on PHOENIX-4229:
---------------------------------------

The way to interpret the row key of the SYSTEM.CATALOG (like any Phoenix table) 
is to look at the primary key definition of its DDL statement (in 
QueryConstants.CREATE_TABLE_METADATA). So in general you'll have:

tenantId, schemaName, tableName, columnName, columnFamily as the row key with a 
0 byte separator. 

The actual UPSERT statement for the linking row is defined in 
MetaDataClient.CREATE_VIEW_LINK. 

To form the parent -> child link, you can drive it from the cell with a column 
qualifier of PARENT_TENANT_ID (only the parent view link will have that cq):
- parentTenantId is the value of that cell
- parentSchemaName and parentTableName are in the COLUMN_FAMILY position of the 
row key (encoded as the full table name with a . separator - you can use 
SchemaUtil.getSchemaNameFromFullName() and 
SchemaUtil.getTableNameFromFullName() to get those separately.

Given the above, you can use getChildLinkKey(PName parentTenantId, PName 
parentSchemaName, PName parentTableName, PName viewTenantId, PName viewName) to 
form the child link row key. Use PNameFactory.getName(String name) to get a 
PName.

The viewTenantId is the value in the 0th position of the row key
The viewName is the full table name of the view formed by 
SchemaUtil.getTableName(schemaName, tableName).

We have utilities MetaDataUtil.getVarChars() that you can use to decompose the 
row key:
{code}
                    byte[][] rowViewKeyMetaData = new byte[5][];
                    getVarChars(result.getRow(), 5, rowViewKeyMetaData);
                    byte[] tenantId = 
rowKeyMetaData[PhoenixDatabaseMetaData.TENANT_ID_INDEX];
                    byte[] schemaName = 
rowKeyMetaData[PhoenixDatabaseMetaData.SCHEMA_NAME_INDEX];
                    byte[] tableName = 
rowKeyMetaData[PhoenixDatabaseMetaData.TABLE_NAME_INDEX];
                    byte[] viewSchemaName = 
SchemaUtil.getSchemaNameFromFullName(rowViewKeyMetaData[PhoenixDatabaseMetaData.FAMILY_NAME_INDEX]).getBytes();
                    byte[] viewTableNameName = 
SchemaUtil.getTableNameFromFullName(rowViewKeyMetaData[PhoenixDatabaseMetaData.FAMILY_NAME_INDEX]).getBytes();
{code}

You'll just need to create and put a cell with the above row key and a column 
qualifier of PhoenixDatabaseMetaData.LINK_TYPE and a value of 
LinkType.CHILD_TABLE.getSerializedValue().

> Parent-Child linking rows in System.Catalog break tenant view replication
> -------------------------------------------------------------------------
>
>                 Key: PHOENIX-4229
>                 URL: https://issues.apache.org/jira/browse/PHOENIX-4229
>             Project: Phoenix
>          Issue Type: Bug
>    Affects Versions: 4.11.0, 4.12.0
>            Reporter: Geoffrey Jacoby
>            Assignee: Geoffrey Jacoby
>
> PHOENIX-2051 introduced new Parent-Child linking rows to System.Catalog that 
> speed up view deletion. Unfortunately, this breaks assumptions in 
> PHOENIX-3639, which gives a way to replicate tenant views from one cluster to 
> another. (It assumes that all the metadata for a tenant view is owned by the 
> tenant -- the linking rows are not.) 
> PHOENIX-3639 was a workaround in the first place to the more fundamental 
> design problem that Phoenix places the metadata for both table schemas -- 
> which should never be replicated -- in the same table and column family as 
> the metadata for tenant views, which should be replicated. 
> Note that the linking rows also make it more difficult to ever split these 
> two datasets apart, as proposed in PHOENIX-3520.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to