blob: 03e6302ac04c2a7bd224827b2bfbe4434d7556fc [file] [log] [blame]
<!DOCTYPE HTML>
<html lang="en">
<head>
<!-- Generated by javadoc (17) -->
<title>Source code</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="source: package: org.apache.hadoop.hbase.util, class: BaseTestHBaseFsck, class: MasterSyncCoprocessor">
<meta name="generator" content="javadoc/SourceToHTMLConverter">
<link rel="stylesheet" type="text/css" href="../../../../../../stylesheet.css" title="Style">
</head>
<body class="source-page">
<main role="main">
<div class="source-container">
<pre><span class="source-line-no">001</span><span id="line-1">/*</span>
<span class="source-line-no">002</span><span id="line-2"> * Licensed to the Apache Software Foundation (ASF) under one</span>
<span class="source-line-no">003</span><span id="line-3"> * or more contributor license agreements. See the NOTICE file</span>
<span class="source-line-no">004</span><span id="line-4"> * distributed with this work for additional information</span>
<span class="source-line-no">005</span><span id="line-5"> * regarding copyright ownership. The ASF licenses this file</span>
<span class="source-line-no">006</span><span id="line-6"> * to you under the Apache License, Version 2.0 (the</span>
<span class="source-line-no">007</span><span id="line-7"> * "License"); you may not use this file except in compliance</span>
<span class="source-line-no">008</span><span id="line-8"> * with the License. You may obtain a copy of the License at</span>
<span class="source-line-no">009</span><span id="line-9"> *</span>
<span class="source-line-no">010</span><span id="line-10"> * http://www.apache.org/licenses/LICENSE-2.0</span>
<span class="source-line-no">011</span><span id="line-11"> *</span>
<span class="source-line-no">012</span><span id="line-12"> * Unless required by applicable law or agreed to in writing, software</span>
<span class="source-line-no">013</span><span id="line-13"> * distributed under the License is distributed on an "AS IS" BASIS,</span>
<span class="source-line-no">014</span><span id="line-14"> * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span>
<span class="source-line-no">015</span><span id="line-15"> * See the License for the specific language governing permissions and</span>
<span class="source-line-no">016</span><span id="line-16"> * limitations under the License.</span>
<span class="source-line-no">017</span><span id="line-17"> */</span>
<span class="source-line-no">018</span><span id="line-18">package org.apache.hadoop.hbase.util;</span>
<span class="source-line-no">019</span><span id="line-19"></span>
<span class="source-line-no">020</span><span id="line-20">import static org.junit.Assert.assertEquals;</span>
<span class="source-line-no">021</span><span id="line-21">import static org.junit.Assert.fail;</span>
<span class="source-line-no">022</span><span id="line-22"></span>
<span class="source-line-no">023</span><span id="line-23">import java.io.IOException;</span>
<span class="source-line-no">024</span><span id="line-24">import java.util.ArrayList;</span>
<span class="source-line-no">025</span><span id="line-25">import java.util.Collection;</span>
<span class="source-line-no">026</span><span id="line-26">import java.util.EnumSet;</span>
<span class="source-line-no">027</span><span id="line-27">import java.util.HashMap;</span>
<span class="source-line-no">028</span><span id="line-28">import java.util.List;</span>
<span class="source-line-no">029</span><span id="line-29">import java.util.Map;</span>
<span class="source-line-no">030</span><span id="line-30">import java.util.Optional;</span>
<span class="source-line-no">031</span><span id="line-31">import java.util.concurrent.CountDownLatch;</span>
<span class="source-line-no">032</span><span id="line-32">import java.util.concurrent.ExecutorService;</span>
<span class="source-line-no">033</span><span id="line-33">import java.util.concurrent.ScheduledThreadPoolExecutor;</span>
<span class="source-line-no">034</span><span id="line-34">import org.apache.hadoop.conf.Configuration;</span>
<span class="source-line-no">035</span><span id="line-35">import org.apache.hadoop.fs.FileStatus;</span>
<span class="source-line-no">036</span><span id="line-36">import org.apache.hadoop.fs.FileSystem;</span>
<span class="source-line-no">037</span><span id="line-37">import org.apache.hadoop.fs.Path;</span>
<span class="source-line-no">038</span><span id="line-38">import org.apache.hadoop.hbase.ClusterMetrics;</span>
<span class="source-line-no">039</span><span id="line-39">import org.apache.hadoop.hbase.ClusterMetrics.Option;</span>
<span class="source-line-no">040</span><span id="line-40">import org.apache.hadoop.hbase.HBaseTestingUtil;</span>
<span class="source-line-no">041</span><span id="line-41">import org.apache.hadoop.hbase.HConstants;</span>
<span class="source-line-no">042</span><span id="line-42">import org.apache.hadoop.hbase.HRegionLocation;</span>
<span class="source-line-no">043</span><span id="line-43">import org.apache.hadoop.hbase.MetaTableAccessor;</span>
<span class="source-line-no">044</span><span id="line-44">import org.apache.hadoop.hbase.ServerName;</span>
<span class="source-line-no">045</span><span id="line-45">import org.apache.hadoop.hbase.TableName;</span>
<span class="source-line-no">046</span><span id="line-46">import org.apache.hadoop.hbase.client.Admin;</span>
<span class="source-line-no">047</span><span id="line-47">import org.apache.hadoop.hbase.client.ColumnFamilyDescriptor;</span>
<span class="source-line-no">048</span><span id="line-48">import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder;</span>
<span class="source-line-no">049</span><span id="line-49">import org.apache.hadoop.hbase.client.Connection;</span>
<span class="source-line-no">050</span><span id="line-50">import org.apache.hadoop.hbase.client.ConnectionFactory;</span>
<span class="source-line-no">051</span><span id="line-51">import org.apache.hadoop.hbase.client.Delete;</span>
<span class="source-line-no">052</span><span id="line-52">import org.apache.hadoop.hbase.client.Put;</span>
<span class="source-line-no">053</span><span id="line-53">import org.apache.hadoop.hbase.client.RegionInfo;</span>
<span class="source-line-no">054</span><span id="line-54">import org.apache.hadoop.hbase.client.RegionLocator;</span>
<span class="source-line-no">055</span><span id="line-55">import org.apache.hadoop.hbase.client.Scan;</span>
<span class="source-line-no">056</span><span id="line-56">import org.apache.hadoop.hbase.client.Table;</span>
<span class="source-line-no">057</span><span id="line-57">import org.apache.hadoop.hbase.client.TableDescriptor;</span>
<span class="source-line-no">058</span><span id="line-58">import org.apache.hadoop.hbase.client.TableDescriptorBuilder;</span>
<span class="source-line-no">059</span><span id="line-59">import org.apache.hadoop.hbase.coprocessor.MasterCoprocessor;</span>
<span class="source-line-no">060</span><span id="line-60">import org.apache.hadoop.hbase.coprocessor.MasterCoprocessorEnvironment;</span>
<span class="source-line-no">061</span><span id="line-61">import org.apache.hadoop.hbase.coprocessor.MasterObserver;</span>
<span class="source-line-no">062</span><span id="line-62">import org.apache.hadoop.hbase.coprocessor.ObserverContext;</span>
<span class="source-line-no">063</span><span id="line-63">import org.apache.hadoop.hbase.master.assignment.AssignmentManager;</span>
<span class="source-line-no">064</span><span id="line-64">import org.apache.hadoop.hbase.master.assignment.RegionStates;</span>
<span class="source-line-no">065</span><span id="line-65">import org.apache.hadoop.hbase.mob.MobFileName;</span>
<span class="source-line-no">066</span><span id="line-66">import org.apache.hadoop.hbase.mob.MobUtils;</span>
<span class="source-line-no">067</span><span id="line-67">import org.apache.hadoop.hbase.regionserver.HRegionFileSystem;</span>
<span class="source-line-no">068</span><span id="line-68">import org.apache.hadoop.hbase.util.hbck.HFileCorruptionChecker;</span>
<span class="source-line-no">069</span><span id="line-69">import org.junit.rules.TestName;</span>
<span class="source-line-no">070</span><span id="line-70">import org.slf4j.Logger;</span>
<span class="source-line-no">071</span><span id="line-71">import org.slf4j.LoggerFactory;</span>
<span class="source-line-no">072</span><span id="line-72"></span>
<span class="source-line-no">073</span><span id="line-73">/**</span>
<span class="source-line-no">074</span><span id="line-74"> * This is the base class for HBaseFsck's ability to detect reasons for inconsistent tables. Actual</span>
<span class="source-line-no">075</span><span id="line-75"> * tests are in : TestHBaseFsckTwoRS TestHBaseFsckOneRS TestHBaseFsckMOB TestHBaseFsckReplicas</span>
<span class="source-line-no">076</span><span id="line-76"> */</span>
<span class="source-line-no">077</span><span id="line-77">public class BaseTestHBaseFsck {</span>
<span class="source-line-no">078</span><span id="line-78"> static final int POOL_SIZE = 7;</span>
<span class="source-line-no">079</span><span id="line-79"> protected static final Logger LOG = LoggerFactory.getLogger(BaseTestHBaseFsck.class);</span>
<span class="source-line-no">080</span><span id="line-80"> protected final static HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil();</span>
<span class="source-line-no">081</span><span id="line-81"> protected final static Configuration conf = TEST_UTIL.getConfiguration();</span>
<span class="source-line-no">082</span><span id="line-82"> protected final static String FAM_STR = "fam";</span>
<span class="source-line-no">083</span><span id="line-83"> protected final static byte[] FAM = Bytes.toBytes(FAM_STR);</span>
<span class="source-line-no">084</span><span id="line-84"> protected final static int REGION_ONLINE_TIMEOUT = 800;</span>
<span class="source-line-no">085</span><span id="line-85"> protected static AssignmentManager assignmentManager;</span>
<span class="source-line-no">086</span><span id="line-86"> protected static RegionStates regionStates;</span>
<span class="source-line-no">087</span><span id="line-87"> protected static ExecutorService tableExecutorService;</span>
<span class="source-line-no">088</span><span id="line-88"> protected static ScheduledThreadPoolExecutor hbfsckExecutorService;</span>
<span class="source-line-no">089</span><span id="line-89"> protected static Connection connection;</span>
<span class="source-line-no">090</span><span id="line-90"> protected static Admin admin;</span>
<span class="source-line-no">091</span><span id="line-91"></span>
<span class="source-line-no">092</span><span id="line-92"> // for the instance, reset every test run</span>
<span class="source-line-no">093</span><span id="line-93"> protected Table tbl;</span>
<span class="source-line-no">094</span><span id="line-94"> protected final static byte[][] SPLITS =</span>
<span class="source-line-no">095</span><span id="line-95"> new byte[][] { Bytes.toBytes("A"), Bytes.toBytes("B"), Bytes.toBytes("C") };</span>
<span class="source-line-no">096</span><span id="line-96"> // one row per region.</span>
<span class="source-line-no">097</span><span id="line-97"> protected final static byte[][] ROWKEYS = new byte[][] { Bytes.toBytes("00"), Bytes.toBytes("50"),</span>
<span class="source-line-no">098</span><span id="line-98"> Bytes.toBytes("A0"), Bytes.toBytes("A5"), Bytes.toBytes("B0"), Bytes.toBytes("B5"),</span>
<span class="source-line-no">099</span><span id="line-99"> Bytes.toBytes("C0"), Bytes.toBytes("C5") };</span>
<span class="source-line-no">100</span><span id="line-100"></span>
<span class="source-line-no">101</span><span id="line-101"> /**</span>
<span class="source-line-no">102</span><span id="line-102"> * Debugging method to dump the contents of meta.</span>
<span class="source-line-no">103</span><span id="line-103"> */</span>
<span class="source-line-no">104</span><span id="line-104"> protected void dumpMeta(TableName tableName) throws IOException {</span>
<span class="source-line-no">105</span><span id="line-105"> List&lt;RegionInfo&gt; regions =</span>
<span class="source-line-no">106</span><span id="line-106"> MetaTableAccessor.getTableRegions(TEST_UTIL.getConnection(), tableName);</span>
<span class="source-line-no">107</span><span id="line-107"> for (RegionInfo region : regions) {</span>
<span class="source-line-no">108</span><span id="line-108"> LOG.info(region.getRegionNameAsString());</span>
<span class="source-line-no">109</span><span id="line-109"> }</span>
<span class="source-line-no">110</span><span id="line-110"> }</span>
<span class="source-line-no">111</span><span id="line-111"></span>
<span class="source-line-no">112</span><span id="line-112"> /**</span>
<span class="source-line-no">113</span><span id="line-113"> * This method is used to undeploy a region -- close it and attempt to remove its state from the</span>
<span class="source-line-no">114</span><span id="line-114"> * Master.</span>
<span class="source-line-no">115</span><span id="line-115"> */</span>
<span class="source-line-no">116</span><span id="line-116"> protected void undeployRegion(Connection conn, ServerName sn, RegionInfo hri)</span>
<span class="source-line-no">117</span><span id="line-117"> throws IOException, InterruptedException {</span>
<span class="source-line-no">118</span><span id="line-118"> try {</span>
<span class="source-line-no">119</span><span id="line-119"> HBaseFsckRepair.closeRegionSilentlyAndWait(conn, sn, hri);</span>
<span class="source-line-no">120</span><span id="line-120"> if (!hri.isMetaRegion()) {</span>
<span class="source-line-no">121</span><span id="line-121"> admin.offline(hri.getRegionName());</span>
<span class="source-line-no">122</span><span id="line-122"> }</span>
<span class="source-line-no">123</span><span id="line-123"> } catch (IOException ioe) {</span>
<span class="source-line-no">124</span><span id="line-124"> LOG.warn(</span>
<span class="source-line-no">125</span><span id="line-125"> "Got exception when attempting to offline region " + Bytes.toString(hri.getRegionName()),</span>
<span class="source-line-no">126</span><span id="line-126"> ioe);</span>
<span class="source-line-no">127</span><span id="line-127"> }</span>
<span class="source-line-no">128</span><span id="line-128"> }</span>
<span class="source-line-no">129</span><span id="line-129"></span>
<span class="source-line-no">130</span><span id="line-130"> /**</span>
<span class="source-line-no">131</span><span id="line-131"> * Delete a region from assignments, meta, or completely from hdfs.</span>
<span class="source-line-no">132</span><span id="line-132"> * @param unassign if true unassign region if assigned</span>
<span class="source-line-no">133</span><span id="line-133"> * @param metaRow if true remove region's row from META</span>
<span class="source-line-no">134</span><span id="line-134"> * @param hdfs if true remove region's dir in HDFS</span>
<span class="source-line-no">135</span><span id="line-135"> */</span>
<span class="source-line-no">136</span><span id="line-136"> protected void deleteRegion(Configuration conf, final TableDescriptor htd, byte[] startKey,</span>
<span class="source-line-no">137</span><span id="line-137"> byte[] endKey, boolean unassign, boolean metaRow, boolean hdfs)</span>
<span class="source-line-no">138</span><span id="line-138"> throws IOException, InterruptedException {</span>
<span class="source-line-no">139</span><span id="line-139"> deleteRegion(conf, htd, startKey, endKey, unassign, metaRow, hdfs, false,</span>
<span class="source-line-no">140</span><span id="line-140"> RegionInfo.DEFAULT_REPLICA_ID);</span>
<span class="source-line-no">141</span><span id="line-141"> }</span>
<span class="source-line-no">142</span><span id="line-142"></span>
<span class="source-line-no">143</span><span id="line-143"> /**</span>
<span class="source-line-no">144</span><span id="line-144"> * Delete a region from assignments, meta, or completely from hdfs.</span>
<span class="source-line-no">145</span><span id="line-145"> * @param unassign if true unassign region if assigned</span>
<span class="source-line-no">146</span><span id="line-146"> * @param metaRow if true remove region's row from META</span>
<span class="source-line-no">147</span><span id="line-147"> * @param hdfs if true remove region's dir in HDFS</span>
<span class="source-line-no">148</span><span id="line-148"> * @param regionInfoOnly if true remove a region dir's .regioninfo file</span>
<span class="source-line-no">149</span><span id="line-149"> * @param replicaId replica id</span>
<span class="source-line-no">150</span><span id="line-150"> */</span>
<span class="source-line-no">151</span><span id="line-151"> protected void deleteRegion(Configuration conf, final TableDescriptor htd, byte[] startKey,</span>
<span class="source-line-no">152</span><span id="line-152"> byte[] endKey, boolean unassign, boolean metaRow, boolean hdfs, boolean regionInfoOnly,</span>
<span class="source-line-no">153</span><span id="line-153"> int replicaId) throws IOException, InterruptedException {</span>
<span class="source-line-no">154</span><span id="line-154"> LOG.info("** Before delete:");</span>
<span class="source-line-no">155</span><span id="line-155"> dumpMeta(htd.getTableName());</span>
<span class="source-line-no">156</span><span id="line-156"></span>
<span class="source-line-no">157</span><span id="line-157"> List&lt;HRegionLocation&gt; locations;</span>
<span class="source-line-no">158</span><span id="line-158"> try (RegionLocator rl = connection.getRegionLocator(tbl.getName())) {</span>
<span class="source-line-no">159</span><span id="line-159"> locations = rl.getAllRegionLocations();</span>
<span class="source-line-no">160</span><span id="line-160"> }</span>
<span class="source-line-no">161</span><span id="line-161"></span>
<span class="source-line-no">162</span><span id="line-162"> for (HRegionLocation location : locations) {</span>
<span class="source-line-no">163</span><span id="line-163"> RegionInfo hri = location.getRegion();</span>
<span class="source-line-no">164</span><span id="line-164"> ServerName hsa = location.getServerName();</span>
<span class="source-line-no">165</span><span id="line-165"> if (</span>
<span class="source-line-no">166</span><span id="line-166"> Bytes.compareTo(hri.getStartKey(), startKey) == 0</span>
<span class="source-line-no">167</span><span id="line-167"> &amp;&amp; Bytes.compareTo(hri.getEndKey(), endKey) == 0 &amp;&amp; hri.getReplicaId() == replicaId</span>
<span class="source-line-no">168</span><span id="line-168"> ) {</span>
<span class="source-line-no">169</span><span id="line-169"></span>
<span class="source-line-no">170</span><span id="line-170"> LOG.info("RegionName: " + hri.getRegionNameAsString());</span>
<span class="source-line-no">171</span><span id="line-171"> byte[] deleteRow = hri.getRegionName();</span>
<span class="source-line-no">172</span><span id="line-172"></span>
<span class="source-line-no">173</span><span id="line-173"> if (unassign) {</span>
<span class="source-line-no">174</span><span id="line-174"> LOG.info("Undeploying region " + hri + " from server " + hsa);</span>
<span class="source-line-no">175</span><span id="line-175"> undeployRegion(connection, hsa, hri);</span>
<span class="source-line-no">176</span><span id="line-176"> }</span>
<span class="source-line-no">177</span><span id="line-177"></span>
<span class="source-line-no">178</span><span id="line-178"> if (regionInfoOnly) {</span>
<span class="source-line-no">179</span><span id="line-179"> LOG.info("deleting hdfs .regioninfo data: " + hri.toString() + hsa.toString());</span>
<span class="source-line-no">180</span><span id="line-180"> Path rootDir = CommonFSUtils.getRootDir(conf);</span>
<span class="source-line-no">181</span><span id="line-181"> FileSystem fs = rootDir.getFileSystem(conf);</span>
<span class="source-line-no">182</span><span id="line-182"> Path p =</span>
<span class="source-line-no">183</span><span id="line-183"> new Path(CommonFSUtils.getTableDir(rootDir, htd.getTableName()), hri.getEncodedName());</span>
<span class="source-line-no">184</span><span id="line-184"> Path hriPath = new Path(p, HRegionFileSystem.REGION_INFO_FILE);</span>
<span class="source-line-no">185</span><span id="line-185"> fs.delete(hriPath, true);</span>
<span class="source-line-no">186</span><span id="line-186"> }</span>
<span class="source-line-no">187</span><span id="line-187"></span>
<span class="source-line-no">188</span><span id="line-188"> if (hdfs) {</span>
<span class="source-line-no">189</span><span id="line-189"> LOG.info("deleting hdfs data: " + hri.toString() + hsa.toString());</span>
<span class="source-line-no">190</span><span id="line-190"> Path rootDir = CommonFSUtils.getRootDir(conf);</span>
<span class="source-line-no">191</span><span id="line-191"> FileSystem fs = rootDir.getFileSystem(conf);</span>
<span class="source-line-no">192</span><span id="line-192"> Path p =</span>
<span class="source-line-no">193</span><span id="line-193"> new Path(CommonFSUtils.getTableDir(rootDir, htd.getTableName()), hri.getEncodedName());</span>
<span class="source-line-no">194</span><span id="line-194"> HBaseFsck.debugLsr(conf, p);</span>
<span class="source-line-no">195</span><span id="line-195"> boolean success = fs.delete(p, true);</span>
<span class="source-line-no">196</span><span id="line-196"> LOG.info("Deleted " + p + " sucessfully? " + success);</span>
<span class="source-line-no">197</span><span id="line-197"> HBaseFsck.debugLsr(conf, p);</span>
<span class="source-line-no">198</span><span id="line-198"> }</span>
<span class="source-line-no">199</span><span id="line-199"></span>
<span class="source-line-no">200</span><span id="line-200"> if (metaRow) {</span>
<span class="source-line-no">201</span><span id="line-201"> try (Table meta = connection.getTable(TableName.META_TABLE_NAME, tableExecutorService)) {</span>
<span class="source-line-no">202</span><span id="line-202"> Delete delete = new Delete(deleteRow);</span>
<span class="source-line-no">203</span><span id="line-203"> meta.delete(delete);</span>
<span class="source-line-no">204</span><span id="line-204"> }</span>
<span class="source-line-no">205</span><span id="line-205"> }</span>
<span class="source-line-no">206</span><span id="line-206"> }</span>
<span class="source-line-no">207</span><span id="line-207"> LOG.info(hri.toString() + hsa.toString());</span>
<span class="source-line-no">208</span><span id="line-208"> }</span>
<span class="source-line-no">209</span><span id="line-209"></span>
<span class="source-line-no">210</span><span id="line-210"> LOG.info("*** After delete:");</span>
<span class="source-line-no">211</span><span id="line-211"> dumpMeta(htd.getTableName());</span>
<span class="source-line-no">212</span><span id="line-212"> }</span>
<span class="source-line-no">213</span><span id="line-213"></span>
<span class="source-line-no">214</span><span id="line-214"> /**</span>
<span class="source-line-no">215</span><span id="line-215"> * Setup a clean table before we start mucking with it. It will set tbl which needs to be closed</span>
<span class="source-line-no">216</span><span id="line-216"> * after test</span>
<span class="source-line-no">217</span><span id="line-217"> */</span>
<span class="source-line-no">218</span><span id="line-218"> void setupTable(TableName tablename) throws Exception {</span>
<span class="source-line-no">219</span><span id="line-219"> setupTableWithRegionReplica(tablename, 1);</span>
<span class="source-line-no">220</span><span id="line-220"> }</span>
<span class="source-line-no">221</span><span id="line-221"></span>
<span class="source-line-no">222</span><span id="line-222"> /**</span>
<span class="source-line-no">223</span><span id="line-223"> * Setup a clean table with a certain region_replica count It will set tbl which needs to be</span>
<span class="source-line-no">224</span><span id="line-224"> * closed after test</span>
<span class="source-line-no">225</span><span id="line-225"> */</span>
<span class="source-line-no">226</span><span id="line-226"> void setupTableWithRegionReplica(TableName tablename, int replicaCount) throws Exception {</span>
<span class="source-line-no">227</span><span id="line-227"> TableDescriptorBuilder tableDescriptorBuilder = TableDescriptorBuilder.newBuilder(tablename);</span>
<span class="source-line-no">228</span><span id="line-228"> ColumnFamilyDescriptor columnFamilyDescriptor =</span>
<span class="source-line-no">229</span><span id="line-229"> ColumnFamilyDescriptorBuilder.newBuilder(FAM).build();</span>
<span class="source-line-no">230</span><span id="line-230"> tableDescriptorBuilder.setRegionReplication(replicaCount);</span>
<span class="source-line-no">231</span><span id="line-231"> // If a table has no CF's it doesn't get checked</span>
<span class="source-line-no">232</span><span id="line-232"> tableDescriptorBuilder.setColumnFamily(columnFamilyDescriptor);</span>
<span class="source-line-no">233</span><span id="line-233"> createTable(TEST_UTIL, tableDescriptorBuilder.build(), SPLITS);</span>
<span class="source-line-no">234</span><span id="line-234"></span>
<span class="source-line-no">235</span><span id="line-235"> tbl = connection.getTable(tablename, tableExecutorService);</span>
<span class="source-line-no">236</span><span id="line-236"> List&lt;Put&gt; puts = new ArrayList&lt;&gt;(ROWKEYS.length);</span>
<span class="source-line-no">237</span><span id="line-237"> for (byte[] row : ROWKEYS) {</span>
<span class="source-line-no">238</span><span id="line-238"> Put p = new Put(row);</span>
<span class="source-line-no">239</span><span id="line-239"> p.addColumn(FAM, Bytes.toBytes("val"), row);</span>
<span class="source-line-no">240</span><span id="line-240"> puts.add(p);</span>
<span class="source-line-no">241</span><span id="line-241"> }</span>
<span class="source-line-no">242</span><span id="line-242"> tbl.put(puts);</span>
<span class="source-line-no">243</span><span id="line-243"> }</span>
<span class="source-line-no">244</span><span id="line-244"></span>
<span class="source-line-no">245</span><span id="line-245"> /**</span>
<span class="source-line-no">246</span><span id="line-246"> * Setup a clean table with a mob-enabled column.</span>
<span class="source-line-no">247</span><span id="line-247"> * @param tablename The name of a table to be created.</span>
<span class="source-line-no">248</span><span id="line-248"> */</span>
<span class="source-line-no">249</span><span id="line-249"> void setupMobTable(TableName tablename) throws Exception {</span>
<span class="source-line-no">250</span><span id="line-250"> TableDescriptorBuilder tableDescriptorBuilder = TableDescriptorBuilder.newBuilder(tablename);</span>
<span class="source-line-no">251</span><span id="line-251"> ColumnFamilyDescriptor columnFamilyDescriptor =</span>
<span class="source-line-no">252</span><span id="line-252"> ColumnFamilyDescriptorBuilder.newBuilder(FAM).setMobEnabled(true).setMobThreshold(0).build();</span>
<span class="source-line-no">253</span><span id="line-253"> // If a table has no CF's it doesn't get checked</span>
<span class="source-line-no">254</span><span id="line-254"> tableDescriptorBuilder.setColumnFamily(columnFamilyDescriptor);</span>
<span class="source-line-no">255</span><span id="line-255"> createTable(TEST_UTIL, tableDescriptorBuilder.build(), SPLITS);</span>
<span class="source-line-no">256</span><span id="line-256"></span>
<span class="source-line-no">257</span><span id="line-257"> tbl = connection.getTable(tablename, tableExecutorService);</span>
<span class="source-line-no">258</span><span id="line-258"> List&lt;Put&gt; puts = new ArrayList&lt;&gt;(ROWKEYS.length);</span>
<span class="source-line-no">259</span><span id="line-259"> for (byte[] row : ROWKEYS) {</span>
<span class="source-line-no">260</span><span id="line-260"> Put p = new Put(row);</span>
<span class="source-line-no">261</span><span id="line-261"> p.addColumn(FAM, Bytes.toBytes("val"), row);</span>
<span class="source-line-no">262</span><span id="line-262"> puts.add(p);</span>
<span class="source-line-no">263</span><span id="line-263"> }</span>
<span class="source-line-no">264</span><span id="line-264"> tbl.put(puts);</span>
<span class="source-line-no">265</span><span id="line-265"> }</span>
<span class="source-line-no">266</span><span id="line-266"></span>
<span class="source-line-no">267</span><span id="line-267"> /**</span>
<span class="source-line-no">268</span><span id="line-268"> * Counts the number of rows to verify data loss or non-dataloss.</span>
<span class="source-line-no">269</span><span id="line-269"> */</span>
<span class="source-line-no">270</span><span id="line-270"> int countRows() throws IOException {</span>
<span class="source-line-no">271</span><span id="line-271"> return TEST_UTIL.countRows(tbl);</span>
<span class="source-line-no">272</span><span id="line-272"> }</span>
<span class="source-line-no">273</span><span id="line-273"></span>
<span class="source-line-no">274</span><span id="line-274"> /**</span>
<span class="source-line-no">275</span><span id="line-275"> * Counts the number of rows to verify data loss or non-dataloss.</span>
<span class="source-line-no">276</span><span id="line-276"> */</span>
<span class="source-line-no">277</span><span id="line-277"> int countRows(byte[] start, byte[] end) throws IOException {</span>
<span class="source-line-no">278</span><span id="line-278"> return TEST_UTIL.countRows(tbl, new Scan().withStartRow(start).withStopRow(end));</span>
<span class="source-line-no">279</span><span id="line-279"> }</span>
<span class="source-line-no">280</span><span id="line-280"></span>
<span class="source-line-no">281</span><span id="line-281"> /**</span>
<span class="source-line-no">282</span><span id="line-282"> * delete table in preparation for next test</span>
<span class="source-line-no">283</span><span id="line-283"> */</span>
<span class="source-line-no">284</span><span id="line-284"> void cleanupTable(TableName tablename) throws Exception {</span>
<span class="source-line-no">285</span><span id="line-285"> if (tbl != null) {</span>
<span class="source-line-no">286</span><span id="line-286"> tbl.close();</span>
<span class="source-line-no">287</span><span id="line-287"> tbl = null;</span>
<span class="source-line-no">288</span><span id="line-288"> }</span>
<span class="source-line-no">289</span><span id="line-289"> connection.clearRegionLocationCache();</span>
<span class="source-line-no">290</span><span id="line-290"> deleteTable(TEST_UTIL, tablename);</span>
<span class="source-line-no">291</span><span id="line-291"> }</span>
<span class="source-line-no">292</span><span id="line-292"></span>
<span class="source-line-no">293</span><span id="line-293"> /**</span>
<span class="source-line-no">294</span><span id="line-294"> * Get region info from local cluster.</span>
<span class="source-line-no">295</span><span id="line-295"> */</span>
<span class="source-line-no">296</span><span id="line-296"> Map&lt;ServerName, List&lt;String&gt;&gt; getDeployedHRIs(final Admin admin) throws IOException {</span>
<span class="source-line-no">297</span><span id="line-297"> ClusterMetrics status = admin.getClusterMetrics(EnumSet.of(Option.LIVE_SERVERS));</span>
<span class="source-line-no">298</span><span id="line-298"> Collection&lt;ServerName&gt; regionServers = status.getLiveServerMetrics().keySet();</span>
<span class="source-line-no">299</span><span id="line-299"> Map&lt;ServerName, List&lt;String&gt;&gt; mm = new HashMap&lt;&gt;();</span>
<span class="source-line-no">300</span><span id="line-300"> for (ServerName hsi : regionServers) {</span>
<span class="source-line-no">301</span><span id="line-301"> // list all online regions from this region server</span>
<span class="source-line-no">302</span><span id="line-302"> List&lt;RegionInfo&gt; regions = admin.getRegions(hsi);</span>
<span class="source-line-no">303</span><span id="line-303"> List&lt;String&gt; regionNames = new ArrayList&lt;&gt;(regions.size());</span>
<span class="source-line-no">304</span><span id="line-304"> for (RegionInfo hri : regions) {</span>
<span class="source-line-no">305</span><span id="line-305"> regionNames.add(hri.getRegionNameAsString());</span>
<span class="source-line-no">306</span><span id="line-306"> }</span>
<span class="source-line-no">307</span><span id="line-307"> mm.put(hsi, regionNames);</span>
<span class="source-line-no">308</span><span id="line-308"> }</span>
<span class="source-line-no">309</span><span id="line-309"> return mm;</span>
<span class="source-line-no">310</span><span id="line-310"> }</span>
<span class="source-line-no">311</span><span id="line-311"></span>
<span class="source-line-no">312</span><span id="line-312"> /**</span>
<span class="source-line-no">313</span><span id="line-313"> * Returns the HSI a region info is on.</span>
<span class="source-line-no">314</span><span id="line-314"> */</span>
<span class="source-line-no">315</span><span id="line-315"> ServerName findDeployedHSI(Map&lt;ServerName, List&lt;String&gt;&gt; mm, RegionInfo hri) {</span>
<span class="source-line-no">316</span><span id="line-316"> for (Map.Entry&lt;ServerName, List&lt;String&gt;&gt; e : mm.entrySet()) {</span>
<span class="source-line-no">317</span><span id="line-317"> if (e.getValue().contains(hri.getRegionNameAsString())) {</span>
<span class="source-line-no">318</span><span id="line-318"> return e.getKey();</span>
<span class="source-line-no">319</span><span id="line-319"> }</span>
<span class="source-line-no">320</span><span id="line-320"> }</span>
<span class="source-line-no">321</span><span id="line-321"> return null;</span>
<span class="source-line-no">322</span><span id="line-322"> }</span>
<span class="source-line-no">323</span><span id="line-323"></span>
<span class="source-line-no">324</span><span id="line-324"> public void deleteTableDir(TableName table) throws IOException {</span>
<span class="source-line-no">325</span><span id="line-325"> Path rootDir = CommonFSUtils.getRootDir(conf);</span>
<span class="source-line-no">326</span><span id="line-326"> FileSystem fs = rootDir.getFileSystem(conf);</span>
<span class="source-line-no">327</span><span id="line-327"> Path p = CommonFSUtils.getTableDir(rootDir, table);</span>
<span class="source-line-no">328</span><span id="line-328"> HBaseFsck.debugLsr(conf, p);</span>
<span class="source-line-no">329</span><span id="line-329"> boolean success = fs.delete(p, true);</span>
<span class="source-line-no">330</span><span id="line-330"> LOG.info("Deleted " + p + " sucessfully? " + success);</span>
<span class="source-line-no">331</span><span id="line-331"> }</span>
<span class="source-line-no">332</span><span id="line-332"></span>
<span class="source-line-no">333</span><span id="line-333"> /**</span>
<span class="source-line-no">334</span><span id="line-334"> * We don't have an easy way to verify that a flush completed, so we loop until we find a</span>
<span class="source-line-no">335</span><span id="line-335"> * legitimate hfile and return it.</span>
<span class="source-line-no">336</span><span id="line-336"> * @return Path of a flushed hfile.</span>
<span class="source-line-no">337</span><span id="line-337"> */</span>
<span class="source-line-no">338</span><span id="line-338"> Path getFlushedHFile(FileSystem fs, TableName table) throws IOException {</span>
<span class="source-line-no">339</span><span id="line-339"> Path tableDir = CommonFSUtils.getTableDir(CommonFSUtils.getRootDir(conf), table);</span>
<span class="source-line-no">340</span><span id="line-340"> Path regionDir = FSUtils.getRegionDirs(fs, tableDir).get(0);</span>
<span class="source-line-no">341</span><span id="line-341"> Path famDir = new Path(regionDir, FAM_STR);</span>
<span class="source-line-no">342</span><span id="line-342"></span>
<span class="source-line-no">343</span><span id="line-343"> // keep doing this until we get a legit hfile</span>
<span class="source-line-no">344</span><span id="line-344"> while (true) {</span>
<span class="source-line-no">345</span><span id="line-345"> FileStatus[] hfFss = fs.listStatus(famDir);</span>
<span class="source-line-no">346</span><span id="line-346"> if (hfFss.length == 0) {</span>
<span class="source-line-no">347</span><span id="line-347"> continue;</span>
<span class="source-line-no">348</span><span id="line-348"> }</span>
<span class="source-line-no">349</span><span id="line-349"> for (FileStatus hfs : hfFss) {</span>
<span class="source-line-no">350</span><span id="line-350"> if (!hfs.isDirectory()) {</span>
<span class="source-line-no">351</span><span id="line-351"> return hfs.getPath();</span>
<span class="source-line-no">352</span><span id="line-352"> }</span>
<span class="source-line-no">353</span><span id="line-353"> }</span>
<span class="source-line-no">354</span><span id="line-354"> }</span>
<span class="source-line-no">355</span><span id="line-355"> }</span>
<span class="source-line-no">356</span><span id="line-356"></span>
<span class="source-line-no">357</span><span id="line-357"> /**</span>
<span class="source-line-no">358</span><span id="line-358"> * Gets flushed mob files.</span>
<span class="source-line-no">359</span><span id="line-359"> * @param fs The current file system.</span>
<span class="source-line-no">360</span><span id="line-360"> * @param table The current table name.</span>
<span class="source-line-no">361</span><span id="line-361"> * @return Path of a flushed hfile.</span>
<span class="source-line-no">362</span><span id="line-362"> */</span>
<span class="source-line-no">363</span><span id="line-363"> Path getFlushedMobFile(FileSystem fs, TableName table) throws IOException {</span>
<span class="source-line-no">364</span><span id="line-364"> Path famDir = MobUtils.getMobFamilyPath(conf, table, FAM_STR);</span>
<span class="source-line-no">365</span><span id="line-365"></span>
<span class="source-line-no">366</span><span id="line-366"> // keep doing this until we get a legit hfile</span>
<span class="source-line-no">367</span><span id="line-367"> while (true) {</span>
<span class="source-line-no">368</span><span id="line-368"> FileStatus[] hfFss = fs.listStatus(famDir);</span>
<span class="source-line-no">369</span><span id="line-369"> if (hfFss.length == 0) {</span>
<span class="source-line-no">370</span><span id="line-370"> continue;</span>
<span class="source-line-no">371</span><span id="line-371"> }</span>
<span class="source-line-no">372</span><span id="line-372"> for (FileStatus hfs : hfFss) {</span>
<span class="source-line-no">373</span><span id="line-373"> if (!hfs.isDirectory()) {</span>
<span class="source-line-no">374</span><span id="line-374"> return hfs.getPath();</span>
<span class="source-line-no">375</span><span id="line-375"> }</span>
<span class="source-line-no">376</span><span id="line-376"> }</span>
<span class="source-line-no">377</span><span id="line-377"> }</span>
<span class="source-line-no">378</span><span id="line-378"> }</span>
<span class="source-line-no">379</span><span id="line-379"></span>
<span class="source-line-no">380</span><span id="line-380"> /**</span>
<span class="source-line-no">381</span><span id="line-381"> * Creates a new mob file name by the old one.</span>
<span class="source-line-no">382</span><span id="line-382"> * @param oldFileName The old mob file name.</span>
<span class="source-line-no">383</span><span id="line-383"> * @return The new mob file name.</span>
<span class="source-line-no">384</span><span id="line-384"> */</span>
<span class="source-line-no">385</span><span id="line-385"> String createMobFileName(String oldFileName) {</span>
<span class="source-line-no">386</span><span id="line-386"> MobFileName mobFileName = MobFileName.create(oldFileName);</span>
<span class="source-line-no">387</span><span id="line-387"> String startKey = mobFileName.getStartKey();</span>
<span class="source-line-no">388</span><span id="line-388"> String date = mobFileName.getDate();</span>
<span class="source-line-no">389</span><span id="line-389"> return MobFileName</span>
<span class="source-line-no">390</span><span id="line-390"> .create(startKey, date, TEST_UTIL.getRandomUUID().toString().replaceAll("-", ""), "abcdef")</span>
<span class="source-line-no">391</span><span id="line-391"> .getFileName();</span>
<span class="source-line-no">392</span><span id="line-392"> }</span>
<span class="source-line-no">393</span><span id="line-393"></span>
<span class="source-line-no">394</span><span id="line-394"> /**</span>
<span class="source-line-no">395</span><span id="line-395"> * Test that use this should have a timeout, because this method could potentially wait forever.</span>
<span class="source-line-no">396</span><span id="line-396"> */</span>
<span class="source-line-no">397</span><span id="line-397"> protected void doQuarantineTest(TableName table, HBaseFsck hbck, int check, int corrupt, int fail,</span>
<span class="source-line-no">398</span><span id="line-398"> int quar, int missing) throws Exception {</span>
<span class="source-line-no">399</span><span id="line-399"> try {</span>
<span class="source-line-no">400</span><span id="line-400"> setupTable(table);</span>
<span class="source-line-no">401</span><span id="line-401"> assertEquals(ROWKEYS.length, countRows());</span>
<span class="source-line-no">402</span><span id="line-402"> admin.flush(table); // flush is async.</span>
<span class="source-line-no">403</span><span id="line-403"></span>
<span class="source-line-no">404</span><span id="line-404"> // Mess it up by leaving a hole in the assignment, meta, and hdfs data</span>
<span class="source-line-no">405</span><span id="line-405"> admin.disableTable(table);</span>
<span class="source-line-no">406</span><span id="line-406"></span>
<span class="source-line-no">407</span><span id="line-407"> String[] args = { "-sidelineCorruptHFiles", "-repairHoles", "-ignorePreCheckPermission",</span>
<span class="source-line-no">408</span><span id="line-408"> table.getNameAsString() };</span>
<span class="source-line-no">409</span><span id="line-409"> HBaseFsck res = hbck.exec(hbfsckExecutorService, args);</span>
<span class="source-line-no">410</span><span id="line-410"></span>
<span class="source-line-no">411</span><span id="line-411"> HFileCorruptionChecker hfcc = res.getHFilecorruptionChecker();</span>
<span class="source-line-no">412</span><span id="line-412"> assertEquals(hfcc.getHFilesChecked(), check);</span>
<span class="source-line-no">413</span><span id="line-413"> assertEquals(hfcc.getCorrupted().size(), corrupt);</span>
<span class="source-line-no">414</span><span id="line-414"> assertEquals(hfcc.getFailures().size(), fail);</span>
<span class="source-line-no">415</span><span id="line-415"> assertEquals(hfcc.getQuarantined().size(), quar);</span>
<span class="source-line-no">416</span><span id="line-416"> assertEquals(hfcc.getMissing().size(), missing);</span>
<span class="source-line-no">417</span><span id="line-417"></span>
<span class="source-line-no">418</span><span id="line-418"> // its been fixed, verify that we can enable</span>
<span class="source-line-no">419</span><span id="line-419"> admin.enableTableAsync(table);</span>
<span class="source-line-no">420</span><span id="line-420"> while (!admin.isTableEnabled(table)) {</span>
<span class="source-line-no">421</span><span id="line-421"> try {</span>
<span class="source-line-no">422</span><span id="line-422"> Thread.sleep(250);</span>
<span class="source-line-no">423</span><span id="line-423"> } catch (InterruptedException e) {</span>
<span class="source-line-no">424</span><span id="line-424"> e.printStackTrace();</span>
<span class="source-line-no">425</span><span id="line-425"> fail("Interrupted when trying to enable table " + table);</span>
<span class="source-line-no">426</span><span id="line-426"> }</span>
<span class="source-line-no">427</span><span id="line-427"> }</span>
<span class="source-line-no">428</span><span id="line-428"> } finally {</span>
<span class="source-line-no">429</span><span id="line-429"> cleanupTable(table);</span>
<span class="source-line-no">430</span><span id="line-430"> }</span>
<span class="source-line-no">431</span><span id="line-431"> }</span>
<span class="source-line-no">432</span><span id="line-432"></span>
<span class="source-line-no">433</span><span id="line-433"> static class MockErrorReporter implements HbckErrorReporter {</span>
<span class="source-line-no">434</span><span id="line-434"> static int calledCount = 0;</span>
<span class="source-line-no">435</span><span id="line-435"></span>
<span class="source-line-no">436</span><span id="line-436"> @Override</span>
<span class="source-line-no">437</span><span id="line-437"> public void clear() {</span>
<span class="source-line-no">438</span><span id="line-438"> calledCount++;</span>
<span class="source-line-no">439</span><span id="line-439"> }</span>
<span class="source-line-no">440</span><span id="line-440"></span>
<span class="source-line-no">441</span><span id="line-441"> @Override</span>
<span class="source-line-no">442</span><span id="line-442"> public void report(String message) {</span>
<span class="source-line-no">443</span><span id="line-443"> calledCount++;</span>
<span class="source-line-no">444</span><span id="line-444"> }</span>
<span class="source-line-no">445</span><span id="line-445"></span>
<span class="source-line-no">446</span><span id="line-446"> @Override</span>
<span class="source-line-no">447</span><span id="line-447"> public void reportError(String message) {</span>
<span class="source-line-no">448</span><span id="line-448"> calledCount++;</span>
<span class="source-line-no">449</span><span id="line-449"> }</span>
<span class="source-line-no">450</span><span id="line-450"></span>
<span class="source-line-no">451</span><span id="line-451"> @Override</span>
<span class="source-line-no">452</span><span id="line-452"> public void reportError(ERROR_CODE errorCode, String message) {</span>
<span class="source-line-no">453</span><span id="line-453"> calledCount++;</span>
<span class="source-line-no">454</span><span id="line-454"> }</span>
<span class="source-line-no">455</span><span id="line-455"></span>
<span class="source-line-no">456</span><span id="line-456"> @Override</span>
<span class="source-line-no">457</span><span id="line-457"> public void reportError(ERROR_CODE errorCode, String message, HbckTableInfo table) {</span>
<span class="source-line-no">458</span><span id="line-458"> calledCount++;</span>
<span class="source-line-no">459</span><span id="line-459"> }</span>
<span class="source-line-no">460</span><span id="line-460"></span>
<span class="source-line-no">461</span><span id="line-461"> @Override</span>
<span class="source-line-no">462</span><span id="line-462"> public void reportError(ERROR_CODE errorCode, String message, HbckTableInfo table,</span>
<span class="source-line-no">463</span><span id="line-463"> HbckRegionInfo info) {</span>
<span class="source-line-no">464</span><span id="line-464"> calledCount++;</span>
<span class="source-line-no">465</span><span id="line-465"> }</span>
<span class="source-line-no">466</span><span id="line-466"></span>
<span class="source-line-no">467</span><span id="line-467"> @Override</span>
<span class="source-line-no">468</span><span id="line-468"> public void reportError(ERROR_CODE errorCode, String message, HbckTableInfo table,</span>
<span class="source-line-no">469</span><span id="line-469"> HbckRegionInfo info1, HbckRegionInfo info2) {</span>
<span class="source-line-no">470</span><span id="line-470"> calledCount++;</span>
<span class="source-line-no">471</span><span id="line-471"> }</span>
<span class="source-line-no">472</span><span id="line-472"></span>
<span class="source-line-no">473</span><span id="line-473"> @Override</span>
<span class="source-line-no">474</span><span id="line-474"> public int summarize() {</span>
<span class="source-line-no">475</span><span id="line-475"> return ++calledCount;</span>
<span class="source-line-no">476</span><span id="line-476"> }</span>
<span class="source-line-no">477</span><span id="line-477"></span>
<span class="source-line-no">478</span><span id="line-478"> @Override</span>
<span class="source-line-no">479</span><span id="line-479"> public void detail(String details) {</span>
<span class="source-line-no">480</span><span id="line-480"> calledCount++;</span>
<span class="source-line-no">481</span><span id="line-481"> }</span>
<span class="source-line-no">482</span><span id="line-482"></span>
<span class="source-line-no">483</span><span id="line-483"> @Override</span>
<span class="source-line-no">484</span><span id="line-484"> public ArrayList&lt;ERROR_CODE&gt; getErrorList() {</span>
<span class="source-line-no">485</span><span id="line-485"> calledCount++;</span>
<span class="source-line-no">486</span><span id="line-486"> return new ArrayList&lt;&gt;();</span>
<span class="source-line-no">487</span><span id="line-487"> }</span>
<span class="source-line-no">488</span><span id="line-488"></span>
<span class="source-line-no">489</span><span id="line-489"> @Override</span>
<span class="source-line-no">490</span><span id="line-490"> public void progress() {</span>
<span class="source-line-no">491</span><span id="line-491"> calledCount++;</span>
<span class="source-line-no">492</span><span id="line-492"> }</span>
<span class="source-line-no">493</span><span id="line-493"></span>
<span class="source-line-no">494</span><span id="line-494"> @Override</span>
<span class="source-line-no">495</span><span id="line-495"> public void print(String message) {</span>
<span class="source-line-no">496</span><span id="line-496"> calledCount++;</span>
<span class="source-line-no">497</span><span id="line-497"> }</span>
<span class="source-line-no">498</span><span id="line-498"></span>
<span class="source-line-no">499</span><span id="line-499"> @Override</span>
<span class="source-line-no">500</span><span id="line-500"> public void resetErrors() {</span>
<span class="source-line-no">501</span><span id="line-501"> calledCount++;</span>
<span class="source-line-no">502</span><span id="line-502"> }</span>
<span class="source-line-no">503</span><span id="line-503"></span>
<span class="source-line-no">504</span><span id="line-504"> @Override</span>
<span class="source-line-no">505</span><span id="line-505"> public boolean tableHasErrors(HbckTableInfo table) {</span>
<span class="source-line-no">506</span><span id="line-506"> calledCount++;</span>
<span class="source-line-no">507</span><span id="line-507"> return false;</span>
<span class="source-line-no">508</span><span id="line-508"> }</span>
<span class="source-line-no">509</span><span id="line-509"> }</span>
<span class="source-line-no">510</span><span id="line-510"></span>
<span class="source-line-no">511</span><span id="line-511"> protected void deleteMetaRegion(Configuration conf, boolean unassign, boolean hdfs,</span>
<span class="source-line-no">512</span><span id="line-512"> boolean regionInfoOnly) throws IOException, InterruptedException {</span>
<span class="source-line-no">513</span><span id="line-513"> HRegionLocation metaLocation = connection.getRegionLocator(TableName.META_TABLE_NAME)</span>
<span class="source-line-no">514</span><span id="line-514"> .getRegionLocation(HConstants.EMPTY_START_ROW);</span>
<span class="source-line-no">515</span><span id="line-515"> ServerName hsa = metaLocation.getServerName();</span>
<span class="source-line-no">516</span><span id="line-516"> RegionInfo hri = metaLocation.getRegion();</span>
<span class="source-line-no">517</span><span id="line-517"> if (unassign) {</span>
<span class="source-line-no">518</span><span id="line-518"> LOG.info("Undeploying meta region " + hri + " from server " + hsa);</span>
<span class="source-line-no">519</span><span id="line-519"> try (Connection unmanagedConnection = ConnectionFactory.createConnection(conf)) {</span>
<span class="source-line-no">520</span><span id="line-520"> undeployRegion(unmanagedConnection, hsa, hri);</span>
<span class="source-line-no">521</span><span id="line-521"> }</span>
<span class="source-line-no">522</span><span id="line-522"> }</span>
<span class="source-line-no">523</span><span id="line-523"></span>
<span class="source-line-no">524</span><span id="line-524"> if (regionInfoOnly) {</span>
<span class="source-line-no">525</span><span id="line-525"> LOG.info("deleting hdfs .regioninfo data: " + hri.toString() + hsa.toString());</span>
<span class="source-line-no">526</span><span id="line-526"> Path rootDir = CommonFSUtils.getRootDir(conf);</span>
<span class="source-line-no">527</span><span id="line-527"> FileSystem fs = rootDir.getFileSystem(conf);</span>
<span class="source-line-no">528</span><span id="line-528"> Path p =</span>
<span class="source-line-no">529</span><span id="line-529"> new Path(rootDir + "/" + TableName.META_TABLE_NAME.getNameAsString(), hri.getEncodedName());</span>
<span class="source-line-no">530</span><span id="line-530"> Path hriPath = new Path(p, HRegionFileSystem.REGION_INFO_FILE);</span>
<span class="source-line-no">531</span><span id="line-531"> fs.delete(hriPath, true);</span>
<span class="source-line-no">532</span><span id="line-532"> }</span>
<span class="source-line-no">533</span><span id="line-533"></span>
<span class="source-line-no">534</span><span id="line-534"> if (hdfs) {</span>
<span class="source-line-no">535</span><span id="line-535"> LOG.info("deleting hdfs data: " + hri.toString() + hsa.toString());</span>
<span class="source-line-no">536</span><span id="line-536"> Path rootDir = CommonFSUtils.getRootDir(conf);</span>
<span class="source-line-no">537</span><span id="line-537"> FileSystem fs = rootDir.getFileSystem(conf);</span>
<span class="source-line-no">538</span><span id="line-538"> Path p =</span>
<span class="source-line-no">539</span><span id="line-539"> new Path(rootDir + "/" + TableName.META_TABLE_NAME.getNameAsString(), hri.getEncodedName());</span>
<span class="source-line-no">540</span><span id="line-540"> HBaseFsck.debugLsr(conf, p);</span>
<span class="source-line-no">541</span><span id="line-541"> boolean success = fs.delete(p, true);</span>
<span class="source-line-no">542</span><span id="line-542"> LOG.info("Deleted " + p + " sucessfully? " + success);</span>
<span class="source-line-no">543</span><span id="line-543"> HBaseFsck.debugLsr(conf, p);</span>
<span class="source-line-no">544</span><span id="line-544"> }</span>
<span class="source-line-no">545</span><span id="line-545"> }</span>
<span class="source-line-no">546</span><span id="line-546"></span>
<span class="source-line-no">547</span><span id="line-547"> @org.junit.Rule</span>
<span class="source-line-no">548</span><span id="line-548"> public TestName name = new TestName();</span>
<span class="source-line-no">549</span><span id="line-549"></span>
<span class="source-line-no">550</span><span id="line-550"> public static class MasterSyncCoprocessor implements MasterCoprocessor, MasterObserver {</span>
<span class="source-line-no">551</span><span id="line-551"> volatile CountDownLatch tableCreationLatch = null;</span>
<span class="source-line-no">552</span><span id="line-552"> volatile CountDownLatch tableDeletionLatch = null;</span>
<span class="source-line-no">553</span><span id="line-553"></span>
<span class="source-line-no">554</span><span id="line-554"> @Override</span>
<span class="source-line-no">555</span><span id="line-555"> public Optional&lt;MasterObserver&gt; getMasterObserver() {</span>
<span class="source-line-no">556</span><span id="line-556"> return Optional.of(this);</span>
<span class="source-line-no">557</span><span id="line-557"> }</span>
<span class="source-line-no">558</span><span id="line-558"></span>
<span class="source-line-no">559</span><span id="line-559"> @Override</span>
<span class="source-line-no">560</span><span id="line-560"> public void postCompletedCreateTableAction(</span>
<span class="source-line-no">561</span><span id="line-561"> final ObserverContext&lt;MasterCoprocessorEnvironment&gt; ctx, final TableDescriptor desc,</span>
<span class="source-line-no">562</span><span id="line-562"> final RegionInfo[] regions) throws IOException {</span>
<span class="source-line-no">563</span><span id="line-563"> // the AccessController test, some times calls only and directly the</span>
<span class="source-line-no">564</span><span id="line-564"> // postCompletedCreateTableAction()</span>
<span class="source-line-no">565</span><span id="line-565"> if (tableCreationLatch != null) {</span>
<span class="source-line-no">566</span><span id="line-566"> tableCreationLatch.countDown();</span>
<span class="source-line-no">567</span><span id="line-567"> }</span>
<span class="source-line-no">568</span><span id="line-568"> }</span>
<span class="source-line-no">569</span><span id="line-569"></span>
<span class="source-line-no">570</span><span id="line-570"> @Override</span>
<span class="source-line-no">571</span><span id="line-571"> public void postCompletedDeleteTableAction(</span>
<span class="source-line-no">572</span><span id="line-572"> final ObserverContext&lt;MasterCoprocessorEnvironment&gt; ctx, final TableName tableName)</span>
<span class="source-line-no">573</span><span id="line-573"> throws IOException {</span>
<span class="source-line-no">574</span><span id="line-574"> // the AccessController test, some times calls only and directly the</span>
<span class="source-line-no">575</span><span id="line-575"> // postCompletedDeleteTableAction()</span>
<span class="source-line-no">576</span><span id="line-576"> if (tableDeletionLatch != null) {</span>
<span class="source-line-no">577</span><span id="line-577"> tableDeletionLatch.countDown();</span>
<span class="source-line-no">578</span><span id="line-578"> }</span>
<span class="source-line-no">579</span><span id="line-579"> }</span>
<span class="source-line-no">580</span><span id="line-580"> }</span>
<span class="source-line-no">581</span><span id="line-581"></span>
<span class="source-line-no">582</span><span id="line-582"> public static void createTable(HBaseTestingUtil testUtil, TableDescriptor tableDescriptor,</span>
<span class="source-line-no">583</span><span id="line-583"> byte[][] splitKeys) throws Exception {</span>
<span class="source-line-no">584</span><span id="line-584"> // NOTE: We need a latch because admin is not sync,</span>
<span class="source-line-no">585</span><span id="line-585"> // so the postOp coprocessor method may be called after the admin operation returned.</span>
<span class="source-line-no">586</span><span id="line-586"> MasterSyncCoprocessor coproc = testUtil.getHBaseCluster().getMaster().getMasterCoprocessorHost()</span>
<span class="source-line-no">587</span><span id="line-587"> .findCoprocessor(MasterSyncCoprocessor.class);</span>
<span class="source-line-no">588</span><span id="line-588"> coproc.tableCreationLatch = new CountDownLatch(1);</span>
<span class="source-line-no">589</span><span id="line-589"> if (splitKeys != null) {</span>
<span class="source-line-no">590</span><span id="line-590"> admin.createTable(tableDescriptor, splitKeys);</span>
<span class="source-line-no">591</span><span id="line-591"> } else {</span>
<span class="source-line-no">592</span><span id="line-592"> admin.createTable(tableDescriptor);</span>
<span class="source-line-no">593</span><span id="line-593"> }</span>
<span class="source-line-no">594</span><span id="line-594"> coproc.tableCreationLatch.await();</span>
<span class="source-line-no">595</span><span id="line-595"> coproc.tableCreationLatch = null;</span>
<span class="source-line-no">596</span><span id="line-596"> testUtil.waitUntilAllRegionsAssigned(tableDescriptor.getTableName());</span>
<span class="source-line-no">597</span><span id="line-597"> }</span>
<span class="source-line-no">598</span><span id="line-598"></span>
<span class="source-line-no">599</span><span id="line-599"> public static void deleteTable(HBaseTestingUtil testUtil, TableName tableName) throws Exception {</span>
<span class="source-line-no">600</span><span id="line-600"> // NOTE: We need a latch because admin is not sync,</span>
<span class="source-line-no">601</span><span id="line-601"> // so the postOp coprocessor method may be called after the admin operation returned.</span>
<span class="source-line-no">602</span><span id="line-602"> MasterSyncCoprocessor coproc = testUtil.getHBaseCluster().getMaster().getMasterCoprocessorHost()</span>
<span class="source-line-no">603</span><span id="line-603"> .findCoprocessor(MasterSyncCoprocessor.class);</span>
<span class="source-line-no">604</span><span id="line-604"> coproc.tableDeletionLatch = new CountDownLatch(1);</span>
<span class="source-line-no">605</span><span id="line-605"> try {</span>
<span class="source-line-no">606</span><span id="line-606"> admin.disableTable(tableName);</span>
<span class="source-line-no">607</span><span id="line-607"> } catch (Exception e) {</span>
<span class="source-line-no">608</span><span id="line-608"> LOG.debug("Table: " + tableName + " already disabled, so just deleting it.");</span>
<span class="source-line-no">609</span><span id="line-609"> }</span>
<span class="source-line-no">610</span><span id="line-610"> admin.deleteTable(tableName);</span>
<span class="source-line-no">611</span><span id="line-611"> coproc.tableDeletionLatch.await();</span>
<span class="source-line-no">612</span><span id="line-612"> coproc.tableDeletionLatch = null;</span>
<span class="source-line-no">613</span><span id="line-613"> }</span>
<span class="source-line-no">614</span><span id="line-614">}</span>
</pre>
</div>
</main>
</body>
</html>