-
Notifications
You must be signed in to change notification settings - Fork 151
HBASE-22567 - HBCK2 addMissingRegionsToMeta #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
88f96b3
HBASE-22567 - HBCK2 addMissingRegionsToMeta
wchevreuil 2e3fab7
HBASE-22567 - HBCK2 addMissingRegionsToMeta
wchevreuil 581e7ab
Addressing PR suggestions from ankitsinghal made on 2019-09-02
wchevreuil 25aa329
Addressing additional comments from ankitsinghal on PR #18
wchevreuil e15eb70
Addressing latest PR comments from 2019/09/04
wchevreuil a74cb9c
updated readme to reflect the method name changes, and also to mentio…
wchevreuil f85865d
Moving former MetaFixer class (now FsRegionsMetaRecoverer) from 'hbck…
wchevreuil d845fcf
replacing mentions to 'hbck2' to 'HBCK2'
wchevreuil 1bd877b
Addressing suggestion from ankitsinghal for replacing FileSystem.get(…
wchevreuil dd534e0
removed the attempt to disable/enable target table prior to regions r…
wchevreuil File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
129 changes: 129 additions & 0 deletions
129
hbase-hbck2/src/main/java/org/apache/hbase/FsRegionsMetaRecoverer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| /** | ||
| * 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.hbase; | ||
|
|
||
| import org.apache.hadoop.conf.Configuration; | ||
| import org.apache.hadoop.fs.FileSystem; | ||
| import org.apache.hadoop.fs.Path; | ||
| import org.apache.hadoop.hbase.HConstants; | ||
| import org.apache.hadoop.hbase.MetaTableAccessor; | ||
| import org.apache.hadoop.hbase.TableName; | ||
| import org.apache.hadoop.hbase.client.Connection; | ||
| import org.apache.hadoop.hbase.client.ConnectionFactory; | ||
| import org.apache.hadoop.hbase.client.RegionInfo; | ||
| import org.apache.hadoop.hbase.regionserver.HRegionFileSystem; | ||
| import org.apache.hadoop.hbase.util.CommonFSUtils; | ||
| import org.apache.hadoop.hbase.util.FSUtils; | ||
| import org.apache.logging.log4j.LogManager; | ||
| import org.apache.logging.log4j.Logger; | ||
|
|
||
| import java.io.Closeable; | ||
| import java.io.IOException; | ||
| import java.util.ArrayList; | ||
| import java.util.HashMap; | ||
| import java.util.HashSet; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Optional; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| /** | ||
| * This class implements the inner works required for check and recover regions that wrongly | ||
| * went missing in META. | ||
| * Normally HBCK2 fix options rely on Master self-contained information to recover/fix | ||
| * inconsistencies, but this an exception case where META table is in a broken state. | ||
| * So, it assumes HDFS state as the source of truth, in other words, methods provided here consider | ||
| * meta information found on HDFS region dirs as the valid ones. | ||
| */ | ||
| public class FsRegionsMetaRecoverer implements Closeable { | ||
| private static final Logger LOG = LogManager.getLogger(FsRegionsMetaRecoverer.class); | ||
| private final FileSystem fs; | ||
| private final Connection conn; | ||
| private final Configuration config; | ||
|
|
||
| public FsRegionsMetaRecoverer(Configuration configuration) throws IOException { | ||
| this.config = configuration; | ||
| this.fs = CommonFSUtils.getRootDirFileSystem(configuration); | ||
| this.conn = ConnectionFactory.createConnection(configuration); | ||
| } | ||
|
|
||
| /*Initially defined for test only purposes */ | ||
| FsRegionsMetaRecoverer(Configuration configuration, Connection connection, FileSystem fileSystem){ | ||
| this.config = configuration; | ||
| this.conn = connection; | ||
| this.fs = fileSystem; | ||
| } | ||
|
|
||
| private List<Path> getTableRegionsDirs(String table) throws Exception { | ||
| String hbaseRoot = this.config.get(HConstants.HBASE_DIR); | ||
| Path tableDir = FSUtils.getTableDir(new Path(hbaseRoot), TableName.valueOf(table)); | ||
| return FSUtils.getRegionDirs(fs, tableDir); | ||
| } | ||
|
|
||
| public Map<TableName,List<Path>> reportTablesMissingRegions(final List<String> namespacesOrTables) | ||
| throws IOException { | ||
| final Map<TableName,List<Path>> result = new HashMap<>(); | ||
| List<TableName> tableNames = MetaTableAccessor.getTableStates(this.conn).keySet().stream() | ||
| .filter(tableName -> { | ||
| if(namespacesOrTables==null || namespacesOrTables.isEmpty()){ | ||
| return true; | ||
| } else { | ||
| Optional<String> findings = namespacesOrTables.stream().filter( | ||
| name -> (name.indexOf(":") > 0) ? | ||
| tableName.equals(TableName.valueOf(name)) : | ||
| tableName.getNamespaceAsString().equals(name)).findFirst(); | ||
| return findings.isPresent(); | ||
| } | ||
| }).collect(Collectors.toList()); | ||
| tableNames.stream().forEach(tableName -> { | ||
| try { | ||
| result.put(tableName, | ||
| findMissingRegionsInMETA(tableName.getNameWithNamespaceInclAsString())); | ||
| } catch (Exception e) { | ||
| LOG.warn(e); | ||
| } | ||
| }); | ||
| return result; | ||
| } | ||
|
|
||
| List<Path> findMissingRegionsInMETA(String table) throws Exception { | ||
| final List<Path> missingRegions = new ArrayList<>(); | ||
| final List<Path> regionsDirs = getTableRegionsDirs(table); | ||
| TableName tableName = TableName.valueOf(table); | ||
| List<RegionInfo> regionInfos = MetaTableAccessor. | ||
| getTableRegions(this.conn, tableName, false); | ||
| HashSet<String> regionsInMeta = regionInfos.stream().map(info -> | ||
| info.getEncodedName()).collect(Collectors.toCollection(HashSet::new)); | ||
| for(final Path regionDir : regionsDirs){ | ||
| if (!regionsInMeta.contains(regionDir.getName())) { | ||
| LOG.debug(regionDir + "is not in META."); | ||
| missingRegions.add(regionDir); | ||
| } | ||
| } | ||
| return missingRegions; | ||
| } | ||
|
|
||
| public void putRegionInfoFromHdfsInMeta(Path region) throws IOException { | ||
| RegionInfo info = HRegionFileSystem.loadRegionInfoFileContent(fs, region); | ||
| MetaTableAccessor.addRegionToMeta(conn, info); | ||
| } | ||
|
|
||
| @Override public void close() throws IOException { | ||
| this.conn.close(); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.