Search in sources :

Example 1 with GCMultipleMergedRegionsProcedure

use of org.apache.hadoop.hbase.master.assignment.GCMultipleMergedRegionsProcedure in project hbase by apache.

the class TestMetaFixer method testOverlap.

@Test
public void testOverlap() throws Exception {
    TableName tn = TableName.valueOf(this.name.getMethodName());
    testOverlapCommon(tn);
    HMaster services = TEST_UTIL.getHBaseCluster().getMaster();
    HbckChore hbckChore = services.getHbckChore();
    CatalogJanitor cj = services.getCatalogJanitor();
    cj.scan();
    Report report = cj.getLastReport();
    assertEquals(6, report.getOverlaps().size());
    assertEquals(1, MetaFixer.calculateMerges(10, report.getOverlaps()).size());
    MetaFixer fixer = new MetaFixer(services);
    fixer.fixOverlaps(report);
    HBaseTestingUtil.await(10, () -> {
        try {
            if (cj.scan() > 0) {
                // It submits GC once, then it will immediately kick off another GC to test if
                // GCMultipleMergedRegionsProcedure is idempotent. If it is not, it will create
                // a hole.
                Map<RegionInfo, Result> mergedRegions = cj.getLastReport().mergedRegions;
                for (Map.Entry<RegionInfo, Result> e : mergedRegions.entrySet()) {
                    List<RegionInfo> parents = CatalogFamilyFormat.getMergeRegions(e.getValue().rawCells());
                    if (parents != null) {
                        ProcedureExecutor<MasterProcedureEnv> pe = services.getMasterProcedureExecutor();
                        pe.submitProcedure(new GCMultipleMergedRegionsProcedure(pe.getEnvironment(), e.getKey(), parents));
                    }
                }
                return true;
            }
            return false;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    });
    // Wait until all GCs settled down
    HBaseTestingUtil.await(10, () -> {
        return services.getMasterProcedureExecutor().getActiveProcIds().isEmpty();
    });
    // No orphan regions on FS
    hbckChore.choreForTesting();
    assertEquals(0, hbckChore.getOrphanRegionsOnFS().size());
    // No holes reported.
    cj.scan();
    final Report postReport = cj.getLastReport();
    assertTrue(postReport.isEmpty());
}
Also used : HbckChore(org.apache.hadoop.hbase.master.HbckChore) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) MasterProcedureEnv(org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv) IOException(java.io.IOException) Result(org.apache.hadoop.hbase.client.Result) TableName(org.apache.hadoop.hbase.TableName) GCMultipleMergedRegionsProcedure(org.apache.hadoop.hbase.master.assignment.GCMultipleMergedRegionsProcedure) HMaster(org.apache.hadoop.hbase.master.HMaster) Map(java.util.Map) Test(org.junit.Test)

Example 2 with GCMultipleMergedRegionsProcedure

use of org.apache.hadoop.hbase.master.assignment.GCMultipleMergedRegionsProcedure in project hbase by apache.

the class CatalogJanitor method cleanMergeRegion.

/**
 * If merged region no longer holds reference to the merge regions, archive merge region on hdfs
 * and perform deleting references in hbase:meta
 * @return true if we delete references in merged region on hbase:meta and archive the files on
 *         the file system
 */
private boolean cleanMergeRegion(final RegionInfo mergedRegion, List<RegionInfo> parents) throws IOException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Cleaning merged region {}", mergedRegion);
    }
    FileSystem fs = this.services.getMasterFileSystem().getFileSystem();
    Path rootdir = this.services.getMasterFileSystem().getRootDir();
    Path tabledir = CommonFSUtils.getTableDir(rootdir, mergedRegion.getTable());
    TableDescriptor htd = getDescriptor(mergedRegion.getTable());
    HRegionFileSystem regionFs = null;
    try {
        regionFs = HRegionFileSystem.openRegionFromFileSystem(this.services.getConfiguration(), fs, tabledir, mergedRegion, true);
    } catch (IOException e) {
        LOG.warn("Merged region does not exist: " + mergedRegion.getEncodedName());
    }
    if (regionFs == null || !regionFs.hasReferences(htd)) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Deleting parents ({}) from fs; merged child {} no longer holds references", parents.stream().map(r -> RegionInfo.getShortNameToLog(r)).collect(Collectors.joining(", ")), mergedRegion);
        }
        ProcedureExecutor<MasterProcedureEnv> pe = this.services.getMasterProcedureExecutor();
        GCMultipleMergedRegionsProcedure mergeRegionProcedure = new GCMultipleMergedRegionsProcedure(pe.getEnvironment(), mergedRegion, parents);
        pe.submitProcedure(mergeRegionProcedure);
        if (LOG.isDebugEnabled()) {
            LOG.debug("Submitted procedure {} for merged region {}", mergeRegionProcedure, mergedRegion);
        }
        return true;
    }
    return false;
}
Also used : Path(org.apache.hadoop.fs.Path) HRegionFileSystem(org.apache.hadoop.hbase.regionserver.HRegionFileSystem) FileSystem(org.apache.hadoop.fs.FileSystem) HRegionFileSystem(org.apache.hadoop.hbase.regionserver.HRegionFileSystem) GCMultipleMergedRegionsProcedure(org.apache.hadoop.hbase.master.assignment.GCMultipleMergedRegionsProcedure) MasterProcedureEnv(org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv) IOException(java.io.IOException) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor)

Aggregations

IOException (java.io.IOException)2 GCMultipleMergedRegionsProcedure (org.apache.hadoop.hbase.master.assignment.GCMultipleMergedRegionsProcedure)2 MasterProcedureEnv (org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv)2 Map (java.util.Map)1 FileSystem (org.apache.hadoop.fs.FileSystem)1 Path (org.apache.hadoop.fs.Path)1 TableName (org.apache.hadoop.hbase.TableName)1 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)1 Result (org.apache.hadoop.hbase.client.Result)1 TableDescriptor (org.apache.hadoop.hbase.client.TableDescriptor)1 HMaster (org.apache.hadoop.hbase.master.HMaster)1 HbckChore (org.apache.hadoop.hbase.master.HbckChore)1 HRegionFileSystem (org.apache.hadoop.hbase.regionserver.HRegionFileSystem)1 Test (org.junit.Test)1