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_r363960695
 
 

 ##########
 File path: 
phoenix-core/src/main/java/org/apache/phoenix/coprocessor/BaseScannerRegionObserver.java
 ##########
 @@ -374,20 +382,111 @@ RegionScanner getWrappedScanner(final 
ObserverContext<RegionCoprocessorEnvironme
                 dataRegion, indexMaintainer, null, viewConstants, null, null, 
projector, ptr, useQualiferAsListIndex);
     }
 
+
     @Override
     public KeyValueScanner preStoreScannerOpen(final 
ObserverContext<RegionCoprocessorEnvironment> c,
         final Store store, final Scan scan, final NavigableSet<byte[]> 
targetCols,
         final KeyValueScanner s) throws IOException {
-
-      if (scan.isRaw() || ScanInfoUtil.isKeepDeletedCells(store.getScanInfo()) 
|| scan.getTimeRange().getMax() == HConstants.LATEST_TIMESTAMP || 
TransactionUtil.isTransactionalTimestamp(scan.getTimeRange().getMax())) {
+      if (storeFileScanDoesntNeedAlteration(store, scan)) {
         return s;
       }
       
       if (s!=null) {
           s.close();
       }
-      ScanInfo scanInfo = 
ScanInfoUtil.cloneScanInfoWithKeepDeletedCells(store.getScanInfo());
+      ScanInfo scanInfo = ScanInfoUtil.cloneScanInfoWithKeepDeletedCells(store,
+          store.getScanInfo());
       return ScanInfoUtil.createStoreScanner(store, scanInfo, scan, targetCols,
           
c.getEnvironment().getRegion().getReadpoint(scan.getIsolationLevel()));
     }
+
+    private boolean storeFileScanDoesntNeedAlteration(Store store, Scan scan) {
+        boolean isRaw = scan.isRaw();
+        //true if keep deleted cells is either TRUE or TTL
+        boolean keepDeletedCells = 
ScanInfoUtil.isKeepDeletedCells(store.getScanInfo());
+        boolean timeRangeIsLatest = scan.getTimeRange().getMax() == 
HConstants.LATEST_TIMESTAMP;
+        boolean timestampIsTransactional =
+            
TransactionUtil.isTransactionalTimestamp(scan.getTimeRange().getMax());
+        return isRaw
+            || keepDeletedCells
+            || timeRangeIsLatest
+            || timestampIsTransactional;
+    }
+
+    @Override
+    public InternalScanner preFlushScannerOpen(final 
ObserverContext<RegionCoprocessorEnvironment> c,
+                                               final Store store,
+                                               final KeyValueScanner 
memstoreScanner,
+                                               final InternalScanner s)
+        throws IOException {
+
+        if 
(!ScanInfoUtil.isMaxLookbackTimeEnabled(c.getEnvironment().getConfiguration())){
+            return s;
+        }
+
+        //close last scanner object before creating a new one
+        if(s != null) {
+            s.close();
+        }
+
+        // Called during flushing the memstore to disk.
+        // Need to retain all the delete markers & all the versions
+        Scan scan = new Scan();
+        scan.setMaxVersions(Integer.MAX_VALUE);
+        ScanInfo oldScanInfo = store.getScanInfo();
+
+        Configuration conf = c.getEnvironment().getConfiguration();
+        //minor compactions and flushes both use "compact retain deletes"
+        ScanType scanType = ScanType.COMPACT_RETAIN_DELETES;
+        ScanInfo scanInfo =
+            ScanInfoUtil.getScanInfoForFlushesAndCompactions(conf, 
oldScanInfo, store, scanType);
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Creating the store scanner with :" + scanInfo + ", " +
+                "scan object:" + scan + " for table " + 
store.getTableName().getNameAsString() +
+                " and region " + store.getRegionInfo().getRegionNameAsString() 
+
+                " and cf " + store.getColumnFamilyName());
+        }
+        return new StoreScanner(store, scanInfo, scan, 
Collections.singletonList(memstoreScanner),
+            scanType, store.getSmallestReadPoint(),
+            HConstants.LATEST_TIMESTAMP);
+    }
+
+    @Override
+    public InternalScanner preCompactScannerOpen(
 
 Review comment:
   There is a lot of commonality in the function body of the above two hooks. 
Is it possible to throw that in a common function and invoke it from both the 
hooks?

----------------------------------------------------------------
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