Skip to content

Commit e191fe9

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 c24ba54 commit e191fe9

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
@@ -132,6 +132,7 @@
132132
import org.apache.hadoop.hbase.master.cleaner.LogCleaner;
133133
import org.apache.hadoop.hbase.master.cleaner.ReplicationBarrierCleaner;
134134
import org.apache.hadoop.hbase.master.cleaner.SnapshotCleanerChore;
135+
import org.apache.hadoop.hbase.master.hbck.HbckChore;
135136
import org.apache.hadoop.hbase.master.http.MasterDumpServlet;
136137
import org.apache.hadoop.hbase.master.http.MasterRedirectServlet;
137138
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
@@ -67,6 +67,7 @@
6767
import org.apache.hadoop.hbase.master.assignment.RegionStateNode;
6868
import org.apache.hadoop.hbase.master.assignment.RegionStates;
6969
import org.apache.hadoop.hbase.master.cleaner.HFileCleaner;
70+
import org.apache.hadoop.hbase.master.hbck.HbckChore;
7071
import org.apache.hadoop.hbase.master.janitor.MetaFixer;
7172
import org.apache.hadoop.hbase.master.locking.LockProcedure;
7273
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
@@ -86,7 +86,7 @@ public class CatalogJanitor extends ScheduledChore {
8686
* Saved report from last hbase:meta scan to completion. May be stale if having trouble completing
8787
* scan. Check its date.
8888
*/
89-
private volatile Report lastReport;
89+
private volatile CatalogJanitorReport lastReport;
9090

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

229229
/**
230230
* Scan hbase:meta.
231-
* @return Return generated {@link Report}
231+
* @return Return generated {@link CatalogJanitorReport}
232232
*/
233233
// will be override in tests.
234-
protected Report scanForReport() throws IOException {
234+
protected CatalogJanitorReport scanForReport() throws IOException {
235235
ReportMakingVisitor visitor = new ReportMakingVisitor(this.services);
236236
// Null tablename means scan all of meta.
237237
MetaTableAccessor.scanMetaForTableRegions(this.services.getConnection(), visitor, null);
@@ -241,7 +241,7 @@ protected Report scanForReport() throws IOException {
241241
/**
242242
* @return Returns last published Report that comes of last successful scan of hbase:meta.
243243
*/
244-
public Report getLastReport() {
244+
public CatalogJanitorReport getLastReport() {
245245
return this.lastReport;
246246
}
247247

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

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
@@ -73,7 +73,7 @@ public MetaFixer(MasterServices masterServices) {
7373
}
7474

7575
public void fix() throws IOException {
76-
Report report = this.masterServices.getCatalogJanitor().getLastReport();
76+
CatalogJanitorReport report = this.masterServices.getCatalogJanitor().getLastReport();
7777
if (report == null) {
7878
LOG.info("CatalogJanitor has not generated a report yet; run 'catalogjanitor_run' in "
7979
+ "shell or wait until CatalogJanitor chore runs.");
@@ -90,7 +90,7 @@ public void fix() throws IOException {
9090
* If hole, it papers it over by adding a region in the filesystem and to hbase:meta. Does not
9191
* assign.
9292
*/
93-
void fixHoles(Report report) {
93+
void fixHoles(CatalogJanitorReport report) {
9494
final List<Pair<RegionInfo, RegionInfo>> holes = report.getHoles();
9595
if (holes.isEmpty()) {
9696
LOG.info("CatalogJanitor Report contains no holes to fix. Skipping.");
@@ -220,7 +220,7 @@ private static List<RegionInfo> createMetaEntries(final MasterServices masterSer
220220
/**
221221
* Fix overlaps noted in CJ consistency report.
222222
*/
223-
List<Long> fixOverlaps(Report report) throws IOException {
223+
List<Long> fixOverlaps(CatalogJanitorReport report) throws IOException {
224224
List<Long> pidList = new ArrayList<>();
225225
for (Set<RegionInfo> regions : calculateMerges(maxMergeCount, report.getOverlaps())) {
226226
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
@@ -54,7 +54,7 @@ class ReportMakingVisitor implements ClientMetaTableAccessor.CloseableVisitor {
5454
/**
5555
* Report is not done until after the close has been called.
5656
*/
57-
private Report report = new Report();
57+
private CatalogJanitorReport report = new CatalogJanitorReport();
5858

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

0 commit comments

Comments
 (0)