private void setupMockTableName(RegionLocator table) throws IOException { TableName mockTableName = TableName.valueOf("mock_table"); Mockito.doReturn(mockTableName).when(table).getName(); }
private void init(RegionLocator regionLocator, Admin admin) throws IOException { if (!enabled(admin.getConfiguration())) { LOG.info("Region size calculation disabled."); return; } if (regionLocator.getName().isSystemTable()) { LOG.info("Region size calculation disabled for system tables."); return; } LOG.info("Calculating region sizes for table \"" + regionLocator.getName() + "\"."); // Get the servers which host regions of the table Set<ServerName> tableServers = getRegionServersOfTable(regionLocator); for (ServerName tableServerName : tableServers) { for (RegionMetrics regionLoad : admin.getRegionMetrics( tableServerName,regionLocator.getName())) { byte[] regionId = regionLoad.getRegionName(); long regionSizeBytes = ((long) regionLoad.getStoreFileSize().get(Size.Unit.MEGABYTE)) * MEGABYTE; sizeMap.put(regionId, regionSizeBytes); if (LOG.isDebugEnabled()) { LOG.debug("Region " + regionLoad.getNameAsString() + " has size " + regionSizeBytes); } } } LOG.debug("Region sizes calculated"); }
/** * Return the start keys of all of the regions in this table, * as a list of ImmutableBytesWritable. */ private static List<ImmutableBytesWritable> getRegionStartKeys(List<RegionLocator> regionLocators, boolean writeMultipleTables) throws IOException { ArrayList<ImmutableBytesWritable> ret = new ArrayList<>(); for(RegionLocator regionLocator : regionLocators) { TableName tableName = regionLocator.getName(); LOG.info("Looking up current regions for table " + tableName); byte[][] byteKeys = regionLocator.getStartKeys(); for (byte[] byteKey : byteKeys) { byte[] fullKey = byteKey; //HFileOutputFormat2 use case if (writeMultipleTables) { //MultiTableHFileOutputFormat use case fullKey = combineTableNameSuffix(tableName.getName(), byteKey); } if (LOG.isDebugEnabled()) { LOG.debug("SplitPoint startkey for table [" + tableName + "]: [" + Bytes.toStringBinary (fullKey) + "]"); } ret.add(new ImmutableBytesWritable(fullKey)); } } return ret; }
LOG.info("Incremental table " + regionLocator.getName() + " output configured.");
/** * Makes some table with given region names. * */ private RegionLocator mockRegionLocator(String... regionNames) throws IOException { RegionLocator mockedTable = Mockito.mock(RegionLocator.class); when(mockedTable.getName()).thenReturn(TableName.valueOf("sizeTestTable")); List<HRegionLocation> regionLocations = new ArrayList<>(regionNames.length); when(mockedTable.getAllRegionLocations()).thenReturn(regionLocations); for (String regionName : regionNames) { HRegionInfo info = Mockito.mock(HRegionInfo.class); when(info.getRegionName()).thenReturn(regionName.getBytes()); regionLocations.add(new HRegionLocation(info, sn)); } return mockedTable; }
@Override public void perform() throws Exception { LOG.info("Performing action: Restart random RS holding table " + this.locator.getName()); List<HRegionLocation> locations = locator.getAllRegionLocations(); restartRs(locations.get(RandomUtils.nextInt(0, locations.size())).getServerName(), sleepTime); } }
RegionLocator regionLocator, boolean silence, boolean copyFile) throws TableNotFoundException, IOException { if (!admin.isTableAvailable(regionLocator.getName())) { throw new TableNotFoundException("Table " + table.getName() + " is not currently available.");
Table table, RegionLocator regionLocator, boolean silence, boolean copyFile) throws TableNotFoundException, IOException { if (!admin.isTableAvailable(regionLocator.getName())) { throw new TableNotFoundException("Table " + table.getName() + " is not currently available.");
Mockito.when(mockedRegionLocator.getStartEndKeys()). thenReturn(new Pair<byte [][], byte[][]>(startKeys, endKeys)); Mockito.when(mockedRegionLocator.getName()).thenReturn(tableName); return mockedRegionLocator;
private RegionLocator getCachedLocator(TableName tableName) { for (RegionLocator locator : locatorCache) { if (locator.getName().equals(tableName)) { return locator; } } return null; }
private RegionLocator getCachedLocator(TableName tableName) { for (RegionLocator locator : locatorCache) { if (locator.getName().equals(tableName)) { return locator; } } return null; }
private static List<KeyValue> getSplitPoints(RegionLocator regionLocator) throws IOException { List<byte[]> startKeys = ImmutableList.copyOf(regionLocator.getStartKeys()); if (startKeys.isEmpty()) { throw new AssertionError(regionLocator.getName().getNameAsString() + " has no regions!"); } List<KeyValue> splitPoints = Lists.newArrayList(); for (byte[] startKey : startKeys.subList(1, startKeys.size())) { KeyValue kv = KeyValueUtil.createFirstOnRow(startKey); LOG.debug("split row: " + Bytes.toString(CellUtil.cloneRow(kv))); splitPoints.add(kv); } return splitPoints; }
private void setupMockTableName(RegionLocator table) throws IOException { TableName mockTableName = TableName.valueOf("mock_table"); Mockito.doReturn(mockTableName).when(table).getName(); }
private void setupMockTableName(RegionLocator table) throws IOException { TableName mockTableName = TableName.valueOf("mock_table"); Mockito.doReturn(mockTableName).when(table).getName(); }
private void setupMockTableName(RegionLocator table) throws IOException { TableName mockTableName = TableName.valueOf("mock_table"); Mockito.doReturn(mockTableName).when(table).getName(); }
private void setupMockTableName(RegionLocator table) throws IOException { TableName mockTableName = TableName.valueOf("mock_table"); Mockito.doReturn(mockTableName).when(table).getName(); }
/** * Makes some table with given region names. * */ private RegionLocator mockRegionLocator(String... regionNames) throws IOException { RegionLocator mockedTable = Mockito.mock(RegionLocator.class); when(mockedTable.getName()).thenReturn(TableName.valueOf("sizeTestTable")); List<HRegionLocation> regionLocations = new ArrayList<>(regionNames.length); when(mockedTable.getAllRegionLocations()).thenReturn(regionLocations); for (String regionName : regionNames) { HRegionInfo info = Mockito.mock(HRegionInfo.class); when(info.getRegionName()).thenReturn(regionName.getBytes()); regionLocations.add(new HRegionLocation(info, sn)); } return mockedTable; }
/** * Makes some table with given region names. * */ private RegionLocator mockRegionLocator(String... regionNames) throws IOException { RegionLocator mockedTable = Mockito.mock(RegionLocator.class); when(mockedTable.getName()).thenReturn(TableName.valueOf("sizeTestTable")); List<HRegionLocation> regionLocations = new ArrayList<>(regionNames.length); when(mockedTable.getAllRegionLocations()).thenReturn(regionLocations); for (String regionName : regionNames) { HRegionInfo info = Mockito.mock(HRegionInfo.class); when(info.getRegionName()).thenReturn(regionName.getBytes()); regionLocations.add(new HRegionLocation(info, sn)); } return mockedTable; }
@Override public void perform() throws Exception { LOG.info("Performing action: Restart random RS holding table " + this.locator.getName()); List<HRegionLocation> locations = locator.getAllRegionLocations(); restartRs(locations.get(RandomUtils.nextInt(0, locations.size())).getServerName(), sleepTime); } }