public ClientSideRegionScanner(Configuration conf, FileSystem fs, Path rootDir, TableDescriptor htd, RegionInfo hri, Scan scan, ScanMetrics scanMetrics) throws IOException { // region is immutable, set isolation level scan.setIsolationLevel(IsolationLevel.READ_UNCOMMITTED); htd = TableDescriptorBuilder.newBuilder(htd).setReadOnly(true).build(); // open region from the snapshot directory region = HRegion.newHRegion(FSUtils.getTableDir(rootDir, htd.getTableName()), null, fs, conf, hri, htd, null); // we won't initialize the MobFileCache when not running in RS process. so provided an // initialized cache. Consider the case: an CF was set from an mob to non-mob. if we only // initialize cache for MOB region, NPE from HMobStore will still happen. So Initialize the // cache for every region although it may hasn't any mob CF, BTW the cache is very light-weight. region.setMobFileCache(new MobFileCache(conf)); region.initialize(); // create an internal region scanner this.scanner = region.getScanner(scan); values = new ArrayList<>(); if (scanMetrics == null) { initScanMetrics(scan); } else { this.scanMetrics = scanMetrics; } region.startRegionOperation(); }
/** * Verify schema change for read only table */ @Test public void testReadOnlyTableModify() throws IOException, InterruptedException { final TableName tableName = TableName.valueOf(name.getMethodName()); TEST_UTIL.createTable(tableName, HConstants.CATALOG_FAMILY).close(); // Make table read only TableDescriptor htd = TableDescriptorBuilder.newBuilder(this.admin.getDescriptor(tableName)) .setReadOnly(true).build(); admin.modifyTable(htd); // try to modify the read only table now htd = TableDescriptorBuilder.newBuilder(this.admin.getDescriptor(tableName)) .setCompactionEnabled(false).build(); admin.modifyTable(htd); // Delete the table this.admin.disableTable(tableName); this.admin.deleteTable(tableName); assertFalse(this.admin.tableExists(tableName)); }
private static HRegion initHRegion(TableName tableName, byte[] startKey, byte[] stopKey, String callingMethod, Configuration conf, HBaseTestingUtility testUtil, boolean isReadOnly, byte[]... families) throws IOException { RegionInfo regionInfo = RegionInfoBuilder.newBuilder(tableName).setStartKey(startKey).setEndKey(stopKey).build(); TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(tableName); builder.setReadOnly(isReadOnly).setDurability(Durability.SYNC_WAL); for (byte[] family : families) { builder.setColumnFamily( ColumnFamilyDescriptorBuilder.newBuilder(family).setMaxVersions(Integer.MAX_VALUE) .build()); } return HBaseTestingUtility .createRegionAndWAL(regionInfo, testUtil.getDataTestDir(callingMethod), conf, builder.build(), BlockCacheFactory.createBlockCache(conf)); } }
@Test public void testPb() throws DeserializationException, IOException { final int v = 123; TableDescriptor htd = TableDescriptorBuilder.newBuilder(TableName.META_TABLE_NAME) .setMaxFileSize(v) .setDurability(Durability.ASYNC_WAL) .setReadOnly(true) .setRegionReplication(2) .build(); byte [] bytes = TableDescriptorBuilder.toByteArray(htd); TableDescriptor deserializedHtd = TableDescriptorBuilder.parseFrom(bytes); assertEquals(htd, deserializedHtd); assertEquals(v, deserializedHtd.getMaxFileSize()); assertTrue(deserializedHtd.isReadOnly()); assertEquals(Durability.ASYNC_WAL, deserializedHtd.getDurability()); assertEquals(2, deserializedHtd.getRegionReplication()); }
@Test public void testPb() throws DeserializationException, IOException { final int v = 123; TableDescriptor htd = TableDescriptorBuilder.newBuilder(TableName.META_TABLE_NAME) .setMaxFileSize(v) .setDurability(Durability.ASYNC_WAL) .setReadOnly(true) .setRegionReplication(2) .build(); byte [] bytes = TableDescriptorBuilder.toByteArray(htd); TableDescriptor deserializedHtd = TableDescriptorBuilder.parseFrom(bytes); assertEquals(htd, deserializedHtd); assertEquals(v, deserializedHtd.getMaxFileSize()); assertTrue(deserializedHtd.isReadOnly()); assertEquals(Durability.ASYNC_WAL, deserializedHtd.getDurability()); assertEquals(2, deserializedHtd.getRegionReplication()); }
/** * Verify schema change for read only table */ @Test public void testReadOnlyTableModify() throws IOException, InterruptedException { final TableName tableName = TableName.valueOf(name.getMethodName()); TEST_UTIL.createTable(tableName, HConstants.CATALOG_FAMILY).close(); // Make table read only TableDescriptor htd = TableDescriptorBuilder.newBuilder(this.admin.getDescriptor(tableName)) .setReadOnly(true).build(); admin.modifyTable(htd); // try to modify the read only table now htd = TableDescriptorBuilder.newBuilder(this.admin.getDescriptor(tableName)) .setCompactionEnabled(false).build(); admin.modifyTable(htd); // Delete the table this.admin.disableTable(tableName); this.admin.deleteTable(tableName); assertFalse(this.admin.tableExists(tableName)); }