private static <T extends RegionObserver> T find(final TableName tableName, Class<T> clz) throws IOException, InterruptedException { HRegion region = find(tableName); Coprocessor cp = region.getCoprocessorHost().findCoprocessor(clz.getName()); assertTrue("The cp instance should be " + clz.getName() + ", current instance is " + cp.getClass().getName(), clz.isInstance(cp)); return clz.cast(cp); }
if (region.getRegionInfo().getRegionNameAsString().startsWith(tableName.getNameAsString())) { found_1 = found_1 || (region.getCoprocessorHost().findCoprocessor(cpName1) != null); found_2 = found_2 || (region.getCoprocessorHost().findCoprocessor(cpName2) != null); found_3 = found_3 || (region.getCoprocessorHost().findCoprocessor("SimpleRegionObserver") != null); found_5 = found_5 || (region.getCoprocessorHost().findCoprocessor(cpName5) != null);
public void testRegionObserverStacking() throws Exception { byte[] ROW = Bytes.toBytes("testRow"); byte[] TABLE = Bytes.toBytes(this.getClass().getSimpleName()); byte[] A = Bytes.toBytes("A"); byte[][] FAMILIES = new byte[][] { A } ; Configuration conf = TEST_UTIL.getConfiguration(); HRegion region = initHRegion(TABLE, getClass().getName(), conf, FAMILIES); RegionCoprocessorHost h = region.getCoprocessorHost(); h.load(ObserverA.class, Coprocessor.PRIORITY_HIGHEST, conf); h.load(ObserverB.class, Coprocessor.PRIORITY_USER, conf); h.load(ObserverC.class, Coprocessor.PRIORITY_LOWEST, conf); Put put = new Put(ROW); put.addColumn(A, A, A); region.put(put); Coprocessor c = h.findCoprocessor(ObserverA.class.getName()); long idA = ((ObserverA)c).id; c = h.findCoprocessor(ObserverB.class.getName()); long idB = ((ObserverB)c).id; c = h.findCoprocessor(ObserverC.class.getName()); long idC = ((ObserverC)c).id; assertTrue(idA < idB); assertTrue(idB < idC); HBaseTestingUtility.closeRegionAndWAL(region); } }
private static List<AccessController> getAccessControllers(MiniHBaseCluster cluster) { List<AccessController> result = Lists.newArrayList(); for (RegionServerThread t: cluster.getLiveRegionServerThreads()) { for (HRegion region: t.getRegionServer().getOnlineRegionsLocalContext()) { Coprocessor cp = region.getCoprocessorHost().findCoprocessor(AccessController.class); if (cp != null) { result.add((AccessController)cp); } } } return result; }
private void verifyMethodResult(Class<?> coprocessor, String methodName[], TableName tableName, Object value[]) throws IOException { try { for (JVMClusterUtil.RegionServerThread t : cluster.getRegionServerThreads()) { if (!t.isAlive() || t.getRegionServer().isAborted() || t.getRegionServer().isStopping()) { continue; } for (RegionInfo r : ProtobufUtil .getOnlineRegions(t.getRegionServer().getRSRpcServices())) { if (!r.getTable().equals(tableName)) { continue; } RegionCoprocessorHost cph = t.getRegionServer().getOnlineRegion(r.getRegionName()).getCoprocessorHost(); Coprocessor cp = cph.findCoprocessor(coprocessor.getName()); assertNotNull(cp); for (int i = 0; i < methodName.length; ++i) { Method m = coprocessor.getMethod(methodName[i]); Object o = m.invoke(cp); assertTrue("Result of " + coprocessor.getName() + "." + methodName[i] + " is expected to be " + value[i].toString() + ", while we get " + o.toString(), o.equals(value[i])); } } } } catch (Exception e) { throw new IOException(e.toString()); } }
@Test // HBASE-6308: Test CP classloader is the CoprocessorClassLoader public void testPrivateClassLoader() throws Exception { File jarFile = buildCoprocessorJar(cpName4); // create a table that references the jar HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(cpName4)); htd.addFamily(new HColumnDescriptor("test")); htd.setValue("COPROCESSOR$1", getLocalPath(jarFile) + "|" + cpName4 + "|" + Coprocessor.PRIORITY_USER); Admin admin = TEST_UTIL.getAdmin(); admin.createTable(htd); waitForTable(htd.getTableName()); // verify that the coprocessor was loaded correctly boolean found = false; MiniHBaseCluster hbase = TEST_UTIL.getHBaseCluster(); for (HRegion region: hbase.getRegionServer(0).getOnlineRegionsLocalContext()) { if (region.getRegionInfo().getRegionNameAsString().startsWith(cpName4)) { Coprocessor cp = region.getCoprocessorHost().findCoprocessor(cpName4); if (cp != null) { found = true; assertEquals("Class " + cpName4 + " was not loaded by CoprocessorClassLoader", cp.getClass().getClassLoader().getClass(), CoprocessorClassLoader.class); } } } assertTrue("Class " + cpName4 + " was missing on a region", found); }
HRegion initHRegion (TableName tableName, String callingMethod, Configuration conf, Class<?> [] implClasses, byte [][] families) throws IOException { HTableDescriptor htd = new HTableDescriptor(tableName); for(byte [] family : families) { htd.addFamily(new HColumnDescriptor(family)); } ChunkCreator.initialize(MemStoreLABImpl.CHUNK_SIZE_DEFAULT, false, 0, 0, 0, null); RegionInfo info = RegionInfoBuilder.newBuilder(tableName) .setStartKey(null) .setEndKey(null) .setSplit(false) .build(); Path path = new Path(DIR + callingMethod); HRegion r = HBaseTestingUtility.createRegionAndWAL(info, path, conf, htd); // this following piece is a hack. RegionCoprocessorHost host = new RegionCoprocessorHost(r, Mockito.mock(RegionServerServices.class), conf); r.setCoprocessorHost(host); for (Class<?> implClass : implClasses) { host.load((Class<? extends RegionCoprocessor>) implClass, Coprocessor.PRIORITY_USER, conf); Coprocessor c = host.findCoprocessor(implClass.getName()); assertNotNull(c); } // Here we have to call pre and postOpen explicitly. host.preOpen(); host.postOpen(); return r; }
@Test // HBASE-3516: Test CP Class loading from local file system public void testClassLoadingFromLocalFS() throws Exception { File jarFile = buildCoprocessorJar(cpName3); // create a table that references the jar HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(cpName3)); htd.addFamily(new HColumnDescriptor("test")); htd.setValue("COPROCESSOR$1", getLocalPath(jarFile) + "|" + cpName3 + "|" + Coprocessor.PRIORITY_USER); Admin admin = TEST_UTIL.getAdmin(); admin.createTable(htd); waitForTable(htd.getTableName()); // verify that the coprocessor was loaded boolean found = false; MiniHBaseCluster hbase = TEST_UTIL.getHBaseCluster(); for (HRegion region: hbase.getRegionServer(0).getOnlineRegionsLocalContext()) { if (region.getRegionInfo().getRegionNameAsString().startsWith(cpName3)) { found = (region.getCoprocessorHost().findCoprocessor(cpName3) != null); } } assertTrue("Class " + cpName3 + " was missing on a region", found); }
Coprocessor c = region.getCoprocessorHost().findCoprocessor(CoprocessorImpl.class); Coprocessor c2 = region.getCoprocessorHost().findCoprocessor(CoprocessorII.class); Object o = ((CoprocessorImpl)c).getSharedData().get("test1"); Object o2 = ((CoprocessorII)c2).getSharedData().get("test2"); c = region.getCoprocessorHost().findCoprocessor(CoprocessorImpl.class); c2 = region.getCoprocessorHost().findCoprocessor(CoprocessorII.class); } catch (org.apache.hadoop.hbase.DoNotRetryIOException xc) { assertNull(region.getCoprocessorHost().findCoprocessor(CoprocessorII.class)); c = region.getCoprocessorHost().findCoprocessor(CoprocessorImpl.class); assertTrue(((CoprocessorImpl)c).getSharedData().get("test1") == o); c = c2 = null; c = region.getCoprocessorHost().findCoprocessor(CoprocessorImpl.class); c2 = region.getCoprocessorHost().findCoprocessor(CoprocessorII.class);
Coprocessor cp = firstRegion.getCoprocessorHost().findCoprocessor(EvenOnlyCompactor.class); assertNotNull("EvenOnlyCompactor coprocessor should be loaded", cp); EvenOnlyCompactor compactor = (EvenOnlyCompactor) cp;
@Override public Void run() throws Exception { Path p = runWALSplit(newConf); LOG.info("WALSplit path == " + p); // Make a new wal for new region open. final WALFactory wals2 = new WALFactory(conf, ServerName.valueOf(currentTest.getMethodName() + "2", 16010, System.currentTimeMillis()) .toString()); WAL wal2 = wals2.getWAL(null); HRegion region = HRegion.openHRegion(newConf, FileSystem.get(newConf), hbaseRootDir, hri, htd, wal2, TEST_UTIL.getHBaseCluster().getRegionServer(0), null); SampleRegionWALCoprocessor cp2 = region.getCoprocessorHost().findCoprocessor(SampleRegionWALCoprocessor.class); // TODO: asserting here is problematic. assertNotNull(cp2); assertTrue(cp2.isPreWALRestoreCalled()); assertTrue(cp2.isPostWALRestoreCalled()); region.close(); wals2.close(); return null; } });
@Test public void testCoprocessorInterface() throws IOException { TableName tableName = TableName.valueOf(name.getMethodName()); byte [][] families = { fam1, fam2, fam3 }; Configuration hc = initConfig(); HRegion region = initHRegion(tableName, name.getMethodName(), hc, new Class<?>[]{CoprocessorImpl.class}, families); for (int i = 0; i < 3; i++) { HBaseTestCase.addContent(region, fam3); region.flush(true); } region.compact(false); // HBASE-4197 Scan s = new Scan(); RegionScanner scanner = region.getCoprocessorHost().postScannerOpen(s, region.getScanner(s)); assertTrue(scanner instanceof CustomScanner); // this would throw an exception before HBASE-4197 scanner.next(new ArrayList<>()); HBaseTestingUtility.closeRegionAndWAL(region); Coprocessor c = region.getCoprocessorHost().findCoprocessor(CoprocessorImpl.class); assertTrue("Coprocessor not started", ((CoprocessorImpl)c).wasStarted()); assertTrue("Coprocessor not stopped", ((CoprocessorImpl)c).wasStopped()); assertTrue(((CoprocessorImpl)c).wasOpened()); assertTrue(((CoprocessorImpl)c).wasClosed()); assertTrue(((CoprocessorImpl)c).wasFlushed()); assertTrue(((CoprocessorImpl)c).wasCompacted()); }
(Indexer) region.getCoprocessorHost().findCoprocessor(Indexer.class.getName()); CoveredColumnsIndexBuilder builder = (CoveredColumnsIndexBuilder) indexer.getBuilderForTesting();
private static <T extends RegionObserver> T find(final TableName tableName, Class<T> clz) throws IOException, InterruptedException { HRegion region = find(tableName); Coprocessor cp = region.getCoprocessorHost().findCoprocessor(clz.getName()); assertTrue("The cp instance should be " + clz.getName() + ", current instance is " + cp.getClass().getName(), clz.isInstance(cp)); return clz.cast(cp); }
@Override public void setCoprocessorTimestampOracle(TimestampOracle timeOracle) { Coprocessor cp = region.getCoprocessorHost().findCoprocessor(IncrementHandler.class.getName()); assertNotNull(cp); ((IncrementHandler) cp).setTimestampOracle(timeOracle); }
@Override public void setCoprocessorTimestampOracle(TimestampOracle timeOracle) { Coprocessor cp = region.getCoprocessorHost().findCoprocessor(IncrementHandler.class.getName()); assertNotNull(cp); ((IncrementHandler) cp).setTimestampOracle(timeOracle); }
@Override public void setCoprocessorTimestampOracle(TimestampOracle timeOracle) { Coprocessor cp = region.getCoprocessorHost().findCoprocessor(IncrementHandler.class.getName()); assertNotNull(cp); ((IncrementHandler) cp).setTimestampOracle(timeOracle); }
@Override public void setCoprocessorTimestampOracle(TimestampOracle timeOracle) { Coprocessor cp = region.getCoprocessorHost().findCoprocessor(IncrementHandler.class.getName()); assertNotNull(cp); ((IncrementHandler) cp).setTimestampOracle(timeOracle); }
@Override public void setCoprocessorTimestampOracle(TimestampOracle timeOracle) { Coprocessor cp = region.getCoprocessorHost().findCoprocessor(IncrementHandler.class.getName()); assertNotNull(cp); ((IncrementHandler) cp).setTimestampOracle(timeOracle); }
private static List<AccessController> getAccessControllers(MiniHBaseCluster cluster) { List<AccessController> result = Lists.newArrayList(); for (RegionServerThread t: cluster.getLiveRegionServerThreads()) { for (HRegion region: t.getRegionServer().getOnlineRegionsLocalContext()) { Coprocessor cp = region.getCoprocessorHost().findCoprocessor(AccessController.class); if (cp != null) { result.add((AccessController)cp); } } } return result; }