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

ASF GitHub Bot commented on PHOENIX-6141:
-----------------------------------------

tkhurana commented on code in PR #1575:
URL: https://github.com/apache/phoenix/pull/1575#discussion_r1240113225


##########
phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java:
##########
@@ -2203,6 +2196,89 @@ public MetaDataResponse call(MetaDataService instance) 
throws IOException {
                 return rpcCallback.get();
             }
         });
+
+        //For view creation, if SYSCAT rpc succeeds, mark child_link rows as 
VERIFIED
+        if (!childLinkMutations.isEmpty()) {
+            try {
+                if (result.getMutationCode() == MutationCode.TABLE_NOT_FOUND) {
+                    sendChildLinkMutations(childLinkMutations, true, false, 
physicalTableNameBytes, schemaBytes);
+                } else {
+                    sendChildLinkMutations(childLinkMutations, true, true, 
physicalTableNameBytes, schemaBytes);
+                }
+            }
+            catch (SQLException e) {
+                //unverified rows will be repaired during read
+                LOGGER.debug("Exception in phase-3 of view creation: " + 
e.getMessage());
+                addChildLinkScanTask();
+            }
+        }
+        return result;
+    }
+
+    /*
+    Helper method to send mutations to SYSTEM.CHILD_LINK using its endpoint 
coprocessor
+     */
+    public void sendChildLinkMutations(List<Mutation> mutations, boolean 
isVerified, boolean isDelete,
+                                        byte[] physicalTableNameBytes, byte[] 
schemaBytes)
+            throws SQLException {
+
+        // get empty column information
+        PTable childLinkLogicalTable = getTable(null, 
PhoenixDatabaseMetaData.SYSTEM_CHILD_LINK_NAME, HConstants.LATEST_TIMESTAMP);
+        byte[] emptyCF = 
SchemaUtil.getEmptyColumnFamily(childLinkLogicalTable);
+        byte[] emptyCQ = 
EncodedColumnsUtil.getEmptyKeyValueInfo(childLinkLogicalTable).getFirst();
+
+        // add empty column value to mutations or create delete mutations for 
phase-3
+        List<Mutation> childLinkMutations = new ArrayList<>();
+        for (Mutation m : mutations) {
+            if (isDelete) {
+                Delete delete = new Delete(m.getRow());
+                childLinkMutations.add(delete);
+            }
+            else {
+                Put put = isVerified ? new Put(m.getRow()) : (Put)m;
+                byte[] emptyColumnValue = isVerified ? VERIFIED_BYTES : 
UNVERIFIED_BYTES;
+                put.addColumn(emptyCF, emptyCQ, IndexUtil.getMaxTimestamp(m), 
emptyColumnValue);

Review Comment:
   But you are setting the timestamp from the existing cells in the mutation 
`IndexUtil.getMaxTimestamp(m)`. I am surprised you are getting a higher 
timestamp.





> Ensure consistency between SYSTEM.CATALOG and SYSTEM.CHILD_LINK
> ---------------------------------------------------------------
>
>                 Key: PHOENIX-6141
>                 URL: https://issues.apache.org/jira/browse/PHOENIX-6141
>             Project: Phoenix
>          Issue Type: Improvement
>    Affects Versions: 5.0.0, 4.15.0
>            Reporter: Chinmay Kulkarni
>            Assignee: Palash Chauhan
>            Priority: Blocker
>             Fix For: 5.2.0, 5.1.4
>
>
> Before 4.15, "CREATE/DROP VIEW" was an atomic operation since we were issuing 
> batch mutations on just the 1 SYSTEM.CATALOG region. In 4.15 we introduced 
> SYSTEM.CHILD_LINK to store the parent->child links and so a CREATE VIEW is no 
> longer atomic since it consists of 2 separate RPCs  (1 to SYSTEM.CHILD_LINK 
> to add the linking row and another to SYSTEM.CATALOG to write metadata for 
> the new view). 
> If the second RPC i.e. the RPC to write metadata to SYSTEM.CATALOG fails 
> after the 1st RPC has already gone through, there will be an inconsistency 
> between both metadata tables. We will see orphan parent->child linking rows 
> in SYSTEM.CHILD_LINK in this case. This can cause the following issues:
> # ALTER TABLE calls on the base table will fail
> # DROP TABLE without CASCADE will fail
> # The upgrade path has calls like UpgradeUtil.upgradeTable() which will fail
> # Any metadata consistency checks can be thrown off
> # Unnecessary extra storage of orphan links
> The first 3 issues happen because we wrongly deduce that a base table has 
> child views due to the orphan linking rows.
> This Jira aims at trying to come up with a way to make mutations among 
> SYSTEM.CATALOG and SYSTEM.CHILD_LINK an atomic transaction. We can use a 
> 2-phase commit approach like in global indexing or also potentially explore 
> using a transaction manager. 



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to