Skip to content

Commit 1dcee76

Browse files
authored
HBASE-27095 HbckChore should produce a report
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 <apurtell@apache.org>
1 parent 27f9182 commit 1dcee76

File tree

15 files changed

+304
-279
lines changed

15 files changed

+304
-279
lines changed

hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@
131131
import org.apache.hadoop.hbase.master.cleaner.LogCleaner;
132132
import org.apache.hadoop.hbase.master.cleaner.ReplicationBarrierCleaner;
133133
import org.apache.hadoop.hbase.master.cleaner.SnapshotCleanerChore;
134+
import org.apache.hadoop.hbase.master.hbck.HbckChore;
134135
import org.apache.hadoop.hbase.master.http.MasterDumpServlet;
135136
import org.apache.hadoop.hbase.master.http.MasterRedirectServlet;
136137
import org.apache.hadoop.hbase.master.http.MasterStatusServlet;

hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterRpcServices.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
import org.apache.hadoop.hbase.master.assignment.RegionStateNode;
7777
import org.apache.hadoop.hbase.master.assignment.RegionStates;
7878
import org.apache.hadoop.hbase.master.cleaner.HFileCleaner;
79+
import org.apache.hadoop.hbase.master.hbck.HbckChore;
7980
import org.apache.hadoop.hbase.master.janitor.MetaFixer;
8081
import org.apache.hadoop.hbase.master.locking.LockProcedure;
8182
import org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv;

hbase-server/src/main/java/org/apache/hadoop/hbase/master/HbckChore.java renamed to hbase-server/src/main/java/org/apache/hadoop/hbase/master/hbck/HbckChore.java

Lines changed: 56 additions & 157 deletions
Large diffs are not rendered by default.
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.hadoop.hbase.master.hbck;
19+
20+
import java.time.Instant;
21+
import java.util.HashMap;
22+
import java.util.HashSet;
23+
import java.util.List;
24+
import java.util.Map;
25+
import java.util.Set;
26+
import org.apache.hadoop.fs.Path;
27+
import org.apache.hadoop.hbase.ServerName;
28+
import org.apache.hadoop.hbase.util.HbckRegionInfo;
29+
import org.apache.hadoop.hbase.util.Pair;
30+
import org.apache.yetus.audience.InterfaceAudience;
31+
32+
/**
33+
* The result of an {@link HbckChore} execution.
34+
*/
35+
@InterfaceAudience.Private
36+
public class HbckReport {
37+
38+
private final Map<String, HbckRegionInfo> regionInfoMap = new HashMap<>();
39+
private final Set<String> disabledTableRegions = new HashSet<>();
40+
private final Set<String> splitParentRegions = new HashSet<>();
41+
private final Map<String, ServerName> orphanRegionsOnRS = new HashMap<>();
42+
private final Map<String, Path> orphanRegionsOnFS = new HashMap<>();
43+
private final Map<String, Pair<ServerName, List<ServerName>>> inconsistentRegions =
44+
new HashMap<>();
45+
46+
private Instant checkingStartTimestamp = null;
47+
private Instant checkingEndTimestamp = null;
48+
49+
/**
50+
* Used for web ui to show when the HBCK checking started.
51+
*/
52+
public Instant getCheckingStartTimestamp() {
53+
return checkingStartTimestamp;
54+
}
55+
56+
public void setCheckingStartTimestamp(Instant checkingStartTimestamp) {
57+
this.checkingStartTimestamp = checkingStartTimestamp;
58+
}
59+
60+
/**
61+
* Used for web ui to show when the HBCK checking report generated.
62+
*/
63+
public Instant getCheckingEndTimestamp() {
64+
return checkingEndTimestamp;
65+
}
66+
67+
public void setCheckingEndTimestamp(Instant checkingEndTimestamp) {
68+
this.checkingEndTimestamp = checkingEndTimestamp;
69+
}
70+
71+
/**
72+
* This map contains the state of all hbck items. It maps from encoded region name to
73+
* HbckRegionInfo structure. The information contained in HbckRegionInfo is used to detect and
74+
* correct consistency (hdfs/meta/deployment) problems.
75+
*/
76+
public Map<String, HbckRegionInfo> getRegionInfoMap() {
77+
return regionInfoMap;
78+
}
79+
80+
public Set<String> getDisabledTableRegions() {
81+
return disabledTableRegions;
82+
}
83+
84+
public Set<String> getSplitParentRegions() {
85+
return splitParentRegions;
86+
}
87+
88+
/**
89+
* The regions only opened on RegionServers, but no region info in meta.
90+
*/
91+
public Map<String, ServerName> getOrphanRegionsOnRS() {
92+
return orphanRegionsOnRS;
93+
}
94+
95+
/**
96+
* The regions have directory on FileSystem, but no region info in meta.
97+
*/
98+
public Map<String, Path> getOrphanRegionsOnFS() {
99+
return orphanRegionsOnFS;
100+
}
101+
102+
/**
103+
* The inconsistent regions. There are three case: case 1. Master thought this region opened, but
104+
* no regionserver reported it. case 2. Master thought this region opened on Server1, but
105+
* regionserver reported Server2 case 3. More than one regionservers reported opened this region
106+
*/
107+
public Map<String, Pair<ServerName, List<ServerName>>> getInconsistentRegions() {
108+
return inconsistentRegions;
109+
}
110+
}

hbase-server/src/main/java/org/apache/hadoop/hbase/master/janitor/CatalogJanitor.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public class CatalogJanitor extends ScheduledChore {
8585
* Saved report from last hbase:meta scan to completion. May be stale if having trouble completing
8686
* scan. Check its date.
8787
*/
88-
private volatile Report lastReport;
88+
private volatile CatalogJanitorReport lastReport;
8989

9090
public CatalogJanitor(final MasterServices services) {
9191
super("CatalogJanitor-" + services.getServerName().toShortString(), services,
@@ -227,10 +227,10 @@ && cleanParent(e.getKey(), e.getValue())
227227

228228
/**
229229
* Scan hbase:meta.
230-
* @return Return generated {@link Report}
230+
* @return Return generated {@link CatalogJanitorReport}
231231
*/
232232
// will be override in tests.
233-
protected Report scanForReport() throws IOException {
233+
protected CatalogJanitorReport scanForReport() throws IOException {
234234
ReportMakingVisitor visitor = new ReportMakingVisitor(this.services);
235235
// Null tablename means scan all of meta.
236236
MetaTableAccessor.scanMetaForTableRegions(this.services.getConnection(), visitor, null);
@@ -240,7 +240,7 @@ protected Report scanForReport() throws IOException {
240240
/**
241241
* @return Returns last published Report that comes of last successful scan of hbase:meta.
242242
*/
243-
public Report getLastReport() {
243+
public CatalogJanitorReport getLastReport() {
244244
return this.lastReport;
245245
}
246246

@@ -493,7 +493,7 @@ public static void main(String[] args) throws IOException {
493493
t.put(p);
494494
}
495495
MetaTableAccessor.scanMetaForTableRegions(connection, visitor, null);
496-
Report report = visitor.getReport();
496+
CatalogJanitorReport report = visitor.getReport();
497497
LOG.info(report != null ? report.toString() : "empty");
498498
}
499499
}

hbase-server/src/main/java/org/apache/hadoop/hbase/master/janitor/Report.java renamed to hbase-server/src/main/java/org/apache/hadoop/hbase/master/janitor/CatalogJanitorReport.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
* Report made by ReportMakingVisitor
3535
*/
3636
@InterfaceAudience.Private
37-
public class Report {
37+
public class CatalogJanitorReport {
3838
private final long now = EnvironmentEdgeManager.currentTime();
3939

4040
// Keep Map of found split parents. These are candidates for cleanup.

hbase-server/src/main/java/org/apache/hadoop/hbase/master/janitor/MetaFixer.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public MetaFixer(MasterServices masterServices) {
7676
}
7777

7878
public void fix() throws IOException {
79-
Report report = this.masterServices.getCatalogJanitor().getLastReport();
79+
CatalogJanitorReport report = this.masterServices.getCatalogJanitor().getLastReport();
8080
if (report == null) {
8181
LOG.info("CatalogJanitor has not generated a report yet; run 'catalogjanitor_run' in "
8282
+ "shell or wait until CatalogJanitor chore runs.");
@@ -93,7 +93,7 @@ public void fix() throws IOException {
9393
* If hole, it papers it over by adding a region in the filesystem and to hbase:meta. Does not
9494
* assign.
9595
*/
96-
void fixHoles(Report report) {
96+
void fixHoles(CatalogJanitorReport report) {
9797
final List<Pair<RegionInfo, RegionInfo>> holes = report.getHoles();
9898
if (holes.isEmpty()) {
9999
LOG.info("CatalogJanitor Report contains no holes to fix. Skipping.");
@@ -229,7 +229,7 @@ private static List<RegionInfo> createMetaEntries(final MasterServices masterSer
229229
/**
230230
* Fix overlaps noted in CJ consistency report.
231231
*/
232-
List<Long> fixOverlaps(Report report) throws IOException {
232+
List<Long> fixOverlaps(CatalogJanitorReport report) throws IOException {
233233
List<Long> pidList = new ArrayList<>();
234234
for (Set<RegionInfo> regions : calculateMerges(maxMergeCount, report.getOverlaps())) {
235235
RegionInfo[] regionsArray = regions.toArray(new RegionInfo[] {});

hbase-server/src/main/java/org/apache/hadoop/hbase/master/janitor/ReportMakingVisitor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class ReportMakingVisitor implements MetaTableAccessor.CloseableVisitor {
5353
/**
5454
* Report is not done until after the close has been called.
5555
*/
56-
private Report report = new Report();
56+
private CatalogJanitorReport report = new CatalogJanitorReport();
5757

5858
/**
5959
* RegionInfo from previous row.
@@ -76,7 +76,7 @@ class ReportMakingVisitor implements MetaTableAccessor.CloseableVisitor {
7676
/**
7777
* Do not call until after {@link #close()}. Will throw a {@link RuntimeException} if you do.
7878
*/
79-
Report getReport() {
79+
CatalogJanitorReport getReport() {
8080
if (!this.closed) {
8181
throw new RuntimeException("Report not ready until after close()");
8282
}

0 commit comments

Comments
 (0)