private HRegionInfo hri(long regionId, int replicaId) { TableName table = TableName.valueOf("table"); byte[] startKey = HConstants.EMPTY_START_ROW; byte[] endKey = HConstants.EMPTY_END_ROW; HRegionInfo info = new HRegionInfo(table, startKey, endKey, false, regionId, replicaId); return info; }
private HRegionInfo createRandomRegion(final String name) { HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(name)); String [] families = new String [] {"info", "anchor"}; for (int i = 0; i < families.length; i++) { htd.addFamily(new HColumnDescriptor(families[i])); } return new HRegionInfo(htd.getTableName(), HConstants.EMPTY_START_ROW, HConstants.EMPTY_END_ROW); }
@Test public void testLastRegionCompare() { HTableDescriptor tableDesc = new HTableDescriptor(TableName.valueOf(name.getMethodName())); HRegionInfo hrip = new HRegionInfo( tableDesc.getTableName(), Bytes.toBytes("a"), new byte[0]); HRegionInfo hric = new HRegionInfo( tableDesc.getTableName(), Bytes.toBytes("a"), Bytes.toBytes("b")); assertTrue(hrip.compareTo(hric) > 0); }
@Test public void testImmutable() { HRegionInfo hri = new HRegionInfo(TableName.valueOf(name.getMethodName())); ImmutableHRegionInfo immutableHri = new ImmutableHRegionInfo(hri); TEST_FUNCTIONS.forEach(f -> { try { f.accept(immutableHri); fail("ImmutableHRegionInfo can't be modified !!!"); } catch(UnsupportedOperationException e) { } }); }
@Test public void testThreadCreation() throws Exception { final int NB_REGS = 100; List<Get> gets = new ArrayList<>(NB_REGS); for (int i = 0; i < NB_REGS; i++) { HRegionInfo hri = new HRegionInfo( DUMMY_TABLE, Bytes.toBytes(i * 10L), Bytes.toBytes(i * 10L + 9L), false, i); HRegionLocation hrl = new HRegionLocation(hri, i % 2 == 0 ? sn : sn2); hrls.add(hrl); Get get = new Get(Bytes.toBytes(i * 10L)); gets.add(get);
@Test public void testGetStoreArchivePath() throws IOException { byte[] family = Bytes.toBytes("Family"); Path tabledir = FSUtils.getTableDir(rootDir, TableName.valueOf(name.getMethodName())); HRegionInfo region = new HRegionInfo(TableName.valueOf(name.getMethodName())); Configuration conf = new Configuration(); FSUtils.setRootDir(conf, new Path("root")); assertNotNull(HFileArchiveUtil.getStoreArchivePath(conf, region, tabledir, family)); } }
@Test public void testHBaseGroupScanAssignmentAllPreferred() throws Exception { NavigableMap<HRegionInfo,ServerName> regionsToScan = Maps.newTreeMap(); regionsToScan.put(new HRegionInfo(TABLE_NAME, splits[0], splits[1]), SERVER_A); regionsToScan.put(new HRegionInfo(TABLE_NAME, splits[1], splits[2]), SERVER_A); regionsToScan.put(new HRegionInfo(TABLE_NAME, splits[2], splits[3]), SERVER_B); regionsToScan.put(new HRegionInfo(TABLE_NAME, splits[3], splits[4]), SERVER_B); regionsToScan.put(new HRegionInfo(TABLE_NAME, splits[4], splits[5]), SERVER_C); regionsToScan.put(new HRegionInfo(TABLE_NAME, splits[5], splits[6]), SERVER_C); regionsToScan.put(new HRegionInfo(TABLE_NAME, splits[6], splits[7]), SERVER_D); regionsToScan.put(new HRegionInfo(TABLE_NAME, splits[7], splits[0]), SERVER_D);
private void setupOperations() throws Exception { // Create set of operations based on --ops_type command line argument. final ProcedureFactory[] tableOps = new ProcedureFactory[numTables]; for (int i = 0; i < numTables; ++i) { tableOps[i] = new TableProcedureFactory(TableName.valueOf("testTableLock-" + i)); } final ProcedureFactory[] regionOps = new ProcedureFactory[numTables * regionsPerTable]; for (int i = 0; i < numTables; ++i) { for (int j = 0; j < regionsPerTable; ++j) { regionOps[i * regionsPerTable + j] = new RegionProcedureFactory( new HRegionInfo(((TableProcedureFactory)tableOps[i]).tableName, Bytes.toBytes(j), Bytes.toBytes(j + 1))); } } if (opsType.equals("table")) { System.out.println("Operations: table only"); ops = tableOps; } else if (opsType.equals("region")) { System.out.println("Operations: region only"); ops = regionOps; } else if (opsType.equals("both")) { System.out.println("Operations: both (table + region)"); ops = (ProcedureFactory[])ArrayUtils.addAll(tableOps, regionOps); } else { throw new Exception("-ops_type should be one of table/region/both."); } }
private HRegion initHRegion(byte [] tableName, String callingMethod, byte[] ... families) throws IOException { HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(tableName)); for(byte [] family : families) { htd.addFamily(new HColumnDescriptor(family)); } HRegionInfo info = new HRegionInfo(htd.getTableName(), null, null, false); return HBTU.createLocalHRegion(info, htd); }
@Test public void testGetName() { TableRegionModel model = buildTestModel(); String modelName = model.getName(); HRegionInfo hri = new HRegionInfo(TableName.valueOf(TABLE), START_KEY, END_KEY, false, ID); assertEquals(modelName, hri.getRegionNameAsString()); }
@Test public void testScanDoesNotCleanRegionsWithExistingParents() throws Exception { TableDescriptor td = createTableDescriptorForCurrentMethod(); HRegionInfo parent = new HRegionInfo(td.getTableName(), Bytes.toBytes("aaa"), HConstants.EMPTY_BYTE_ARRAY, true); new HRegionInfo(td.getTableName(), Bytes.toBytes("aaa"), Bytes.toBytes("ccc"), true); Thread.sleep(1001); new HRegionInfo(td.getTableName(), Bytes.toBytes("aaa"), Bytes.toBytes("bbb"), false); HRegionInfo splitab = new HRegionInfo(td.getTableName(), Bytes.toBytes("bbb"), Bytes.toBytes("ccc"), false); new HRegionInfo(td.getTableName(), Bytes.toBytes("ccc"), HConstants.EMPTY_BYTE_ARRAY); Thread.sleep(1001);
@Test public void testFindsSnapshotFilesWhenCleaning() throws IOException { Configuration conf = TEST_UTIL.getConfiguration(); FSUtils.setRootDir(conf, TEST_UTIL.getDataTestDir()); Path rootDir = FSUtils.getRootDir(conf); Path archivedHfileDir = new Path(TEST_UTIL.getDataTestDir(), HConstants.HFILE_ARCHIVE_DIRECTORY); FileSystem fs = FileSystem.get(conf); SnapshotHFileCleaner cleaner = new SnapshotHFileCleaner(); cleaner.setConf(conf); // write an hfile to the snapshot directory String snapshotName = "snapshot"; byte[] snapshot = Bytes.toBytes(snapshotName); final TableName tableName = TableName.valueOf(name.getMethodName()); Path snapshotDir = SnapshotDescriptionUtils.getCompletedSnapshotDir(snapshotName, rootDir); HRegionInfo mockRegion = new HRegionInfo(tableName); Path regionSnapshotDir = new Path(snapshotDir, mockRegion.getEncodedName()); Path familyDir = new Path(regionSnapshotDir, "family"); // create a reference to a supposedly valid hfile String hfile = "fd1e73e8a96c486090c5cec07b4894c4"; Path refFile = new Path(familyDir, hfile); // make sure the reference file exists fs.create(refFile); // create the hfile in the archive fs.mkdirs(archivedHfileDir); fs.createNewFile(new Path(archivedHfileDir, hfile)); // make sure that the file isn't deletable assertFalse(cleaner.isFileDeletable(fs.getFileStatus(refFile))); }
@SuppressWarnings("SelfComparison") @Test public void testComparator() { final TableName tableName = TableName.valueOf(name.getMethodName()); byte[] empty = new byte[0]; HRegionInfo older = new HRegionInfo(tableName, empty, empty, false, 0L); HRegionInfo newer = new HRegionInfo(tableName, empty, empty, false, 1L); assertTrue(older.compareTo(newer) < 0); assertTrue(newer.compareTo(older) > 0); HRegionInfo a = new HRegionInfo(TableName.valueOf("a"), null, null); HRegionInfo b = new HRegionInfo(TableName.valueOf("b"), null, null); assertNotEquals(0, a.compareTo(b)); HTableDescriptor t = new HTableDescriptor(TableName.valueOf("t")); byte [] midway = Bytes.toBytes("midway"); a = new HRegionInfo(t.getTableName(), null, midway); b = new HRegionInfo(t.getTableName(), midway, null); assertTrue(a.compareTo(b) < 0); assertTrue(b.compareTo(a) > 0); assertEquals(a, a); assertEquals(0, a.compareTo(a)); a = new HRegionInfo(t.getTableName(), Bytes.toBytes("a"), Bytes.toBytes("d")); b = new HRegionInfo(t.getTableName(), Bytes.toBytes("e"), Bytes.toBytes("g")); assertTrue(a.compareTo(b) < 0); a = new HRegionInfo(t.getTableName(), Bytes.toBytes("aaaa"), Bytes.toBytes("dddd")); b = new HRegionInfo(t.getTableName(), Bytes.toBytes("e"), Bytes.toBytes("g")); assertTrue(a.compareTo(b) < 0); a = new HRegionInfo(t.getTableName(), Bytes.toBytes("aaaa"), Bytes.toBytes("dddd")); b = new HRegionInfo(t.getTableName(), Bytes.toBytes("aaaa"), Bytes.toBytes("eeee")); assertTrue(a.compareTo(b) < 0);
/** * @param count * @param namespaceSpan * @return <code>count</code> regions */ private static HRegionInfo [] makeHRegionInfos(final byte [] tableName, final int count, final long namespaceSpan) { byte [] startKey = HConstants.EMPTY_BYTE_ARRAY; byte [] endKey = HConstants.EMPTY_BYTE_ARRAY; long interval = namespaceSpan / count; HRegionInfo [] hris = new HRegionInfo[count]; for (int i = 0; i < count; i++) { if (i == 0) { endKey = format(interval); } else { startKey = endKey; if (i == count - 1) endKey = HConstants.EMPTY_BYTE_ARRAY; else endKey = format((i + 1) * interval); } hris[i] = new HRegionInfo(TableName.valueOf(tableName), startKey, endKey); } return hris; }
private HRegion initHRegion(String callingMethod, Configuration conf) throws IOException { HTableDescriptor htd = new HTableDescriptor(TABLENAME); for (byte[] family : FAMILIES) { htd.addFamily(new HColumnDescriptor(family)); } HRegionInfo info = new HRegionInfo(TABLENAME, null, null, false); Path path = new Path(DIR, callingMethod); return HBaseTestingUtility.createRegionAndWAL(info, path, conf, htd); }
@Test public void testRegionDetailsForDisplay() throws IOException { byte[] startKey = new byte[] {0x01, 0x01, 0x02, 0x03}; byte[] endKey = new byte[] {0x01, 0x01, 0x02, 0x04}; Configuration conf = new Configuration(); conf.setBoolean("hbase.display.keys", false); HRegionInfo h = new HRegionInfo(TableName.valueOf(name.getMethodName()), startKey, endKey); checkEquality(h, conf); // check HRIs with non-default replicaId h = new HRegionInfo(TableName.valueOf(name.getMethodName()), startKey, endKey, false, System.currentTimeMillis(), 1); checkEquality(h, conf); Assert.assertArrayEquals(HRegionInfo.HIDDEN_END_KEY, HRegionInfo.getEndKeyForDisplay(h, conf)); Assert.assertArrayEquals(HRegionInfo.HIDDEN_START_KEY, HRegionInfo.getStartKeyForDisplay(h, conf)); RegionState state = RegionState.createForTesting(h, RegionState.State.OPEN); String descriptiveNameForDisplay = HRegionInfo.getDescriptiveNameFromRegionStateForDisplay(state, conf); checkDescriptiveNameEquality(descriptiveNameForDisplay,state.toDescriptiveString(), startKey); conf.setBoolean("hbase.display.keys", true); Assert.assertArrayEquals(endKey, HRegionInfo.getEndKeyForDisplay(h, conf)); Assert.assertArrayEquals(startKey, HRegionInfo.getStartKeyForDisplay(h, conf)); Assert.assertEquals(state.toDescriptiveString(), HRegionInfo.getDescriptiveNameFromRegionStateForDisplay(state, conf)); }
@Test public void testCleanParent() throws IOException, InterruptedException { TableDescriptor td = createTableDescriptorForCurrentMethod(); new HRegionInfo(td.getTableName(), Bytes.toBytes("aaa"), Bytes.toBytes("eee")); HRegionInfo splita = new HRegionInfo(td.getTableName(), Bytes.toBytes("aaa"), Bytes.toBytes("ccc")); HRegionInfo splitb = new HRegionInfo(td.getTableName(), Bytes.toBytes("ccc"), Bytes.toBytes("eee"));
@Test public void testOldEntriesRemoved() { MasterServices masterServices = mock(MasterServices.class); manager.initializeRegionSizes(); TableName tableName = TableName.valueOf("foo"); HRegionInfo region1 = new HRegionInfo(tableName, null, toBytes("a")); HRegionInfo region2 = new HRegionInfo(tableName, toBytes("a"), toBytes("b")); HRegionInfo region3 = new HRegionInfo(tableName, toBytes("b"), toBytes("c")); HRegionInfo region4 = new HRegionInfo(tableName, toBytes("c"), toBytes("d")); HRegionInfo region5 = new HRegionInfo(tableName, toBytes("d"), null);
@Test public void testContainsRange() { HTableDescriptor tableDesc = new HTableDescriptor(TableName.valueOf(name.getMethodName())); HRegionInfo hri = new HRegionInfo( tableDesc.getTableName(), Bytes.toBytes("a"), Bytes.toBytes("g")); // Single row range at start of region assertTrue(hri.containsRange(Bytes.toBytes("a"), Bytes.toBytes("a"))); // Fully contained range assertTrue(hri.containsRange(Bytes.toBytes("b"), Bytes.toBytes("c"))); // Range overlapping start of region assertTrue(hri.containsRange(Bytes.toBytes("a"), Bytes.toBytes("c"))); // Fully contained single-row range assertTrue(hri.containsRange(Bytes.toBytes("c"), Bytes.toBytes("c"))); // Range that overlaps end key and hence doesn't fit assertFalse(hri.containsRange(Bytes.toBytes("a"), Bytes.toBytes("g"))); // Single row range on end key assertFalse(hri.containsRange(Bytes.toBytes("g"), Bytes.toBytes("g"))); // Single row range entirely outside assertFalse(hri.containsRange(Bytes.toBytes("z"), Bytes.toBytes("z"))); // Degenerate range try { hri.containsRange(Bytes.toBytes("z"), Bytes.toBytes("a")); fail("Invalid range did not throw IAE"); } catch (IllegalArgumentException iae) { } }
@BeforeClass public static void before() throws Exception { // Reduce the hdfs block size and prefetch to trigger the file-link reopen // when the file is moved to archive (e.g. compaction) HTU.getConfiguration().setInt(DFSConfigKeys.DFS_BLOCK_SIZE_KEY, 8192); HTU.getConfiguration().setInt(DFSConfigKeys.DFS_CLIENT_READ_PREFETCH_SIZE_KEY, 1); HTU.getConfiguration().setInt(HConstants.HREGION_MEMSTORE_FLUSH_SIZE, 128 * 1024 * 1024); HTU.startMiniCluster(NB_SERVERS); final TableName tableName = TableName.valueOf(TestRegionReplicas.class.getSimpleName()); // Create table then get the single region for our new table. table = HTU.createTable(tableName, f); try (RegionLocator locator = HTU.getConnection().getRegionLocator(tableName)) { hriPrimary = locator.getRegionLocation(row, false).getRegionInfo(); } // mock a secondary region info to open hriSecondary = new HRegionInfo(hriPrimary.getTable(), hriPrimary.getStartKey(), hriPrimary.getEndKey(), hriPrimary.isSplit(), hriPrimary.getRegionId(), 1); // No master TestRegionServerNoMaster.stopMasterAndAssignMeta(HTU); }