Search in sources :

Example 56 with HMaster

use of org.apache.hadoop.hbase.master.HMaster in project hbase by apache.

the class TestRegionSizeUse method testBasicRegionSizeReports.

@Test
public void testBasicRegionSizeReports() throws Exception {
    // 5MB
    final long bytesWritten = 5L * 1024L * 1024L;
    final TableName tn = writeData(bytesWritten);
    LOG.debug("Data was written to HBase");
    final Admin admin = TEST_UTIL.getAdmin();
    // Push the data to disk.
    admin.flush(tn);
    LOG.debug("Data flushed to disk");
    // Get the final region distribution
    final List<RegionInfo> regions = TEST_UTIL.getAdmin().getRegions(tn);
    HMaster master = cluster.getMaster();
    MasterQuotaManager quotaManager = master.getMasterQuotaManager();
    Map<RegionInfo, Long> regionSizes = quotaManager.snapshotRegionSizes();
    // Wait until we get all of the region reports for our table
    // The table may split, so make sure we have at least as many as expected right after we
    // finished writing the data.
    int observedRegions = numRegionsForTable(tn, regionSizes);
    while (observedRegions < regions.size()) {
        LOG.debug("Expecting more regions. Saw " + observedRegions + " region sizes reported, expected at least " + regions.size());
        Thread.sleep(1000);
        regionSizes = quotaManager.snapshotRegionSizes();
        observedRegions = numRegionsForTable(tn, regionSizes);
    }
    LOG.debug("Observed region sizes by the HMaster: " + regionSizes);
    long totalRegionSize = 0L;
    for (Long regionSize : regionSizes.values()) {
        totalRegionSize += regionSize;
    }
    assertTrue("Expected region size report to exceed " + bytesWritten + ", but was " + totalRegionSize + ". RegionSizes=" + regionSizes, bytesWritten < totalRegionSize);
}
Also used : TableName(org.apache.hadoop.hbase.TableName) HMaster(org.apache.hadoop.hbase.master.HMaster) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) Admin(org.apache.hadoop.hbase.client.Admin) Test(org.junit.Test)

Example 57 with HMaster

use of org.apache.hadoop.hbase.master.HMaster in project hbase by apache.

the class TestQuotaObserverChoreRegionReports method testMissingReportsRemovesQuota.

@Test
public void testMissingReportsRemovesQuota() throws Exception {
    Configuration conf = TEST_UTIL.getConfiguration();
    // Expire the reports after 5 seconds
    conf.setInt(QuotaObserverChore.REGION_REPORT_RETENTION_DURATION_KEY, 5000);
    TEST_UTIL.startMiniCluster(1);
    // Wait till quota table onlined.
    TEST_UTIL.waitFor(10000, new Waiter.Predicate<Exception>() {

        @Override
        public boolean evaluate() throws Exception {
            return TEST_UTIL.getAdmin().tableExists(QuotaTableUtil.QUOTA_TABLE_NAME);
        }
    });
    final String FAM1 = "f1";
    // Create a table
    final TableName tn = TableName.valueOf("quotaAcceptanceWithoutReports");
    TableDescriptor tableDesc = TableDescriptorBuilder.newBuilder(tn).setColumnFamily(ColumnFamilyDescriptorBuilder.of(FAM1)).build();
    TEST_UTIL.getAdmin().createTable(tableDesc);
    // Set a quota
    final long sizeLimit = 1L * SpaceQuotaHelperForTests.ONE_KILOBYTE;
    final SpaceViolationPolicy violationPolicy = SpaceViolationPolicy.NO_INSERTS;
    QuotaSettings settings = QuotaSettingsFactory.limitTableSpace(tn, sizeLimit, violationPolicy);
    final Admin admin = TEST_UTIL.getAdmin();
    LOG.info("SET QUOTA");
    admin.setQuota(settings);
    final Connection conn = TEST_UTIL.getConnection();
    // Write enough data to invalidate the quota
    Put p = new Put(Bytes.toBytes("row1"));
    byte[] bytes = new byte[10];
    Arrays.fill(bytes, (byte) 2);
    for (int i = 0; i < 200; i++) {
        p.addColumn(Bytes.toBytes(FAM1), Bytes.toBytes("qual" + i), bytes);
    }
    conn.getTable(tn).put(p);
    admin.flush(tn);
    // Wait for the table to move into violation
    Waiter.waitFor(TEST_UTIL.getConfiguration(), 30000, 1000, new Waiter.Predicate<Exception>() {

        @Override
        public boolean evaluate() throws Exception {
            SpaceQuotaSnapshot snapshot = getSnapshotForTable(conn, tn);
            if (snapshot == null) {
                return false;
            }
            return snapshot.getQuotaStatus().isInViolation();
        }
    });
    // Close the region, prevent the server from sending new status reports.
    List<RegionInfo> regions = admin.getRegions(tn);
    assertEquals(1, regions.size());
    RegionInfo hri = regions.get(0);
    admin.unassign(hri.getRegionName(), true);
    // We should see this table move out of violation after the report expires.
    Waiter.waitFor(TEST_UTIL.getConfiguration(), 30000, 1000, new Waiter.Predicate<Exception>() {

        @Override
        public boolean evaluate() throws Exception {
            SpaceQuotaSnapshot snapshot = getSnapshotForTable(conn, tn);
            if (snapshot == null) {
                return false;
            }
            return !snapshot.getQuotaStatus().isInViolation();
        }
    });
    // The QuotaObserverChore's memory should also show it not in violation.
    final HMaster master = TEST_UTIL.getMiniHBaseCluster().getMaster();
    QuotaSnapshotStore<TableName> tableStore = master.getQuotaObserverChore().getTableSnapshotStore();
    SpaceQuotaSnapshot snapshot = tableStore.getCurrentState(tn);
    assertFalse("Quota should not be in violation", snapshot.getQuotaStatus().isInViolation());
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) Connection(org.apache.hadoop.hbase.client.Connection) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) Admin(org.apache.hadoop.hbase.client.Admin) IOException(java.io.IOException) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor) Put(org.apache.hadoop.hbase.client.Put) TableName(org.apache.hadoop.hbase.TableName) HMaster(org.apache.hadoop.hbase.master.HMaster) Waiter(org.apache.hadoop.hbase.Waiter) Test(org.junit.Test)

Example 58 with HMaster

use of org.apache.hadoop.hbase.master.HMaster in project hbase by apache.

the class TestSpaceQuotaBasicFunctioning method testDisablePolicyQuotaAndViolate.

@Test
public void testDisablePolicyQuotaAndViolate() throws Exception {
    TableName tableName = helper.createTable();
    helper.setQuotaLimit(tableName, SpaceViolationPolicy.DISABLE, 1L);
    helper.writeData(tableName, SpaceQuotaHelperForTests.ONE_MEGABYTE * 2L);
    TEST_UTIL.getConfiguration().setLong("hbase.master.quotas.region.report.retention.millis", 100);
    HMaster master = TEST_UTIL.getMiniHBaseCluster().getMaster();
    MasterQuotaManager quotaManager = master.getMasterQuotaManager();
    // Make sure the master has report for the table.
    Waiter.waitFor(TEST_UTIL.getConfiguration(), 30 * 1000, new Waiter.Predicate<Exception>() {

        @Override
        public boolean evaluate() throws Exception {
            Map<RegionInfo, Long> regionSizes = quotaManager.snapshotRegionSizes();
            List<RegionInfo> tableRegions = MetaTableAccessor.getTableRegions(TEST_UTIL.getConnection(), tableName);
            return regionSizes.containsKey(tableRegions.get(0));
        }
    });
    // Check if disabled table region report present in the map after retention period expired.
    // It should be present after retention period expired.
    final long regionSizes = quotaManager.snapshotRegionSizes().keySet().stream().filter(k -> k.getTable().equals(tableName)).count();
    Assert.assertTrue(regionSizes > 0);
}
Also used : Waiter(org.apache.hadoop.hbase.Waiter) BeforeClass(org.junit.BeforeClass) Increment(org.apache.hadoop.hbase.client.Increment) LoggerFactory(org.slf4j.LoggerFactory) Delete(org.apache.hadoop.hbase.client.Delete) StringUtils(org.apache.hadoop.util.StringUtils) TestName(org.junit.rules.TestName) Map(java.util.Map) Configuration(org.apache.hadoop.conf.Configuration) Assert.fail(org.junit.Assert.fail) ClassRule(org.junit.ClassRule) Bytes(org.apache.hadoop.hbase.util.Bytes) Before(org.junit.Before) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) Append(org.apache.hadoop.hbase.client.Append) TableName(org.apache.hadoop.hbase.TableName) AfterClass(org.junit.AfterClass) Logger(org.slf4j.Logger) HBaseTestingUtil(org.apache.hadoop.hbase.HBaseTestingUtil) Put(org.apache.hadoop.hbase.client.Put) Assert.assertTrue(org.junit.Assert.assertTrue) HBaseClassTestRule(org.apache.hadoop.hbase.HBaseClassTestRule) LargeTests(org.apache.hadoop.hbase.testclassification.LargeTests) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) AccessDeniedException(org.apache.hadoop.hbase.security.AccessDeniedException) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) Rule(org.junit.Rule) Admin(org.apache.hadoop.hbase.client.Admin) Assert.assertFalse(org.junit.Assert.assertFalse) Table(org.apache.hadoop.hbase.client.Table) MetaTableAccessor(org.apache.hadoop.hbase.MetaTableAccessor) Assert(org.junit.Assert) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) HMaster(org.apache.hadoop.hbase.master.HMaster) TableName(org.apache.hadoop.hbase.TableName) HMaster(org.apache.hadoop.hbase.master.HMaster) List(java.util.List) Waiter(org.apache.hadoop.hbase.Waiter) Map(java.util.Map) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) AccessDeniedException(org.apache.hadoop.hbase.security.AccessDeniedException) Test(org.junit.Test)

Example 59 with HMaster

use of org.apache.hadoop.hbase.master.HMaster in project hbase by apache.

the class TestMasterQuotasObserver method testObserverAddedByDefault.

@Test
public void testObserverAddedByDefault() throws Exception {
    final HMaster master = TEST_UTIL.getHBaseCluster().getMaster();
    final MasterCoprocessorHost cpHost = master.getMasterCoprocessorHost();
    Set<String> coprocessorNames = cpHost.getCoprocessors();
    assertTrue("Did not find MasterQuotasObserver in list of CPs: " + coprocessorNames, coprocessorNames.contains(MasterQuotasObserver.class.getSimpleName()));
}
Also used : MasterCoprocessorHost(org.apache.hadoop.hbase.master.MasterCoprocessorHost) HMaster(org.apache.hadoop.hbase.master.HMaster) Test(org.junit.Test)

Example 60 with HMaster

use of org.apache.hadoop.hbase.master.HMaster in project hbase by apache.

the class TestWALFiltering method testFlushedSequenceIdsSentToHMaster.

@Test
public void testFlushedSequenceIdsSentToHMaster() throws IOException, InterruptedException, org.apache.hbase.thirdparty.com.google.protobuf.ServiceException, ServiceException {
    SortedMap<byte[], Long> allFlushedSequenceIds = new TreeMap<>(Bytes.BYTES_COMPARATOR);
    for (int i = 0; i < NUM_RS; ++i) {
        flushAllRegions(i);
    }
    Thread.sleep(10000);
    HMaster master = TEST_UTIL.getMiniHBaseCluster().getMaster();
    for (int i = 0; i < NUM_RS; ++i) {
        for (byte[] regionName : getRegionsByServer(i)) {
            if (allFlushedSequenceIds.containsKey(regionName)) {
                GetLastFlushedSequenceIdRequest req = RequestConverter.buildGetLastFlushedSequenceIdRequest(regionName);
                assertEquals((long) allFlushedSequenceIds.get(regionName), master.getMasterRpcServices().getLastFlushedSequenceId(null, req).getLastFlushedSequenceId());
            }
        }
    }
}
Also used : HMaster(org.apache.hadoop.hbase.master.HMaster) GetLastFlushedSequenceIdRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.GetLastFlushedSequenceIdRequest) TreeMap(java.util.TreeMap) Test(org.junit.Test)

Aggregations

HMaster (org.apache.hadoop.hbase.master.HMaster)132 Test (org.junit.Test)91 TableName (org.apache.hadoop.hbase.TableName)42 IOException (java.io.IOException)33 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)31 ServerName (org.apache.hadoop.hbase.ServerName)24 Admin (org.apache.hadoop.hbase.client.Admin)23 Table (org.apache.hadoop.hbase.client.Table)23 SingleProcessHBaseCluster (org.apache.hadoop.hbase.SingleProcessHBaseCluster)22 TableDescriptor (org.apache.hadoop.hbase.client.TableDescriptor)16 HRegionServer (org.apache.hadoop.hbase.regionserver.HRegionServer)15 Configuration (org.apache.hadoop.conf.Configuration)13 MasterCoprocessorHost (org.apache.hadoop.hbase.master.MasterCoprocessorHost)12 BeforeClass (org.junit.BeforeClass)11 AssignmentManager (org.apache.hadoop.hbase.master.assignment.AssignmentManager)10 List (java.util.List)9 HBaseClassTestRule (org.apache.hadoop.hbase.HBaseClassTestRule)9 HRegionLocation (org.apache.hadoop.hbase.HRegionLocation)9 RegionStates (org.apache.hadoop.hbase.master.assignment.RegionStates)9 ClassRule (org.junit.ClassRule)9