diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/BaseRegionObserver.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/BaseRegionObserver.java index 9e482bce217..769f298e32c 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/BaseRegionObserver.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/BaseRegionObserver.java @@ -140,7 +140,8 @@ public abstract class BaseRegionObserver implements RegionObserver { @Override public InternalScanner preCompact(ObserverContext e, - final HStore store, final InternalScanner scanner) throws IOException { + final HStore store, final InternalScanner scanner, final ScanType scanType) + throws IOException { return scanner; } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/RegionObserver.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/RegionObserver.java index 443ce2306a3..42d96f27a14 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/RegionObserver.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/coprocessor/RegionObserver.java @@ -167,12 +167,14 @@ public interface RegionObserver extends Coprocessor { * @param store the store being compacted * @param scanner the scanner over existing data used in the store file * rewriting + * @param scanType type of Scan * @return the scanner to use during compaction. Should not be {@code null} * unless the implementation is writing new store files on its own. * @throws IOException if an error occurred on the coprocessor */ InternalScanner preCompact(final ObserverContext c, - final HStore store, final InternalScanner scanner) throws IOException; + final HStore store, final InternalScanner scanner, + final ScanType scanType) throws IOException; /** * Called prior to writing the {@link StoreFile}s selected for compaction into diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/Compactor.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/Compactor.java index 1cb8b091b0e..1e8471246a9 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/Compactor.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/Compactor.java @@ -133,17 +133,17 @@ class Compactor extends Configured { .preCompactScannerOpen(store, scanners, majorCompaction ? ScanType.MAJOR_COMPACT : ScanType.MINOR_COMPACT, earliestPutTs); } + ScanType scanType = majorCompaction? ScanType.MAJOR_COMPACT : ScanType.MINOR_COMPACT; if (scanner == null) { Scan scan = new Scan(); scan.setMaxVersions(store.getFamily().getMaxVersions()); /* Include deletes, unless we are doing a major compaction */ scanner = new StoreScanner(store, store.scanInfo, scan, scanners, - majorCompaction? ScanType.MAJOR_COMPACT : ScanType.MINOR_COMPACT, - smallestReadPoint, earliestPutTs); + scanType, smallestReadPoint, earliestPutTs); } if (store.getHRegion().getCoprocessorHost() != null) { InternalScanner cpScanner = - store.getHRegion().getCoprocessorHost().preCompact(store, scanner); + store.getHRegion().getCoprocessorHost().preCompact(store, scanner, scanType); // NULL scanner returned from coprocessor hooks means skip normal processing if (cpScanner == null) { return null; diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RegionCoprocessorHost.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RegionCoprocessorHost.java index 2e288d17b0e..0a2311c9e1e 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RegionCoprocessorHost.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RegionCoprocessorHost.java @@ -425,9 +425,11 @@ public class RegionCoprocessorHost * Called prior to rewriting the store files selected for compaction * @param store the store being compacted * @param scanner the scanner used to read store data during compaction + * @param scanType type of Scan * @throws IOException */ - public InternalScanner preCompact(HStore store, InternalScanner scanner) throws IOException { + public InternalScanner preCompact(HStore store, InternalScanner scanner, + ScanType scanType) throws IOException { ObserverContext ctx = null; boolean bypass = false; for (RegionEnvironment env: coprocessors) { @@ -435,7 +437,7 @@ public class RegionCoprocessorHost ctx = ObserverContext.createAndPrepare(env, ctx); try { scanner = ((RegionObserver)env.getInstance()).preCompact( - ctx, store, scanner); + ctx, store, scanner, scanType); } catch (Throwable e) { handleCoprocessorThrowable(env,e); } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/security/access/AccessController.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/security/access/AccessController.java index 4e3b065663e..58b11d75c7f 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/security/access/AccessController.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/security/access/AccessController.java @@ -58,6 +58,7 @@ import org.apache.hadoop.hbase.regionserver.HRegion; import org.apache.hadoop.hbase.regionserver.InternalScanner; import org.apache.hadoop.hbase.regionserver.RegionScanner; import org.apache.hadoop.hbase.regionserver.HStore; +import org.apache.hadoop.hbase.regionserver.ScanType; import org.apache.hadoop.hbase.regionserver.StoreFile; import org.apache.hadoop.hbase.regionserver.wal.WALEdit; import org.apache.hadoop.hbase.security.AccessDeniedException; @@ -765,7 +766,8 @@ public class AccessController extends BaseRegionObserver @Override public InternalScanner preCompact(ObserverContext e, - final HStore store, final InternalScanner scanner) throws IOException { + final HStore store, final InternalScanner scanner, final ScanType scanType) + throws IOException { requirePermission("compact", getTableName(e.getEnvironment()), null, null, Action.ADMIN); return scanner; } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/SimpleRegionObserver.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/SimpleRegionObserver.java index 244a508570a..665ee267fc7 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/SimpleRegionObserver.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/SimpleRegionObserver.java @@ -186,7 +186,7 @@ public class SimpleRegionObserver extends BaseRegionObserver { @Override public InternalScanner preCompact(ObserverContext e, - HStore store, InternalScanner scanner) { + HStore store, InternalScanner scanner, ScanType scanType) { hadPreCompact = true; return scanner; } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestCoprocessorInterface.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestCoprocessorInterface.java index 300abea6517..62dfce1707a 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestCoprocessorInterface.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestCoprocessorInterface.java @@ -50,6 +50,7 @@ import org.apache.hadoop.hbase.regionserver.HStore; import org.apache.hadoop.hbase.regionserver.InternalScanner; import org.apache.hadoop.hbase.regionserver.RegionCoprocessorHost; import org.apache.hadoop.hbase.regionserver.RegionScanner; +import org.apache.hadoop.hbase.regionserver.ScanType; import org.apache.hadoop.hbase.regionserver.SplitTransaction; import org.apache.hadoop.hbase.regionserver.StoreFile; import org.apache.hadoop.hbase.util.Bytes; @@ -186,7 +187,7 @@ public class TestCoprocessorInterface extends HBaseTestCase { } @Override public InternalScanner preCompact(ObserverContext e, - HStore store, InternalScanner scanner) { + HStore store, InternalScanner scanner, ScanType scanType) { preCompactCalled = true; return scanner; } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionObserverInterface.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionObserverInterface.java index 8ceb712e83f..dbd20d6e39a 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionObserverInterface.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/coprocessor/TestRegionObserverInterface.java @@ -61,6 +61,7 @@ import org.apache.hadoop.hbase.regionserver.HRegion; import org.apache.hadoop.hbase.regionserver.InternalScanner; import org.apache.hadoop.hbase.regionserver.RegionCoprocessorHost; import org.apache.hadoop.hbase.regionserver.HStore; +import org.apache.hadoop.hbase.regionserver.ScanType; import org.apache.hadoop.hbase.regionserver.StoreFile; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; @@ -315,7 +316,7 @@ public class TestRegionObserverInterface { @Override public InternalScanner preCompact(ObserverContext e, - HStore store, final InternalScanner scanner) { + HStore store, final InternalScanner scanner, final ScanType scanType) { return new InternalScanner() { @Override public boolean next(List results) throws IOException { diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestAccessController.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestAccessController.java index b3c80fa46df..bd40d6cb892 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestAccessController.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestAccessController.java @@ -70,6 +70,7 @@ import org.apache.hadoop.hbase.protobuf.generated.AccessControlProtos.CheckPermi import org.apache.hadoop.hbase.regionserver.HRegion; import org.apache.hadoop.hbase.regionserver.RegionCoprocessorHost; import org.apache.hadoop.hbase.regionserver.RegionServerCoprocessorHost; +import org.apache.hadoop.hbase.regionserver.ScanType; import org.apache.hadoop.hbase.security.AccessDeniedException; import org.apache.hadoop.hbase.security.User; import org.apache.hadoop.hbase.security.access.Permission.Action; @@ -567,7 +568,8 @@ public class TestAccessController { public void testCompact() throws Exception { PrivilegedExceptionAction action = new PrivilegedExceptionAction() { public Object run() throws Exception { - ACCESS_CONTROLLER.preCompact(ObserverContext.createAndPrepare(RCP_ENV, null), null, null); + ACCESS_CONTROLLER.preCompact(ObserverContext.createAndPrepare(RCP_ENV, null), null, null, + ScanType.MINOR_COMPACT); return null; } };