hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mi...@apache.org
Subject [01/52] [partial] hbase-site git commit: Published site at 1cfd22bf43c9b64afae35d9bf16f764d0da80cab.
Date Tue, 21 Mar 2017 16:35:57 GMT
Repository: hbase-site
Updated Branches:
  refs/heads/asf-site c6ddb98fc -> fadf6d5a0


http://git-wip-us.apache.org/repos/asf/hbase-site/blob/22cff34f/apidocs/src-html/org/apache/hadoop/hbase/util/RegionMover.html
----------------------------------------------------------------------
diff --git a/apidocs/src-html/org/apache/hadoop/hbase/util/RegionMover.html b/apidocs/src-html/org/apache/hadoop/hbase/util/RegionMover.html
index 27b58df..c28cd5c 100644
--- a/apidocs/src-html/org/apache/hadoop/hbase/util/RegionMover.html
+++ b/apidocs/src-html/org/apache/hadoop/hbase/util/RegionMover.html
@@ -405,7 +405,7 @@
 <span class="sourceLineNo">397</span>    LOG.info("Moving " + regionsToMove.size()
+ " regions to " + server + " using "<a name="line.397"></a>
 <span class="sourceLineNo">398</span>        + this.maxthreads + " threads.Ack
mode:" + this.ack);<a name="line.398"></a>
 <span class="sourceLineNo">399</span>    ExecutorService moveRegionsPool = Executors.newFixedThreadPool(this.maxthreads);<a
name="line.399"></a>
-<span class="sourceLineNo">400</span>    List&lt;Future&lt;Boolean&gt;&gt;
taskList = new ArrayList&lt;Future&lt;Boolean&gt;&gt;();<a name="line.400"></a>
+<span class="sourceLineNo">400</span>    List&lt;Future&lt;Boolean&gt;&gt;
taskList = new ArrayList&lt;&gt;();<a name="line.400"></a>
 <span class="sourceLineNo">401</span>    int counter = 0;<a name="line.401"></a>
 <span class="sourceLineNo">402</span>    while (counter &lt; regionsToMove.size())
{<a name="line.402"></a>
 <span class="sourceLineNo">403</span>      HRegionInfo region = regionsToMove.get(counter);<a
name="line.403"></a>
@@ -469,7 +469,7 @@
 <span class="sourceLineNo">461</span>      justification="FB is wrong; its size
is read")<a name="line.461"></a>
 <span class="sourceLineNo">462</span>  private void unloadRegions(Admin admin,
String server, ArrayList&lt;String&gt; regionServers,<a name="line.462"></a>
 <span class="sourceLineNo">463</span>      boolean ack, List&lt;HRegionInfo&gt;
movedRegions) throws Exception {<a name="line.463"></a>
-<span class="sourceLineNo">464</span>    List&lt;HRegionInfo&gt; regionsToMove
= new ArrayList&lt;HRegionInfo&gt;();// FindBugs: DLS_DEAD_LOCAL_STORE<a name="line.464"></a>
+<span class="sourceLineNo">464</span>    List&lt;HRegionInfo&gt; regionsToMove
= new ArrayList&lt;&gt;();// FindBugs: DLS_DEAD_LOCAL_STORE<a name="line.464"></a>
 <span class="sourceLineNo">465</span>    regionsToMove = getRegions(this.conf,
server);<a name="line.465"></a>
 <span class="sourceLineNo">466</span>    if (regionsToMove.isEmpty()) {<a
name="line.466"></a>
 <span class="sourceLineNo">467</span>      LOG.info("No Regions to move....Quitting
now");<a name="line.467"></a>
@@ -489,7 +489,7 @@
 <span class="sourceLineNo">481</span>          + regionServers.size() + " servers
using " + this.maxthreads + " threads .Ack Mode:"<a name="line.481"></a>
 <span class="sourceLineNo">482</span>          + ack);<a name="line.482"></a>
 <span class="sourceLineNo">483</span>      ExecutorService moveRegionsPool =
Executors.newFixedThreadPool(this.maxthreads);<a name="line.483"></a>
-<span class="sourceLineNo">484</span>      List&lt;Future&lt;Boolean&gt;&gt;
taskList = new ArrayList&lt;Future&lt;Boolean&gt;&gt;();<a name="line.484"></a>
+<span class="sourceLineNo">484</span>      List&lt;Future&lt;Boolean&gt;&gt;
taskList = new ArrayList&lt;&gt;();<a name="line.484"></a>
 <span class="sourceLineNo">485</span>      int serverIndex = 0;<a name="line.485"></a>
 <span class="sourceLineNo">486</span>      while (counter &lt; regionsToMove.size())
{<a name="line.486"></a>
 <span class="sourceLineNo">487</span>        if (ack) {<a name="line.487"></a>
@@ -644,7 +644,7 @@
 <span class="sourceLineNo">636</span>  }<a name="line.636"></a>
 <span class="sourceLineNo">637</span><a name="line.637"></a>
 <span class="sourceLineNo">638</span>  private List&lt;HRegionInfo&gt;
readRegionsFromFile(String filename) throws IOException {<a name="line.638"></a>
-<span class="sourceLineNo">639</span>    List&lt;HRegionInfo&gt; regions
= new ArrayList&lt;HRegionInfo&gt;();<a name="line.639"></a>
+<span class="sourceLineNo">639</span>    List&lt;HRegionInfo&gt; regions
= new ArrayList&lt;&gt;();<a name="line.639"></a>
 <span class="sourceLineNo">640</span>    File f = new File(filename);<a name="line.640"></a>
 <span class="sourceLineNo">641</span>    if (!f.exists()) {<a name="line.641"></a>
 <span class="sourceLineNo">642</span>      return regions;<a name="line.642"></a>
@@ -766,7 +766,7 @@
 <span class="sourceLineNo">758</span>   * @return List of servers from the exclude
file in format 'hostname:port'.<a name="line.758"></a>
 <span class="sourceLineNo">759</span>   */<a name="line.759"></a>
 <span class="sourceLineNo">760</span>  private ArrayList&lt;String&gt;
readExcludes(String excludeFile) throws IOException {<a name="line.760"></a>
-<span class="sourceLineNo">761</span>    ArrayList&lt;String&gt; excludeServers
= new ArrayList&lt;String&gt;();<a name="line.761"></a>
+<span class="sourceLineNo">761</span>    ArrayList&lt;String&gt; excludeServers
= new ArrayList&lt;&gt;();<a name="line.761"></a>
 <span class="sourceLineNo">762</span>    if (excludeFile == null) {<a name="line.762"></a>
 <span class="sourceLineNo">763</span>      return excludeServers;<a name="line.763"></a>
 <span class="sourceLineNo">764</span>    } else {<a name="line.764"></a>
@@ -829,184 +829,183 @@
 <span class="sourceLineNo">821</span>   * @throws IOException<a name="line.821"></a>
 <span class="sourceLineNo">822</span>   */<a name="line.822"></a>
 <span class="sourceLineNo">823</span>  private ArrayList&lt;String&gt;
getServers(Admin admin) throws IOException {<a name="line.823"></a>
-<span class="sourceLineNo">824</span>    ArrayList&lt;ServerName&gt;
serverInfo =<a name="line.824"></a>
-<span class="sourceLineNo">825</span>        new ArrayList&lt;ServerName&gt;(admin.getClusterStatus().getServers());<a
name="line.825"></a>
-<span class="sourceLineNo">826</span>    ArrayList&lt;String&gt; regionServers
= new ArrayList&lt;String&gt;(serverInfo.size());<a name="line.826"></a>
-<span class="sourceLineNo">827</span>    for (ServerName server : serverInfo)
{<a name="line.827"></a>
-<span class="sourceLineNo">828</span>      regionServers.add(server.getServerName());<a
name="line.828"></a>
-<span class="sourceLineNo">829</span>    }<a name="line.829"></a>
-<span class="sourceLineNo">830</span>    return regionServers;<a name="line.830"></a>
-<span class="sourceLineNo">831</span>  }<a name="line.831"></a>
-<span class="sourceLineNo">832</span><a name="line.832"></a>
-<span class="sourceLineNo">833</span>  private void deleteFile(String filename)
{<a name="line.833"></a>
-<span class="sourceLineNo">834</span>    File f = new File(filename);<a name="line.834"></a>
-<span class="sourceLineNo">835</span>    if (f.exists()) {<a name="line.835"></a>
-<span class="sourceLineNo">836</span>      f.delete();<a name="line.836"></a>
-<span class="sourceLineNo">837</span>    }<a name="line.837"></a>
-<span class="sourceLineNo">838</span>  }<a name="line.838"></a>
-<span class="sourceLineNo">839</span><a name="line.839"></a>
-<span class="sourceLineNo">840</span>  /**<a name="line.840"></a>
-<span class="sourceLineNo">841</span>   * Tries to scan a row from passed region<a
name="line.841"></a>
-<span class="sourceLineNo">842</span>   * @param admin<a name="line.842"></a>
-<span class="sourceLineNo">843</span>   * @param region<a name="line.843"></a>
-<span class="sourceLineNo">844</span>   * @throws IOException<a name="line.844"></a>
-<span class="sourceLineNo">845</span>   */<a name="line.845"></a>
-<span class="sourceLineNo">846</span>  private void isSuccessfulScan(Admin admin,
HRegionInfo region) throws IOException {<a name="line.846"></a>
-<span class="sourceLineNo">847</span>    Scan scan = new Scan(region.getStartKey());<a
name="line.847"></a>
-<span class="sourceLineNo">848</span>    scan.setBatch(1);<a name="line.848"></a>
-<span class="sourceLineNo">849</span>    scan.setCaching(1);<a name="line.849"></a>
-<span class="sourceLineNo">850</span>    scan.setFilter(new FirstKeyOnlyFilter());<a
name="line.850"></a>
-<span class="sourceLineNo">851</span>    try {<a name="line.851"></a>
-<span class="sourceLineNo">852</span>      Table table = admin.getConnection().getTable(region.getTable());<a
name="line.852"></a>
-<span class="sourceLineNo">853</span>      try {<a name="line.853"></a>
-<span class="sourceLineNo">854</span>        ResultScanner scanner = table.getScanner(scan);<a
name="line.854"></a>
-<span class="sourceLineNo">855</span>        try {<a name="line.855"></a>
-<span class="sourceLineNo">856</span>          scanner.next();<a name="line.856"></a>
-<span class="sourceLineNo">857</span>        } finally {<a name="line.857"></a>
-<span class="sourceLineNo">858</span>          scanner.close();<a name="line.858"></a>
-<span class="sourceLineNo">859</span>        }<a name="line.859"></a>
-<span class="sourceLineNo">860</span>      } finally {<a name="line.860"></a>
-<span class="sourceLineNo">861</span>        table.close();<a name="line.861"></a>
-<span class="sourceLineNo">862</span>      }<a name="line.862"></a>
-<span class="sourceLineNo">863</span>    } catch (IOException e) {<a name="line.863"></a>
-<span class="sourceLineNo">864</span>      LOG.error("Could not scan region:"
+ region.getEncodedName(), e);<a name="line.864"></a>
-<span class="sourceLineNo">865</span>      throw e;<a name="line.865"></a>
-<span class="sourceLineNo">866</span>    }<a name="line.866"></a>
-<span class="sourceLineNo">867</span>  }<a name="line.867"></a>
-<span class="sourceLineNo">868</span><a name="line.868"></a>
-<span class="sourceLineNo">869</span>  /**<a name="line.869"></a>
-<span class="sourceLineNo">870</span>   * Returns true if passed region is still
on serverName when we look at hbase:meta.<a name="line.870"></a>
-<span class="sourceLineNo">871</span>   * @param admin<a name="line.871"></a>
-<span class="sourceLineNo">872</span>   * @param region<a name="line.872"></a>
-<span class="sourceLineNo">873</span>   * @param serverName<a name="line.873"></a>
-<span class="sourceLineNo">874</span>   * @return true if region is hosted on
serverName otherwise false<a name="line.874"></a>
-<span class="sourceLineNo">875</span>   * @throws IOException<a name="line.875"></a>
-<span class="sourceLineNo">876</span>   */<a name="line.876"></a>
-<span class="sourceLineNo">877</span>  private boolean isSameServer(Admin admin,
HRegionInfo region, String serverName)<a name="line.877"></a>
-<span class="sourceLineNo">878</span>      throws IOException {<a name="line.878"></a>
-<span class="sourceLineNo">879</span>    String serverForRegion = getServerNameForRegion(admin,
region);<a name="line.879"></a>
-<span class="sourceLineNo">880</span>    if (serverForRegion != null &amp;&amp;
serverForRegion.equals(serverName)) {<a name="line.880"></a>
-<span class="sourceLineNo">881</span>      return true;<a name="line.881"></a>
-<span class="sourceLineNo">882</span>    }<a name="line.882"></a>
-<span class="sourceLineNo">883</span>    return false;<a name="line.883"></a>
-<span class="sourceLineNo">884</span>  }<a name="line.884"></a>
-<span class="sourceLineNo">885</span><a name="line.885"></a>
-<span class="sourceLineNo">886</span>  /**<a name="line.886"></a>
-<span class="sourceLineNo">887</span>   * Get servername that is up in hbase:meta
hosting the given region. this is hostname + port +<a name="line.887"></a>
-<span class="sourceLineNo">888</span>   * startcode comma-delimited. Can return
null<a name="line.888"></a>
-<span class="sourceLineNo">889</span>   * @param admin<a name="line.889"></a>
-<span class="sourceLineNo">890</span>   * @param region<a name="line.890"></a>
-<span class="sourceLineNo">891</span>   * @return regionServer hosting the given
region<a name="line.891"></a>
-<span class="sourceLineNo">892</span>   * @throws IOException<a name="line.892"></a>
-<span class="sourceLineNo">893</span>   */<a name="line.893"></a>
-<span class="sourceLineNo">894</span>  private String getServerNameForRegion(Admin
admin, HRegionInfo region) throws IOException {<a name="line.894"></a>
-<span class="sourceLineNo">895</span>    String server = null;<a name="line.895"></a>
-<span class="sourceLineNo">896</span>    if (!admin.isTableEnabled(region.getTable()))
{<a name="line.896"></a>
-<span class="sourceLineNo">897</span>      return null;<a name="line.897"></a>
-<span class="sourceLineNo">898</span>    }<a name="line.898"></a>
-<span class="sourceLineNo">899</span>    if (region.isMetaRegion()) {<a name="line.899"></a>
-<span class="sourceLineNo">900</span>      ZooKeeperWatcher zkw = new ZooKeeperWatcher(admin.getConfiguration(),
"region_mover", null);<a name="line.900"></a>
-<span class="sourceLineNo">901</span>      MetaTableLocator locator = new MetaTableLocator();<a
name="line.901"></a>
-<span class="sourceLineNo">902</span>      int maxWaitInSeconds =<a name="line.902"></a>
-<span class="sourceLineNo">903</span>          admin.getConfiguration().getInt(MOVE_WAIT_MAX_KEY,
DEFAULT_MOVE_WAIT_MAX);<a name="line.903"></a>
-<span class="sourceLineNo">904</span>      try {<a name="line.904"></a>
-<span class="sourceLineNo">905</span>        server = locator.waitMetaRegionLocation(zkw,
maxWaitInSeconds * 1000).toString() + ",";<a name="line.905"></a>
-<span class="sourceLineNo">906</span>      } catch (InterruptedException e) {<a
name="line.906"></a>
-<span class="sourceLineNo">907</span>        LOG.error("Interrupted while waiting
for location of Meta", e);<a name="line.907"></a>
-<span class="sourceLineNo">908</span>      } finally {<a name="line.908"></a>
-<span class="sourceLineNo">909</span>        if (zkw != null) {<a name="line.909"></a>
-<span class="sourceLineNo">910</span>          zkw.close();<a name="line.910"></a>
-<span class="sourceLineNo">911</span>        }<a name="line.911"></a>
-<span class="sourceLineNo">912</span>      }<a name="line.912"></a>
-<span class="sourceLineNo">913</span>    } else {<a name="line.913"></a>
-<span class="sourceLineNo">914</span>      Table table = admin.getConnection().getTable(TableName.META_TABLE_NAME);<a
name="line.914"></a>
-<span class="sourceLineNo">915</span>      try {<a name="line.915"></a>
-<span class="sourceLineNo">916</span>        Get get = new Get(region.getRegionName());<a
name="line.916"></a>
-<span class="sourceLineNo">917</span>        get.addColumn(HConstants.CATALOG_FAMILY,
HConstants.SERVER_QUALIFIER);<a name="line.917"></a>
-<span class="sourceLineNo">918</span>        get.addColumn(HConstants.CATALOG_FAMILY,
HConstants.STARTCODE_QUALIFIER);<a name="line.918"></a>
-<span class="sourceLineNo">919</span>        Result result = table.get(get);<a
name="line.919"></a>
-<span class="sourceLineNo">920</span>        if (result != null) {<a name="line.920"></a>
-<span class="sourceLineNo">921</span>          byte[] servername =<a name="line.921"></a>
-<span class="sourceLineNo">922</span>              result.getValue(HConstants.CATALOG_FAMILY,
HConstants.SERVER_QUALIFIER);<a name="line.922"></a>
-<span class="sourceLineNo">923</span>          byte[] startcode =<a name="line.923"></a>
-<span class="sourceLineNo">924</span>              result.getValue(HConstants.CATALOG_FAMILY,
HConstants.STARTCODE_QUALIFIER);<a name="line.924"></a>
-<span class="sourceLineNo">925</span>          if (servername != null) {<a
name="line.925"></a>
-<span class="sourceLineNo">926</span>            server =<a name="line.926"></a>
-<span class="sourceLineNo">927</span>                Bytes.toString(servername).replaceFirst(":",
",") + "," + Bytes.toLong(startcode);<a name="line.927"></a>
-<span class="sourceLineNo">928</span>          }<a name="line.928"></a>
-<span class="sourceLineNo">929</span>        }<a name="line.929"></a>
-<span class="sourceLineNo">930</span>      } catch (IOException e) {<a name="line.930"></a>
-<span class="sourceLineNo">931</span>        LOG.error("Could not get Server
Name for region:" + region.getEncodedName(), e);<a name="line.931"></a>
-<span class="sourceLineNo">932</span>        throw e;<a name="line.932"></a>
-<span class="sourceLineNo">933</span>      } finally {<a name="line.933"></a>
-<span class="sourceLineNo">934</span>        table.close();<a name="line.934"></a>
-<span class="sourceLineNo">935</span>      }<a name="line.935"></a>
-<span class="sourceLineNo">936</span>    }<a name="line.936"></a>
-<span class="sourceLineNo">937</span>    return server;<a name="line.937"></a>
-<span class="sourceLineNo">938</span>  }<a name="line.938"></a>
-<span class="sourceLineNo">939</span><a name="line.939"></a>
-<span class="sourceLineNo">940</span>  @Override<a name="line.940"></a>
-<span class="sourceLineNo">941</span>  protected void addOptions() {<a name="line.941"></a>
-<span class="sourceLineNo">942</span>    this.addRequiredOptWithArg("r", "regionserverhost",
"region server &lt;hostname&gt;|&lt;hostname:port&gt;");<a name="line.942"></a>
-<span class="sourceLineNo">943</span>    this.addRequiredOptWithArg("o", "operation",
"Expected: load/unload");<a name="line.943"></a>
-<span class="sourceLineNo">944</span>    this.addOptWithArg("m", "maxthreads",<a
name="line.944"></a>
-<span class="sourceLineNo">945</span>      "Define the maximum number of threads
to use to unload and reload the regions");<a name="line.945"></a>
-<span class="sourceLineNo">946</span>    this.addOptWithArg("x", "excludefile",<a
name="line.946"></a>
-<span class="sourceLineNo">947</span>      "File with &lt;hostname:port&gt;
per line to exclude as unload targets; default excludes only "<a name="line.947"></a>
-<span class="sourceLineNo">948</span>          + "target host; useful for rack
decommisioning.");<a name="line.948"></a>
-<span class="sourceLineNo">949</span>    this.addOptWithArg("f", "filename",<a
name="line.949"></a>
-<span class="sourceLineNo">950</span>      "File to save regions list into unloading,
or read from loading; "<a name="line.950"></a>
-<span class="sourceLineNo">951</span>          + "default /tmp/&lt;usernamehostname:port&gt;");<a
name="line.951"></a>
-<span class="sourceLineNo">952</span>    this.addOptNoArg("n", "noack",<a
name="line.952"></a>
-<span class="sourceLineNo">953</span>      "Turn on No-Ack mode(default: false)
which won't check if region is online on target "<a name="line.953"></a>
-<span class="sourceLineNo">954</span>          + "RegionServer, hence best effort.
This is more performant in unloading and loading "<a name="line.954"></a>
-<span class="sourceLineNo">955</span>          + "but might lead to region being
unavailable for some time till master reassigns it "<a name="line.955"></a>
-<span class="sourceLineNo">956</span>          + "in case the move failed");<a
name="line.956"></a>
-<span class="sourceLineNo">957</span>    this.addOptWithArg("t", "timeout", "timeout
in seconds after which the tool will exit "<a name="line.957"></a>
-<span class="sourceLineNo">958</span>        + "irrespective of whether it finished
or not;default Integer.MAX_VALUE");<a name="line.958"></a>
-<span class="sourceLineNo">959</span>  }<a name="line.959"></a>
-<span class="sourceLineNo">960</span><a name="line.960"></a>
-<span class="sourceLineNo">961</span>  @Override<a name="line.961"></a>
-<span class="sourceLineNo">962</span>  protected void processOptions(CommandLine
cmd) {<a name="line.962"></a>
-<span class="sourceLineNo">963</span>    String hostname = cmd.getOptionValue("r");<a
name="line.963"></a>
-<span class="sourceLineNo">964</span>    rmbuilder = new RegionMoverBuilder(hostname);<a
name="line.964"></a>
-<span class="sourceLineNo">965</span>    if (cmd.hasOption('m')) {<a name="line.965"></a>
-<span class="sourceLineNo">966</span>      rmbuilder.maxthreads(Integer.parseInt(cmd.getOptionValue('m')));<a
name="line.966"></a>
-<span class="sourceLineNo">967</span>    }<a name="line.967"></a>
-<span class="sourceLineNo">968</span>    if (cmd.hasOption('n')) {<a name="line.968"></a>
-<span class="sourceLineNo">969</span>      rmbuilder.ack(false);<a name="line.969"></a>
-<span class="sourceLineNo">970</span>    }<a name="line.970"></a>
-<span class="sourceLineNo">971</span>    if (cmd.hasOption('f')) {<a name="line.971"></a>
-<span class="sourceLineNo">972</span>      rmbuilder.filename(cmd.getOptionValue('f'));<a
name="line.972"></a>
-<span class="sourceLineNo">973</span>    }<a name="line.973"></a>
-<span class="sourceLineNo">974</span>    if (cmd.hasOption('x')) {<a name="line.974"></a>
-<span class="sourceLineNo">975</span>      rmbuilder.excludeFile(cmd.getOptionValue('x'));<a
name="line.975"></a>
-<span class="sourceLineNo">976</span>    }<a name="line.976"></a>
-<span class="sourceLineNo">977</span>    if (cmd.hasOption('t')) {<a name="line.977"></a>
-<span class="sourceLineNo">978</span>      rmbuilder.timeout(Integer.parseInt(cmd.getOptionValue('t')));<a
name="line.978"></a>
-<span class="sourceLineNo">979</span>    }<a name="line.979"></a>
-<span class="sourceLineNo">980</span>    this.loadUnload = cmd.getOptionValue("o").toLowerCase(Locale.ROOT);<a
name="line.980"></a>
-<span class="sourceLineNo">981</span>  }<a name="line.981"></a>
-<span class="sourceLineNo">982</span><a name="line.982"></a>
-<span class="sourceLineNo">983</span>  @Override<a name="line.983"></a>
-<span class="sourceLineNo">984</span>  protected int doWork() throws Exception
{<a name="line.984"></a>
-<span class="sourceLineNo">985</span>    boolean success;<a name="line.985"></a>
-<span class="sourceLineNo">986</span>    RegionMover rm = rmbuilder.build();<a
name="line.986"></a>
-<span class="sourceLineNo">987</span>    if (loadUnload.equalsIgnoreCase("load"))
{<a name="line.987"></a>
-<span class="sourceLineNo">988</span>      success = rm.load();<a name="line.988"></a>
-<span class="sourceLineNo">989</span>    } else if (loadUnload.equalsIgnoreCase("unload"))
{<a name="line.989"></a>
-<span class="sourceLineNo">990</span>      success = rm.unload();<a name="line.990"></a>
-<span class="sourceLineNo">991</span>    } else {<a name="line.991"></a>
-<span class="sourceLineNo">992</span>      printUsage();<a name="line.992"></a>
-<span class="sourceLineNo">993</span>      success = false;<a name="line.993"></a>
-<span class="sourceLineNo">994</span>    }<a name="line.994"></a>
-<span class="sourceLineNo">995</span>    return (success ? 0 : 1);<a name="line.995"></a>
-<span class="sourceLineNo">996</span>  }<a name="line.996"></a>
-<span class="sourceLineNo">997</span><a name="line.997"></a>
-<span class="sourceLineNo">998</span>  public static void main(String[] args)
{<a name="line.998"></a>
-<span class="sourceLineNo">999</span>    new RegionMover().doStaticMain(args);<a
name="line.999"></a>
-<span class="sourceLineNo">1000</span>  }<a name="line.1000"></a>
-<span class="sourceLineNo">1001</span>}<a name="line.1001"></a>
+<span class="sourceLineNo">824</span>    ArrayList&lt;ServerName&gt;
serverInfo = new ArrayList&lt;&gt;(admin.getClusterStatus().getServers());<a name="line.824"></a>
+<span class="sourceLineNo">825</span>    ArrayList&lt;String&gt; regionServers
= new ArrayList&lt;&gt;(serverInfo.size());<a name="line.825"></a>
+<span class="sourceLineNo">826</span>    for (ServerName server : serverInfo)
{<a name="line.826"></a>
+<span class="sourceLineNo">827</span>      regionServers.add(server.getServerName());<a
name="line.827"></a>
+<span class="sourceLineNo">828</span>    }<a name="line.828"></a>
+<span class="sourceLineNo">829</span>    return regionServers;<a name="line.829"></a>
+<span class="sourceLineNo">830</span>  }<a name="line.830"></a>
+<span class="sourceLineNo">831</span><a name="line.831"></a>
+<span class="sourceLineNo">832</span>  private void deleteFile(String filename)
{<a name="line.832"></a>
+<span class="sourceLineNo">833</span>    File f = new File(filename);<a name="line.833"></a>
+<span class="sourceLineNo">834</span>    if (f.exists()) {<a name="line.834"></a>
+<span class="sourceLineNo">835</span>      f.delete();<a name="line.835"></a>
+<span class="sourceLineNo">836</span>    }<a name="line.836"></a>
+<span class="sourceLineNo">837</span>  }<a name="line.837"></a>
+<span class="sourceLineNo">838</span><a name="line.838"></a>
+<span class="sourceLineNo">839</span>  /**<a name="line.839"></a>
+<span class="sourceLineNo">840</span>   * Tries to scan a row from passed region<a
name="line.840"></a>
+<span class="sourceLineNo">841</span>   * @param admin<a name="line.841"></a>
+<span class="sourceLineNo">842</span>   * @param region<a name="line.842"></a>
+<span class="sourceLineNo">843</span>   * @throws IOException<a name="line.843"></a>
+<span class="sourceLineNo">844</span>   */<a name="line.844"></a>
+<span class="sourceLineNo">845</span>  private void isSuccessfulScan(Admin admin,
HRegionInfo region) throws IOException {<a name="line.845"></a>
+<span class="sourceLineNo">846</span>    Scan scan = new Scan(region.getStartKey());<a
name="line.846"></a>
+<span class="sourceLineNo">847</span>    scan.setBatch(1);<a name="line.847"></a>
+<span class="sourceLineNo">848</span>    scan.setCaching(1);<a name="line.848"></a>
+<span class="sourceLineNo">849</span>    scan.setFilter(new FirstKeyOnlyFilter());<a
name="line.849"></a>
+<span class="sourceLineNo">850</span>    try {<a name="line.850"></a>
+<span class="sourceLineNo">851</span>      Table table = admin.getConnection().getTable(region.getTable());<a
name="line.851"></a>
+<span class="sourceLineNo">852</span>      try {<a name="line.852"></a>
+<span class="sourceLineNo">853</span>        ResultScanner scanner = table.getScanner(scan);<a
name="line.853"></a>
+<span class="sourceLineNo">854</span>        try {<a name="line.854"></a>
+<span class="sourceLineNo">855</span>          scanner.next();<a name="line.855"></a>
+<span class="sourceLineNo">856</span>        } finally {<a name="line.856"></a>
+<span class="sourceLineNo">857</span>          scanner.close();<a name="line.857"></a>
+<span class="sourceLineNo">858</span>        }<a name="line.858"></a>
+<span class="sourceLineNo">859</span>      } finally {<a name="line.859"></a>
+<span class="sourceLineNo">860</span>        table.close();<a name="line.860"></a>
+<span class="sourceLineNo">861</span>      }<a name="line.861"></a>
+<span class="sourceLineNo">862</span>    } catch (IOException e) {<a name="line.862"></a>
+<span class="sourceLineNo">863</span>      LOG.error("Could not scan region:"
+ region.getEncodedName(), e);<a name="line.863"></a>
+<span class="sourceLineNo">864</span>      throw e;<a name="line.864"></a>
+<span class="sourceLineNo">865</span>    }<a name="line.865"></a>
+<span class="sourceLineNo">866</span>  }<a name="line.866"></a>
+<span class="sourceLineNo">867</span><a name="line.867"></a>
+<span class="sourceLineNo">868</span>  /**<a name="line.868"></a>
+<span class="sourceLineNo">869</span>   * Returns true if passed region is still
on serverName when we look at hbase:meta.<a name="line.869"></a>
+<span class="sourceLineNo">870</span>   * @param admin<a name="line.870"></a>
+<span class="sourceLineNo">871</span>   * @param region<a name="line.871"></a>
+<span class="sourceLineNo">872</span>   * @param serverName<a name="line.872"></a>
+<span class="sourceLineNo">873</span>   * @return true if region is hosted on
serverName otherwise false<a name="line.873"></a>
+<span class="sourceLineNo">874</span>   * @throws IOException<a name="line.874"></a>
+<span class="sourceLineNo">875</span>   */<a name="line.875"></a>
+<span class="sourceLineNo">876</span>  private boolean isSameServer(Admin admin,
HRegionInfo region, String serverName)<a name="line.876"></a>
+<span class="sourceLineNo">877</span>      throws IOException {<a name="line.877"></a>
+<span class="sourceLineNo">878</span>    String serverForRegion = getServerNameForRegion(admin,
region);<a name="line.878"></a>
+<span class="sourceLineNo">879</span>    if (serverForRegion != null &amp;&amp;
serverForRegion.equals(serverName)) {<a name="line.879"></a>
+<span class="sourceLineNo">880</span>      return true;<a name="line.880"></a>
+<span class="sourceLineNo">881</span>    }<a name="line.881"></a>
+<span class="sourceLineNo">882</span>    return false;<a name="line.882"></a>
+<span class="sourceLineNo">883</span>  }<a name="line.883"></a>
+<span class="sourceLineNo">884</span><a name="line.884"></a>
+<span class="sourceLineNo">885</span>  /**<a name="line.885"></a>
+<span class="sourceLineNo">886</span>   * Get servername that is up in hbase:meta
hosting the given region. this is hostname + port +<a name="line.886"></a>
+<span class="sourceLineNo">887</span>   * startcode comma-delimited. Can return
null<a name="line.887"></a>
+<span class="sourceLineNo">888</span>   * @param admin<a name="line.888"></a>
+<span class="sourceLineNo">889</span>   * @param region<a name="line.889"></a>
+<span class="sourceLineNo">890</span>   * @return regionServer hosting the given
region<a name="line.890"></a>
+<span class="sourceLineNo">891</span>   * @throws IOException<a name="line.891"></a>
+<span class="sourceLineNo">892</span>   */<a name="line.892"></a>
+<span class="sourceLineNo">893</span>  private String getServerNameForRegion(Admin
admin, HRegionInfo region) throws IOException {<a name="line.893"></a>
+<span class="sourceLineNo">894</span>    String server = null;<a name="line.894"></a>
+<span class="sourceLineNo">895</span>    if (!admin.isTableEnabled(region.getTable()))
{<a name="line.895"></a>
+<span class="sourceLineNo">896</span>      return null;<a name="line.896"></a>
+<span class="sourceLineNo">897</span>    }<a name="line.897"></a>
+<span class="sourceLineNo">898</span>    if (region.isMetaRegion()) {<a name="line.898"></a>
+<span class="sourceLineNo">899</span>      ZooKeeperWatcher zkw = new ZooKeeperWatcher(admin.getConfiguration(),
"region_mover", null);<a name="line.899"></a>
+<span class="sourceLineNo">900</span>      MetaTableLocator locator = new MetaTableLocator();<a
name="line.900"></a>
+<span class="sourceLineNo">901</span>      int maxWaitInSeconds =<a name="line.901"></a>
+<span class="sourceLineNo">902</span>          admin.getConfiguration().getInt(MOVE_WAIT_MAX_KEY,
DEFAULT_MOVE_WAIT_MAX);<a name="line.902"></a>
+<span class="sourceLineNo">903</span>      try {<a name="line.903"></a>
+<span class="sourceLineNo">904</span>        server = locator.waitMetaRegionLocation(zkw,
maxWaitInSeconds * 1000).toString() + ",";<a name="line.904"></a>
+<span class="sourceLineNo">905</span>      } catch (InterruptedException e) {<a
name="line.905"></a>
+<span class="sourceLineNo">906</span>        LOG.error("Interrupted while waiting
for location of Meta", e);<a name="line.906"></a>
+<span class="sourceLineNo">907</span>      } finally {<a name="line.907"></a>
+<span class="sourceLineNo">908</span>        if (zkw != null) {<a name="line.908"></a>
+<span class="sourceLineNo">909</span>          zkw.close();<a name="line.909"></a>
+<span class="sourceLineNo">910</span>        }<a name="line.910"></a>
+<span class="sourceLineNo">911</span>      }<a name="line.911"></a>
+<span class="sourceLineNo">912</span>    } else {<a name="line.912"></a>
+<span class="sourceLineNo">913</span>      Table table = admin.getConnection().getTable(TableName.META_TABLE_NAME);<a
name="line.913"></a>
+<span class="sourceLineNo">914</span>      try {<a name="line.914"></a>
+<span class="sourceLineNo">915</span>        Get get = new Get(region.getRegionName());<a
name="line.915"></a>
+<span class="sourceLineNo">916</span>        get.addColumn(HConstants.CATALOG_FAMILY,
HConstants.SERVER_QUALIFIER);<a name="line.916"></a>
+<span class="sourceLineNo">917</span>        get.addColumn(HConstants.CATALOG_FAMILY,
HConstants.STARTCODE_QUALIFIER);<a name="line.917"></a>
+<span class="sourceLineNo">918</span>        Result result = table.get(get);<a
name="line.918"></a>
+<span class="sourceLineNo">919</span>        if (result != null) {<a name="line.919"></a>
+<span class="sourceLineNo">920</span>          byte[] servername =<a name="line.920"></a>
+<span class="sourceLineNo">921</span>              result.getValue(HConstants.CATALOG_FAMILY,
HConstants.SERVER_QUALIFIER);<a name="line.921"></a>
+<span class="sourceLineNo">922</span>          byte[] startcode =<a name="line.922"></a>
+<span class="sourceLineNo">923</span>              result.getValue(HConstants.CATALOG_FAMILY,
HConstants.STARTCODE_QUALIFIER);<a name="line.923"></a>
+<span class="sourceLineNo">924</span>          if (servername != null) {<a
name="line.924"></a>
+<span class="sourceLineNo">925</span>            server =<a name="line.925"></a>
+<span class="sourceLineNo">926</span>                Bytes.toString(servername).replaceFirst(":",
",") + "," + Bytes.toLong(startcode);<a name="line.926"></a>
+<span class="sourceLineNo">927</span>          }<a name="line.927"></a>
+<span class="sourceLineNo">928</span>        }<a name="line.928"></a>
+<span class="sourceLineNo">929</span>      } catch (IOException e) {<a name="line.929"></a>
+<span class="sourceLineNo">930</span>        LOG.error("Could not get Server
Name for region:" + region.getEncodedName(), e);<a name="line.930"></a>
+<span class="sourceLineNo">931</span>        throw e;<a name="line.931"></a>
+<span class="sourceLineNo">932</span>      } finally {<a name="line.932"></a>
+<span class="sourceLineNo">933</span>        table.close();<a name="line.933"></a>
+<span class="sourceLineNo">934</span>      }<a name="line.934"></a>
+<span class="sourceLineNo">935</span>    }<a name="line.935"></a>
+<span class="sourceLineNo">936</span>    return server;<a name="line.936"></a>
+<span class="sourceLineNo">937</span>  }<a name="line.937"></a>
+<span class="sourceLineNo">938</span><a name="line.938"></a>
+<span class="sourceLineNo">939</span>  @Override<a name="line.939"></a>
+<span class="sourceLineNo">940</span>  protected void addOptions() {<a name="line.940"></a>
+<span class="sourceLineNo">941</span>    this.addRequiredOptWithArg("r", "regionserverhost",
"region server &lt;hostname&gt;|&lt;hostname:port&gt;");<a name="line.941"></a>
+<span class="sourceLineNo">942</span>    this.addRequiredOptWithArg("o", "operation",
"Expected: load/unload");<a name="line.942"></a>
+<span class="sourceLineNo">943</span>    this.addOptWithArg("m", "maxthreads",<a
name="line.943"></a>
+<span class="sourceLineNo">944</span>      "Define the maximum number of threads
to use to unload and reload the regions");<a name="line.944"></a>
+<span class="sourceLineNo">945</span>    this.addOptWithArg("x", "excludefile",<a
name="line.945"></a>
+<span class="sourceLineNo">946</span>      "File with &lt;hostname:port&gt;
per line to exclude as unload targets; default excludes only "<a name="line.946"></a>
+<span class="sourceLineNo">947</span>          + "target host; useful for rack
decommisioning.");<a name="line.947"></a>
+<span class="sourceLineNo">948</span>    this.addOptWithArg("f", "filename",<a
name="line.948"></a>
+<span class="sourceLineNo">949</span>      "File to save regions list into unloading,
or read from loading; "<a name="line.949"></a>
+<span class="sourceLineNo">950</span>          + "default /tmp/&lt;usernamehostname:port&gt;");<a
name="line.950"></a>
+<span class="sourceLineNo">951</span>    this.addOptNoArg("n", "noack",<a
name="line.951"></a>
+<span class="sourceLineNo">952</span>      "Turn on No-Ack mode(default: false)
which won't check if region is online on target "<a name="line.952"></a>
+<span class="sourceLineNo">953</span>          + "RegionServer, hence best effort.
This is more performant in unloading and loading "<a name="line.953"></a>
+<span class="sourceLineNo">954</span>          + "but might lead to region being
unavailable for some time till master reassigns it "<a name="line.954"></a>
+<span class="sourceLineNo">955</span>          + "in case the move failed");<a
name="line.955"></a>
+<span class="sourceLineNo">956</span>    this.addOptWithArg("t", "timeout", "timeout
in seconds after which the tool will exit "<a name="line.956"></a>
+<span class="sourceLineNo">957</span>        + "irrespective of whether it finished
or not;default Integer.MAX_VALUE");<a name="line.957"></a>
+<span class="sourceLineNo">958</span>  }<a name="line.958"></a>
+<span class="sourceLineNo">959</span><a name="line.959"></a>
+<span class="sourceLineNo">960</span>  @Override<a name="line.960"></a>
+<span class="sourceLineNo">961</span>  protected void processOptions(CommandLine
cmd) {<a name="line.961"></a>
+<span class="sourceLineNo">962</span>    String hostname = cmd.getOptionValue("r");<a
name="line.962"></a>
+<span class="sourceLineNo">963</span>    rmbuilder = new RegionMoverBuilder(hostname);<a
name="line.963"></a>
+<span class="sourceLineNo">964</span>    if (cmd.hasOption('m')) {<a name="line.964"></a>
+<span class="sourceLineNo">965</span>      rmbuilder.maxthreads(Integer.parseInt(cmd.getOptionValue('m')));<a
name="line.965"></a>
+<span class="sourceLineNo">966</span>    }<a name="line.966"></a>
+<span class="sourceLineNo">967</span>    if (cmd.hasOption('n')) {<a name="line.967"></a>
+<span class="sourceLineNo">968</span>      rmbuilder.ack(false);<a name="line.968"></a>
+<span class="sourceLineNo">969</span>    }<a name="line.969"></a>
+<span class="sourceLineNo">970</span>    if (cmd.hasOption('f')) {<a name="line.970"></a>
+<span class="sourceLineNo">971</span>      rmbuilder.filename(cmd.getOptionValue('f'));<a
name="line.971"></a>
+<span class="sourceLineNo">972</span>    }<a name="line.972"></a>
+<span class="sourceLineNo">973</span>    if (cmd.hasOption('x')) {<a name="line.973"></a>
+<span class="sourceLineNo">974</span>      rmbuilder.excludeFile(cmd.getOptionValue('x'));<a
name="line.974"></a>
+<span class="sourceLineNo">975</span>    }<a name="line.975"></a>
+<span class="sourceLineNo">976</span>    if (cmd.hasOption('t')) {<a name="line.976"></a>
+<span class="sourceLineNo">977</span>      rmbuilder.timeout(Integer.parseInt(cmd.getOptionValue('t')));<a
name="line.977"></a>
+<span class="sourceLineNo">978</span>    }<a name="line.978"></a>
+<span class="sourceLineNo">979</span>    this.loadUnload = cmd.getOptionValue("o").toLowerCase(Locale.ROOT);<a
name="line.979"></a>
+<span class="sourceLineNo">980</span>  }<a name="line.980"></a>
+<span class="sourceLineNo">981</span><a name="line.981"></a>
+<span class="sourceLineNo">982</span>  @Override<a name="line.982"></a>
+<span class="sourceLineNo">983</span>  protected int doWork() throws Exception
{<a name="line.983"></a>
+<span class="sourceLineNo">984</span>    boolean success;<a name="line.984"></a>
+<span class="sourceLineNo">985</span>    RegionMover rm = rmbuilder.build();<a
name="line.985"></a>
+<span class="sourceLineNo">986</span>    if (loadUnload.equalsIgnoreCase("load"))
{<a name="line.986"></a>
+<span class="sourceLineNo">987</span>      success = rm.load();<a name="line.987"></a>
+<span class="sourceLineNo">988</span>    } else if (loadUnload.equalsIgnoreCase("unload"))
{<a name="line.988"></a>
+<span class="sourceLineNo">989</span>      success = rm.unload();<a name="line.989"></a>
+<span class="sourceLineNo">990</span>    } else {<a name="line.990"></a>
+<span class="sourceLineNo">991</span>      printUsage();<a name="line.991"></a>
+<span class="sourceLineNo">992</span>      success = false;<a name="line.992"></a>
+<span class="sourceLineNo">993</span>    }<a name="line.993"></a>
+<span class="sourceLineNo">994</span>    return (success ? 0 : 1);<a name="line.994"></a>
+<span class="sourceLineNo">995</span>  }<a name="line.995"></a>
+<span class="sourceLineNo">996</span><a name="line.996"></a>
+<span class="sourceLineNo">997</span>  public static void main(String[] args)
{<a name="line.997"></a>
+<span class="sourceLineNo">998</span>    new RegionMover().doStaticMain(args);<a
name="line.998"></a>
+<span class="sourceLineNo">999</span>  }<a name="line.999"></a>
+<span class="sourceLineNo">1000</span>}<a name="line.1000"></a>
 
 
 


Mime
View raw message