virajjasani commented on code in PR #1569:
URL: https://github.com/apache/phoenix/pull/1569#discussion_r1147135437


##########
phoenix-core/src/main/java/org/apache/phoenix/coprocessor/PhoenixTTLRegionScanner.java:
##########
@@ -0,0 +1,218 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.coprocessor;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.hadoop.hbase.Cell;
+import org.apache.hadoop.hbase.CellUtil;
+import org.apache.hadoop.hbase.HConstants;
+import org.apache.hadoop.hbase.client.Scan;
+import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment;
+import org.apache.hadoop.hbase.filter.PageFilter;
+import org.apache.hadoop.hbase.regionserver.RegionScanner;
+import org.apache.phoenix.query.QueryServices;
+import org.apache.phoenix.query.QueryServicesOptions;
+import org.apache.phoenix.util.EnvironmentEdgeManager;
+import org.apache.phoenix.util.ScanUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static 
org.apache.phoenix.coprocessor.BaseScannerRegionObserver.EMPTY_COLUMN_FAMILY_NAME;
+import static 
org.apache.phoenix.coprocessor.BaseScannerRegionObserver.EMPTY_COLUMN_QUALIFIER_NAME;
+
+/**
+ *  PhoenixTTLRegionScanner masks expired rows using the empty column cell 
timestamp
+ */
+public class PhoenixTTLRegionScanner extends BaseRegionScanner {
+    private static final Logger LOG =
+            LoggerFactory.getLogger(PhoenixTTLRegionScanner.class);
+    private final boolean isPhoenixTableTTLEnabled;
+    private final RegionCoprocessorEnvironment env;
+    private Scan scan;
+    private long rowCount = 0;
+    private long pageSize = Long.MAX_VALUE;
+    long ttl;
+    long ttlWindowStart;
+    byte[] emptyCQ;
+    byte[] emptyCF;
+    private boolean initialized = false;
+
+    public PhoenixTTLRegionScanner(final RegionCoprocessorEnvironment env, 
final Scan scan,
+            final RegionScanner s) {
+        super(s);
+        this.env = env;
+        this.scan = scan;
+        emptyCQ = scan.getAttribute(EMPTY_COLUMN_QUALIFIER_NAME);
+        emptyCF = scan.getAttribute(EMPTY_COLUMN_FAMILY_NAME);
+        long currentTime = EnvironmentEdgeManager.currentTimeMillis();
+        ttl = 
env.getRegion().getTableDescriptor().getColumnFamilies()[0].getTimeToLive();
+        ttlWindowStart = ttl == HConstants.FOREVER ? 1 : currentTime - ttl * 
1000;
+        ttl *= 1000;
+        isPhoenixTableTTLEnabled = emptyCF != null && emptyCQ != null &&
+                
env.getConfiguration().getBoolean(QueryServices.PHOENIX_TABLE_TTL_ENABLED,
+                        
QueryServicesOptions.DEFAULT_PHOENIX_TABLE_TTL_ENABLED);
+    }
+
+    private void init() throws IOException {
+        // HBase PageFilter will also count the expired rows.
+        // Instead of using PageFilter for counting, we will count returned 
row here.
+        PageFilter pageFilter = ScanUtil.removePageFilter(scan);
+        if (pageFilter != null) {
+            pageSize = pageFilter.getPageSize();
+            delegate.close();
+            delegate = 
((DelegateRegionScanner)delegate).getNewRegionScanner(scan);
+        }
+    }
+
+    private boolean isExpired(List<Cell> result) throws IOException {
+        long maxTimestamp = 0;
+        long minTimestamp = Long.MAX_VALUE;
+        long ts;
+        boolean found = false;
+        for (Cell c : result) {
+            ts = c.getTimestamp();
+            if (!found && ScanUtil.isEmptyColumn(c, emptyCF, emptyCQ)) {
+                if (ts < ttlWindowStart) {
+                    return true;
+                }
+                found = true;
+            }
+            ts = c.getTimestamp();

Review Comment:
   nit: this one is redundant right? or is the value of `ts` or cell timestamp 
changed somewhere in the middle that I might have missed?



##########
phoenix-core/src/main/java/org/apache/phoenix/coprocessor/PhoenixTTLRegionScanner.java:
##########
@@ -0,0 +1,218 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.coprocessor;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.hadoop.hbase.Cell;
+import org.apache.hadoop.hbase.CellUtil;
+import org.apache.hadoop.hbase.HConstants;
+import org.apache.hadoop.hbase.client.Scan;
+import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment;
+import org.apache.hadoop.hbase.filter.PageFilter;
+import org.apache.hadoop.hbase.regionserver.RegionScanner;
+import org.apache.phoenix.query.QueryServices;
+import org.apache.phoenix.query.QueryServicesOptions;
+import org.apache.phoenix.util.EnvironmentEdgeManager;
+import org.apache.phoenix.util.ScanUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static 
org.apache.phoenix.coprocessor.BaseScannerRegionObserver.EMPTY_COLUMN_FAMILY_NAME;
+import static 
org.apache.phoenix.coprocessor.BaseScannerRegionObserver.EMPTY_COLUMN_QUALIFIER_NAME;
+
+/**
+ *  PhoenixTTLRegionScanner masks expired rows using the empty column cell 
timestamp
+ */
+public class PhoenixTTLRegionScanner extends BaseRegionScanner {
+    private static final Logger LOG =
+            LoggerFactory.getLogger(PhoenixTTLRegionScanner.class);
+    private final boolean isPhoenixTableTTLEnabled;
+    private final RegionCoprocessorEnvironment env;
+    private Scan scan;
+    private long rowCount = 0;
+    private long pageSize = Long.MAX_VALUE;
+    long ttl;
+    long ttlWindowStart;
+    byte[] emptyCQ;
+    byte[] emptyCF;
+    private boolean initialized = false;
+
+    public PhoenixTTLRegionScanner(final RegionCoprocessorEnvironment env, 
final Scan scan,
+            final RegionScanner s) {
+        super(s);
+        this.env = env;
+        this.scan = scan;
+        emptyCQ = scan.getAttribute(EMPTY_COLUMN_QUALIFIER_NAME);
+        emptyCF = scan.getAttribute(EMPTY_COLUMN_FAMILY_NAME);
+        long currentTime = EnvironmentEdgeManager.currentTimeMillis();
+        ttl = 
env.getRegion().getTableDescriptor().getColumnFamilies()[0].getTimeToLive();
+        ttlWindowStart = ttl == HConstants.FOREVER ? 1 : currentTime - ttl * 
1000;
+        ttl *= 1000;
+        isPhoenixTableTTLEnabled = emptyCF != null && emptyCQ != null &&
+                
env.getConfiguration().getBoolean(QueryServices.PHOENIX_TABLE_TTL_ENABLED,
+                        
QueryServicesOptions.DEFAULT_PHOENIX_TABLE_TTL_ENABLED);
+    }
+
+    private void init() throws IOException {
+        // HBase PageFilter will also count the expired rows.
+        // Instead of using PageFilter for counting, we will count returned 
row here.
+        PageFilter pageFilter = ScanUtil.removePageFilter(scan);
+        if (pageFilter != null) {
+            pageSize = pageFilter.getPageSize();
+            delegate.close();
+            delegate = 
((DelegateRegionScanner)delegate).getNewRegionScanner(scan);
+        }
+    }
+
+    private boolean isExpired(List<Cell> result) throws IOException {
+        long maxTimestamp = 0;
+        long minTimestamp = Long.MAX_VALUE;
+        long ts;
+        boolean found = false;
+        for (Cell c : result) {
+            ts = c.getTimestamp();
+            if (!found && ScanUtil.isEmptyColumn(c, emptyCF, emptyCQ)) {
+                if (ts < ttlWindowStart) {
+                    return true;
+                }
+                found = true;
+            }
+            ts = c.getTimestamp();
+            if (maxTimestamp < ts) {
+                maxTimestamp = ts;
+            }
+            if (minTimestamp > ts) {
+                minTimestamp = ts;
+            }

Review Comment:
   Basically they are
   ```
   maxTimestamp = Math.max(maxTimestamp, ts);
   minTimestamp = Math.min(minTimestamp, ts);
   ```
   correct?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to