-
Notifications
You must be signed in to change notification settings - Fork 151
HBASE-25874 [hbase-operator-tools]Add tool for identifying 'unknown s… #86
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7086031
HBASE-25874 [hbase-operator-tools]Add tool for identifying 'unknown s…
wchevreuil 0f0b6ef
addressing review comments
wchevreuil 58271d7
checkstyle
wchevreuil 09f0a92
more reviews
wchevreuil 1f1c4db
more reviews
wchevreuil a18968d
fixing dryRun
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
119 changes: 119 additions & 0 deletions
119
hbase-tools/src/main/java/org/apache/hbase/RegionsOnUnknownServersRecoverer.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,119 @@ | ||
| /* | ||
| * 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 java.io.BufferedReader; | ||
| import java.io.File; | ||
| import java.io.FileReader; | ||
| import java.util.HashSet; | ||
| import java.util.Set; | ||
|
|
||
| import org.apache.hadoop.conf.Configuration; | ||
| import org.apache.hadoop.conf.Configured; | ||
| import org.apache.hadoop.hbase.HBaseConfiguration; | ||
| import org.apache.hadoop.hbase.client.Connection; | ||
| import org.apache.hadoop.hbase.client.ConnectionFactory; | ||
| import org.apache.hadoop.util.Tool; | ||
| import org.apache.hadoop.util.ToolRunner; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
|
|
||
| /** | ||
| * Tool for identifying Unknown Servers from master logs and schedule SCPs for each of those using | ||
| * HBCK2 'scheduleRecoveries' option. This is useful for clusters running hbase versions lower than | ||
| * 2.2.7, 2.3.5 and 2.4.7. For any of these versions or higher, use HBCK2 'recoverUnknown' option. | ||
| */ | ||
| public class RegionsOnUnknownServersRecoverer extends Configured implements Tool { | ||
|
|
||
| private static final Logger LOG = | ||
| LoggerFactory.getLogger(RegionsOnUnknownServersRecoverer.class.getName()); | ||
|
|
||
| private static final String CATALOG_JANITOR = "CatalogJanitor: hole="; | ||
|
|
||
| private static final String UNKNOWN_SERVER = "unknown_server="; | ||
|
|
||
| private Configuration conf; | ||
|
|
||
| private Set<String> unknownServers = new HashSet<>(); | ||
|
|
||
| private boolean dryRun = false; | ||
|
|
||
| public RegionsOnUnknownServersRecoverer(Configuration conf){ | ||
| this.conf = conf; | ||
| } | ||
|
|
||
| @Override | ||
| public int run(String[] args) throws Exception { | ||
| String logPath = null; | ||
| if(args.length>=1 && args.length<3) { | ||
| logPath = args[0]; | ||
| if(args.length==2) { | ||
| dryRun = args[1].equals("dryRun"); | ||
| } | ||
| } else { | ||
| LOG.error("Wrong number of arguments. " | ||
| + "Arguments are: <PATH_TO_MASTER_LOGS> [dryRun]"); | ||
| return 1; | ||
| } | ||
| BufferedReader reader = null; | ||
| try(Connection conn = ConnectionFactory.createConnection(conf)) { | ||
| reader = new BufferedReader(new FileReader(new File(logPath))); | ||
| String line = null; | ||
| while((line = reader.readLine()) != null){ | ||
| if(line.contains(CATALOG_JANITOR)){ | ||
| String[] servers = line.split(UNKNOWN_SERVER); | ||
| for(int i=1; i<servers.length; i++){ | ||
| String server = servers[i].split("/")[0]; | ||
| if(!unknownServers.contains(server)){ | ||
| LOG.info("Adding server {} to our list of servers that will have SCPs.", server); | ||
| unknownServers.add(server); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| if(dryRun){ | ||
| StringBuilder builder = | ||
| new StringBuilder("This is a dry run, no SCPs will be submitted. Found unknown servers:"); | ||
| builder.append("\n"); | ||
| unknownServers.stream().forEach(s -> builder.append(s).append("\n")); | ||
| LOG.info(builder.toString()); | ||
| } else { | ||
| HBCK2 hbck2 = new HBCK2(conf); | ||
| LOG.info("Submitting SCPs for the found unknown servers with " | ||
| + "HBCK2 scheduleRecoveries option."); | ||
| hbck2.scheduleRecoveries(conn.getHbck(), unknownServers.toArray(new String[] {})); | ||
| } | ||
| } catch(Exception e){ | ||
| LOG.error("Recovering unknown servers failed:", e); | ||
| return 2; | ||
| } finally { | ||
| reader.close(); | ||
| } | ||
| return 0; | ||
| } | ||
|
|
||
| public static void main(String [] args) throws Exception { | ||
| Configuration conf = HBaseConfiguration.create(); | ||
| int errCode = ToolRunner.run(new RegionsOnUnknownServersRecoverer(conf), args); | ||
| if (errCode != 0) { | ||
| System.exit(errCode); | ||
| } | ||
| } | ||
| } | ||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the usage message it is not obvious that the
[dryRun]parameter should betrue.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just wanted to mention the available options here. I guess we can explain the
dryRunoption in the README only?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having it in the readme is enough but in my opinion, it is still not clear what an operator should use as the second parameter.
hbase org.apache.hbase.RegionsOnUnknownServersRecoverer /var/log/hbase.log true
hbase org.apache.hbase.RegionsOnUnknownServersRecoverer /var/log/hbase.log dryRun
Anything passed that is not
truewill schedule SCPs because the default option is dryrun=false.