Skip to content

Commit

Permalink
HBASE-27095 HbckChore should produce a report
Browse files Browse the repository at this point in the history
In #4470 for HBASE-26192, it was noted that the HbckChore is kind of a pain to use and test
because it maintains a bunch of local state. By contract, the CatalogJanitorChore makes a nice
self-contained report. Let's update HbckChore to do the same.

Signed-off-by: Andrew Purtell <[email protected]>
  • Loading branch information
ndimiduk authored Jun 10, 2022
1 parent 3d82d2d commit a3153bf
Show file tree
Hide file tree
Showing 15 changed files with 304 additions and 279 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
import org.apache.hadoop.hbase.master.cleaner.LogCleaner;
import org.apache.hadoop.hbase.master.cleaner.ReplicationBarrierCleaner;
import org.apache.hadoop.hbase.master.cleaner.SnapshotCleanerChore;
import org.apache.hadoop.hbase.master.hbck.HbckChore;
import org.apache.hadoop.hbase.master.janitor.CatalogJanitor;
import org.apache.hadoop.hbase.master.locking.LockManager;
import org.apache.hadoop.hbase.master.normalizer.RegionNormalizerFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
import org.apache.hadoop.hbase.ipc.ServerNotRunningYetException;
import org.apache.hadoop.hbase.ipc.ServerRpcController;
import org.apache.hadoop.hbase.master.assignment.RegionStates;
import org.apache.hadoop.hbase.master.hbck.HbckChore;
import org.apache.hadoop.hbase.master.janitor.MetaFixer;
import org.apache.hadoop.hbase.master.locking.LockProcedure;
import org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv;
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.hadoop.hbase.master.hbck;

import java.time.Instant;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.ServerName;
import org.apache.hadoop.hbase.util.HbckRegionInfo;
import org.apache.hadoop.hbase.util.Pair;
import org.apache.yetus.audience.InterfaceAudience;

/**
* The result of an {@link HbckChore} execution.
*/
@InterfaceAudience.Private
public class HbckReport {

private final Map<String, HbckRegionInfo> regionInfoMap = new HashMap<>();
private final Set<String> disabledTableRegions = new HashSet<>();
private final Set<String> splitParentRegions = new HashSet<>();
private final Map<String, ServerName> orphanRegionsOnRS = new HashMap<>();
private final Map<String, Path> orphanRegionsOnFS = new HashMap<>();
private final Map<String, Pair<ServerName, List<ServerName>>> inconsistentRegions =
new HashMap<>();

private Instant checkingStartTimestamp = null;
private Instant checkingEndTimestamp = null;

/**
* Used for web ui to show when the HBCK checking started.
*/
public Instant getCheckingStartTimestamp() {
return checkingStartTimestamp;
}

public void setCheckingStartTimestamp(Instant checkingStartTimestamp) {
this.checkingStartTimestamp = checkingStartTimestamp;
}

/**
* Used for web ui to show when the HBCK checking report generated.
*/
public Instant getCheckingEndTimestamp() {
return checkingEndTimestamp;
}

public void setCheckingEndTimestamp(Instant checkingEndTimestamp) {
this.checkingEndTimestamp = checkingEndTimestamp;
}

/**
* This map contains the state of all hbck items. It maps from encoded region name to
* HbckRegionInfo structure. The information contained in HbckRegionInfo is used to detect and
* correct consistency (hdfs/meta/deployment) problems.
*/
public Map<String, HbckRegionInfo> getRegionInfoMap() {
return regionInfoMap;
}

public Set<String> getDisabledTableRegions() {
return disabledTableRegions;
}

public Set<String> getSplitParentRegions() {
return splitParentRegions;
}

/**
* The regions only opened on RegionServers, but no region info in meta.
*/
public Map<String, ServerName> getOrphanRegionsOnRS() {
return orphanRegionsOnRS;
}

/**
* The regions have directory on FileSystem, but no region info in meta.
*/
public Map<String, Path> getOrphanRegionsOnFS() {
return orphanRegionsOnFS;
}

/**
* The inconsistent regions. There are three case: case 1. Master thought this region opened, but
* no regionserver reported it. case 2. Master thought this region opened on Server1, but
* regionserver reported Server2 case 3. More than one regionservers reported opened this region
*/
public Map<String, Pair<ServerName, List<ServerName>>> getInconsistentRegions() {
return inconsistentRegions;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public class CatalogJanitor extends ScheduledChore {
* Saved report from last hbase:meta scan to completion. May be stale if having trouble completing
* scan. Check its date.
*/
private volatile Report lastReport;
private volatile CatalogJanitorReport lastReport;

public CatalogJanitor(final MasterServices services) {
super("CatalogJanitor-" + services.getServerName().toShortString(), services,
Expand Down Expand Up @@ -229,10 +229,10 @@ && cleanParent(e.getKey(), e.getValue())

/**
* Scan hbase:meta.
* @return Return generated {@link Report}
* @return Return generated {@link CatalogJanitorReport}
*/
// will be override in tests.
protected Report scanForReport() throws IOException {
protected CatalogJanitorReport scanForReport() throws IOException {
ReportMakingVisitor visitor = new ReportMakingVisitor(this.services);
// Null tablename means scan all of meta.
MetaTableAccessor.scanMetaForTableRegions(this.services.getConnection(), visitor, null);
Expand All @@ -242,7 +242,7 @@ protected Report scanForReport() throws IOException {
/**
* @return Returns last published Report that comes of last successful scan of hbase:meta.
*/
public Report getLastReport() {
public CatalogJanitorReport getLastReport() {
return this.lastReport;
}

Expand Down Expand Up @@ -495,7 +495,7 @@ public static void main(String[] args) throws IOException {
t.put(p);
}
MetaTableAccessor.scanMetaForTableRegions(connection, visitor, null);
Report report = visitor.getReport();
CatalogJanitorReport report = visitor.getReport();
LOG.info(report != null ? report.toString() : "empty");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
* Report made by ReportMakingVisitor
*/
@InterfaceAudience.Private
public class Report {
public class CatalogJanitorReport {
private final long now = EnvironmentEdgeManager.currentTime();

// Keep Map of found split parents. These are candidates for cleanup.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public MetaFixer(MasterServices masterServices) {
}

public void fix() throws IOException {
Report report = this.masterServices.getCatalogJanitor().getLastReport();
CatalogJanitorReport report = this.masterServices.getCatalogJanitor().getLastReport();
if (report == null) {
LOG.info("CatalogJanitor has not generated a report yet; run 'catalogjanitor_run' in "
+ "shell or wait until CatalogJanitor chore runs.");
Expand All @@ -93,7 +93,7 @@ public void fix() throws IOException {
* If hole, it papers it over by adding a region in the filesystem and to hbase:meta. Does not
* assign.
*/
void fixHoles(Report report) {
void fixHoles(CatalogJanitorReport report) {
final List<Pair<RegionInfo, RegionInfo>> holes = report.getHoles();
if (holes.isEmpty()) {
LOG.info("CatalogJanitor Report contains no holes to fix. Skipping.");
Expand Down Expand Up @@ -229,7 +229,7 @@ private static List<RegionInfo> createMetaEntries(final MasterServices masterSer
/**
* Fix overlaps noted in CJ consistency report.
*/
List<Long> fixOverlaps(Report report) throws IOException {
List<Long> fixOverlaps(CatalogJanitorReport report) throws IOException {
List<Long> pidList = new ArrayList<>();
for (Set<RegionInfo> regions : calculateMerges(maxMergeCount, report.getOverlaps())) {
RegionInfo[] regionsArray = regions.toArray(new RegionInfo[] {});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class ReportMakingVisitor implements MetaTableAccessor.CloseableVisitor {
/**
* Report is not done until after the close has been called.
*/
private Report report = new Report();
private CatalogJanitorReport report = new CatalogJanitorReport();

/**
* RegionInfo from previous row.
Expand All @@ -76,7 +76,7 @@ class ReportMakingVisitor implements MetaTableAccessor.CloseableVisitor {
/**
* Do not call until after {@link #close()}. Will throw a {@link RuntimeException} if you do.
*/
Report getReport() {
CatalogJanitorReport getReport() {
if (!this.closed) {
throw new RuntimeException("Report not ready until after close()");
}
Expand Down
Loading

0 comments on commit a3153bf

Please sign in to comment.