public RegionSizeReportingChore(RegionServerServices rsServices) { super( RegionSizeReportingChore.class.getSimpleName(), rsServices, getPeriod(rsServices.getConfiguration()), getInitialDelay(rsServices.getConfiguration()), getTimeUnit(rsServices.getConfiguration())); this.rsServices = rsServices; this.metrics = rsServices.getMetrics(); }
void _chore() { final RegionServerSpaceQuotaManager quotaManager = rsServices.getRegionServerSpaceQuotaManager(); // Get the HRegionInfo for each online region HashSet<RegionInfo> onlineRegionInfos = getOnlineRegionInfos(rsServices.getRegions()); RegionSizeStore store = quotaManager.getRegionSizeStore(); // Remove all sizes for non-online regions removeNonOnlineRegions(store, onlineRegionInfos); rsServices.reportRegionSizesForQuotas(store); }
@Override protected void chore() { final long start = System.nanoTime(); try { _chore(); } finally { if (metrics != null) { metrics.incrementRegionSizeReportingChoreTime( TimeUnit.MILLISECONDS.convert(System.nanoTime() - start, TimeUnit.NANOSECONDS)); } } }
@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)); }
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; }
public synchronized void stop() { if (spaceQuotaRefresher != null) { spaceQuotaRefresher.cancel(); spaceQuotaRefresher = null; } if (regionSizeReporter != null) { regionSizeReporter.cancel(); regionSizeReporter = null; } started = false; }
@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()); }