public synchronized void start() throws IOException { if (!QuotaUtil.isQuotaEnabled(rsServices.getConfiguration())) { LOG.info("Quota support disabled, not starting space quota manager."); return; } if (started) { LOG.warn("RegionServerSpaceQuotaManager has already been started!"); return; } // Start the chores this.spaceQuotaRefresher = new SpaceQuotaRefresherChore(this, rsServices.getClusterConnection()); rsServices.getChoreService().scheduleChore(spaceQuotaRefresher); this.regionSizeReporter = new RegionSizeReportingChore(rsServices); rsServices.getChoreService().scheduleChore(regionSizeReporter); // Instantiate the real RegionSizeStore this.regionSizeStore = RegionSizeStoreFactory.getInstance().createStore(); started = true; }
@Test public void testNonDefaultConfigurationProperties() { final Configuration conf = getDefaultHBaseConfiguration(); final HRegionServer rs = mockRegionServer(conf); final int period = RegionSizeReportingChore.REGION_SIZE_REPORTING_CHORE_PERIOD_DEFAULT + 1; final long delay = RegionSizeReportingChore.REGION_SIZE_REPORTING_CHORE_DELAY_DEFAULT + 1L; final String timeUnit = TimeUnit.SECONDS.name(); conf.setInt(RegionSizeReportingChore.REGION_SIZE_REPORTING_CHORE_PERIOD_KEY, period); conf.setLong(RegionSizeReportingChore.REGION_SIZE_REPORTING_CHORE_DELAY_KEY, delay); conf.set(RegionSizeReportingChore.REGION_SIZE_REPORTING_CHORE_TIMEUNIT_KEY, timeUnit); RegionSizeReportingChore chore = new RegionSizeReportingChore(rs); assertEquals(delay, chore.getInitialDelay()); assertEquals(period, chore.getPeriod()); assertEquals(TimeUnit.valueOf(timeUnit), chore.getTimeUnit()); }
@Test public void testDefaultConfigurationProperties() { final Configuration conf = getDefaultHBaseConfiguration(); final HRegionServer rs = mockRegionServer(conf); RegionSizeReportingChore chore = new RegionSizeReportingChore(rs); assertEquals( RegionSizeReportingChore.REGION_SIZE_REPORTING_CHORE_DELAY_DEFAULT, chore.getInitialDelay()); assertEquals( RegionSizeReportingChore.REGION_SIZE_REPORTING_CHORE_PERIOD_DEFAULT, chore.getPeriod()); assertEquals( TimeUnit.valueOf(RegionSizeReportingChore.REGION_SIZE_REPORTING_CHORE_TIMEUNIT_DEFAULT), chore.getTimeUnit()); }
@Test public void testRemovableOfNonOnlineRegions() { final Configuration conf = getDefaultHBaseConfiguration(); final HRegionServer rs = mockRegionServer(conf); RegionSizeReportingChore chore = new RegionSizeReportingChore(rs); RegionInfo infoA = RegionInfoBuilder.newBuilder(TableName.valueOf("T1")) .setStartKey(Bytes.toBytes("a")).setEndKey(Bytes.toBytes("b")).build(); RegionInfo infoB = RegionInfoBuilder.newBuilder(TableName.valueOf("T1")) .setStartKey(Bytes.toBytes("b")).setEndKey(Bytes.toBytes("d")).build(); RegionInfo infoC = RegionInfoBuilder.newBuilder(TableName.valueOf("T1")) .setStartKey(Bytes.toBytes("c")).setEndKey(Bytes.toBytes("d")).build(); RegionSizeStore store = new RegionSizeStoreImpl(); store.put(infoA, 1024L); store.put(infoB, 1024L); store.put(infoC, 1024L); // If there are no online regions, all entries should be removed. chore.removeNonOnlineRegions(store, Collections.<RegionInfo> emptySet()); assertTrue(store.isEmpty()); store.put(infoA, 1024L); store.put(infoB, 1024L); store.put(infoC, 1024L); // Remove a single region chore.removeNonOnlineRegions(store, new HashSet<>(Arrays.asList(infoA, infoC))); assertEquals(2, store.size()); assertNotNull(store.getRegionSize(infoA)); assertNotNull(store.getRegionSize(infoC)); }