swaroopak commented on a change in pull request #662: PHOENIX-5645 - 
GlobalIndexChecker should prevent compaction from purg…
URL: https://github.com/apache/phoenix/pull/662#discussion_r363996928
 
 

 ##########
 File path: 
phoenix-core/src/main/java/org/apache/hadoop/hbase/regionserver/ScanInfoUtil.java
 ##########
 @@ -20,28 +20,107 @@
 import java.io.IOException;
 import java.util.NavigableSet;
 
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.HColumnDescriptor;
 import org.apache.hadoop.hbase.KeepDeletedCells;
 import org.apache.hadoop.hbase.client.Scan;
+import org.apache.phoenix.util.EnvironmentEdgeManager;
 
 public class ScanInfoUtil {
+    public static final String PHOENIX_MAX_LOOKBACK_AGE_CONF_KEY =
+        "phoenix.max.lookback.age.seconds";
+    public static final long DEFAULT_PHOENIX_MAX_LOOKBACK_AGE = 0L;
+
     private ScanInfoUtil() {
     }
-    
+
     public static boolean isKeepDeletedCells(ScanInfo scanInfo) {
         return scanInfo.getKeepDeletedCells() != KeepDeletedCells.FALSE;
     }
-    
-    public static ScanInfo cloneScanInfoWithKeepDeletedCells(ScanInfo 
scanInfo) {
+
+    public static ScanInfo cloneScanInfoWithKeepDeletedCells(Store store, 
ScanInfo scanInfo) {
         return new ScanInfo(scanInfo.getConfiguration(), scanInfo.getFamily(), 
scanInfo.getMinVersions(),
                     scanInfo.getMaxVersions(), scanInfo.getTtl(), 
KeepDeletedCells.TRUE,
                     scanInfo.getTimeToPurgeDeletes(), 
scanInfo.getComparator());
     }
 
-    public static StoreScanner createStoreScanner(Store store, ScanInfo 
scanInfo, Scan scan, final NavigableSet<byte[]> columns,long readPt) throws 
IOException {
+    public static StoreScanner createStoreScanner(Store store, ScanInfo 
scanInfo, Scan scan,
+                                                  final NavigableSet<byte[]> 
columns,long readPt)
+        throws IOException {
         if(!scan.isReversed()) {
             return new StoreScanner(store, scanInfo, scan, columns,readPt);
         } else {
             return new ReversedStoreScanner(store, scanInfo, scan, 
columns,readPt);
         }
     }
+
+    public static long getTimeToLiveForCompactions(HColumnDescriptor 
columnDescriptor,
+                                                   ScanInfo scanInfo) {
+        long ttl = scanInfo.getTtl();
+        long maxLookbackTtl = getMaxLookback(scanInfo.getConfiguration());
+        if (isMaxLookbackTimeEnabled(maxLookbackTtl)) {
+            if (ttl == Long.MAX_VALUE
+                && columnDescriptor.getKeepDeletedCells() != 
KeepDeletedCells.TRUE) {
+                // If user configured default TTL(FOREVER) and keep deleted 
cells to false or
+                // TTL then to remove unwanted delete markers we should change 
ttl to max lookback age
+                ttl = maxLookbackTtl;
+            } else {
+                //if there is a TTL, use TTL instead of max lookback age.
+                // Max lookback age should be more recent or equal to TTL
+                ttl = Math.max(ttl, maxLookbackTtl);
+            }
+        }
+
+        return ttl;
+    }
+
+    /*
+     * If KeepDeletedCells.FALSE, KeepDeletedCells.TTL ,
+     * let delete markers age once lookback age is done.
+     */
+    private static KeepDeletedCells getKeepDeletedCells(final Store store, 
ScanType scanType) {
+        //if we're doing a minor compaction or flush, always set keep deleted 
cells
+        //to true. Otherwise, if keep deleted cells is false or TTL, use 
KeepDeletedCells TTL,
+        //where the value of the ttl might be overriden to the max lookback 
age elsewhere
+        return (store.getFamily().getKeepDeletedCells() == 
KeepDeletedCells.TRUE
+            || scanType.equals(ScanType.COMPACT_RETAIN_DELETES)) ?
+            KeepDeletedCells.TRUE : KeepDeletedCells.TTL;
+    }
+
+    /*
+     * if the user set a TTL we should leave MIN_VERSIONS at the default (0 in 
most of the cases).
+     * Otherwise the data (1st version) will not be removed after the TTL.
+     */
+    private static int getMinVersions(ScanInfo oldScanInfo, final Store store) 
{
+        return oldScanInfo.getTtl() != Long.MAX_VALUE ? 
store.getFamily().getMinVersions()
+            : Math.max(store.getFamily().getMinVersions(), 1);
+    }
+
+    public static ScanInfo getScanInfoForFlushesAndCompactions(Configuration 
conf,
+                                                               ScanInfo 
oldScanInfo,
+                                                         final Store store,
+                                                         ScanType type) {
+        long ttl = ScanInfoUtil.getTimeToLiveForCompactions(store.getFamily(), 
oldScanInfo);
 
 Review comment:
   nit: no need to provide the class name. 

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to