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

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

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


##########
phoenix-core/src/main/java/org/apache/phoenix/coprocessor/ChildLinkMetaDataEndpoint.java:
##########
@@ -111,4 +141,245 @@ private PhoenixMetaDataCoprocessorHost 
getCoprocessorHost() {
                return phoenixAccessCoprocessorHost;
        }
 
+    /**
+     * Class that verifies a given row of a SYSTEM.CHILD_LINK table.
+     * An instance of this class is created for each scanner on the table
+     * and used to verify individual rows.
+     */
+    public class ChildLinkMetaDataScanner extends BaseRegionScanner {
+
+        private RegionScanner scanner;
+        private Scan scan;
+        private RegionCoprocessorEnvironment env;
+        private Scan sysCatScan = null;
+        private Scan childLinkScan;
+        private byte[] emptyCF;
+        private byte[] emptyCQ;
+        private Region region;
+        private boolean hasMore;
+        private long pageSizeMs;
+        private long pageSize = Long.MAX_VALUE;
+        private long rowCount = 0;
+        private long maxTimestamp;
+        private long ageThreshold;
+
+        public ChildLinkMetaDataScanner(RegionCoprocessorEnvironment env,
+                                        Scan scan,
+                                        RegionScanner scanner) {
+            super(scanner);
+            this.env = env;
+            this.scan = scan;
+            this.scanner = scanner;
+            region = env.getRegion();
+            emptyCF = scan.getAttribute(EMPTY_COLUMN_FAMILY_NAME);
+            emptyCQ = scan.getAttribute(EMPTY_COLUMN_QUALIFIER_NAME);
+            pageSizeMs = getPageSizeMsForRegionScanner(scan);
+            maxTimestamp = scan.getTimeRange().getMax();
+            ageThreshold = env.getConfiguration().getLong(
+                    
QueryServices.CHILD_LINK_ROW_AGE_THRESHOLD_TO_DELETE_MS_ATTRIB,
+                    
QueryServicesOptions.DEFAULT_CHILD_LINK_ROW_AGE_THRESHOLD_TO_DELETE_MS);
+        }
+
+        public boolean next(List<Cell> result, boolean raw) throws IOException 
{
+            try {
+                long startTime = EnvironmentEdgeManager.currentTimeMillis();
+                do {
+                    if (raw) {
+                        hasMore = scanner.nextRaw(result);
+                    } else {
+                        hasMore = scanner.next(result);
+                    }
+                    if (result.isEmpty()) {
+                        break;
+                    }
+                    if (isDummy(result)) {
+                        return true;
+                    }
+                    Cell cell = result.get(0);
+                    if (verifyRowAndRepairIfNecessary(result)) {
+                        break;
+                    }
+                    if (hasMore && (EnvironmentEdgeManager.currentTimeMillis() 
- startTime) >= pageSizeMs) {
+                        byte[] rowKey = CellUtil.cloneRow(cell);
+                        result.clear();
+                        getDummyResult(rowKey, result);
+                        return true;
+                    }
+                    // skip this row as it is invalid
+                    // if there is no more row, then result will be an empty 
list
+                } while (hasMore);
+                rowCount++;
+                if (rowCount == pageSize) {

Review Comment:
   You need to check if the scan has the page filter. If so, you need to remove 
it from the scan and then reopen the underlying the region scanner. Please see 
GlobalIndexChecker. 





> 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