hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From git-site-r...@apache.org
Subject [40/51] [partial] hbase-site git commit: Published site at .
Date Thu, 24 Aug 2017 15:11:18 GMT
http://git-wip-us.apache.org/repos/asf/hbase-site/blob/4f1f2a0b/apidocs/src-html/org/apache/hadoop/hbase/client/TableSnapshotScanner.html
----------------------------------------------------------------------
diff --git a/apidocs/src-html/org/apache/hadoop/hbase/client/TableSnapshotScanner.html b/apidocs/src-html/org/apache/hadoop/hbase/client/TableSnapshotScanner.html
index 9615ff3..de8a96f 100644
--- a/apidocs/src-html/org/apache/hadoop/hbase/client/TableSnapshotScanner.html
+++ b/apidocs/src-html/org/apache/hadoop/hbase/client/TableSnapshotScanner.html
@@ -39,166 +39,165 @@
 <span class="sourceLineNo">031</span>import org.apache.hadoop.fs.Path;<a name="line.31"></a>
 <span class="sourceLineNo">032</span>import org.apache.hadoop.hbase.CellUtil;<a
name="line.32"></a>
 <span class="sourceLineNo">033</span>import org.apache.hadoop.hbase.HRegionInfo;<a
name="line.33"></a>
-<span class="sourceLineNo">034</span>import org.apache.hadoop.hbase.HTableDescriptor;<a
name="line.34"></a>
-<span class="sourceLineNo">035</span>import org.apache.hadoop.hbase.classification.InterfaceAudience;<a
name="line.35"></a>
-<span class="sourceLineNo">036</span>import org.apache.hadoop.hbase.snapshot.RestoreSnapshotHelper;<a
name="line.36"></a>
-<span class="sourceLineNo">037</span>import org.apache.hadoop.hbase.util.FSUtils;<a
name="line.37"></a>
-<span class="sourceLineNo">038</span><a name="line.38"></a>
-<span class="sourceLineNo">039</span>/**<a name="line.39"></a>
-<span class="sourceLineNo">040</span> * A Scanner which performs a scan over
snapshot files. Using this class requires copying the<a name="line.40"></a>
-<span class="sourceLineNo">041</span> * snapshot to a temporary empty directory,
which will copy the snapshot reference files into that<a name="line.41"></a>
-<span class="sourceLineNo">042</span> * directory. Actual data files are not
copied.<a name="line.42"></a>
-<span class="sourceLineNo">043</span> *<a name="line.43"></a>
-<span class="sourceLineNo">044</span> * &lt;p&gt;<a name="line.44"></a>
-<span class="sourceLineNo">045</span> * This also allows one to run the scan
from an<a name="line.45"></a>
-<span class="sourceLineNo">046</span> * online or offline hbase cluster. The
snapshot files can be exported by using the<a name="line.46"></a>
-<span class="sourceLineNo">047</span> * {@link org.apache.hadoop.hbase.snapshot.ExportSnapshot}
tool,<a name="line.47"></a>
-<span class="sourceLineNo">048</span> * to a pure-hdfs cluster, and this scanner
can be used to<a name="line.48"></a>
-<span class="sourceLineNo">049</span> * run the scan directly over the snapshot
files. The snapshot should not be deleted while there<a name="line.49"></a>
-<span class="sourceLineNo">050</span> * are open scanners reading from snapshot
files.<a name="line.50"></a>
-<span class="sourceLineNo">051</span> *<a name="line.51"></a>
-<span class="sourceLineNo">052</span> * &lt;p&gt;<a name="line.52"></a>
-<span class="sourceLineNo">053</span> * An internal RegionScanner is used to
execute the {@link Scan} obtained<a name="line.53"></a>
-<span class="sourceLineNo">054</span> * from the user for each region in the
snapshot.<a name="line.54"></a>
-<span class="sourceLineNo">055</span> * &lt;p&gt;<a name="line.55"></a>
-<span class="sourceLineNo">056</span> * HBase owns all the data and snapshot
files on the filesystem. Only the HBase user can read from<a name="line.56"></a>
-<span class="sourceLineNo">057</span> * snapshot files and data files. HBase
also enforces security because all the requests are handled<a name="line.57"></a>
-<span class="sourceLineNo">058</span> * by the server layer, and the user cannot
read from the data files directly. To read from snapshot<a name="line.58"></a>
-<span class="sourceLineNo">059</span> * files directly from the file system,
the user who is running the MR job must have sufficient<a name="line.59"></a>
-<span class="sourceLineNo">060</span> * permissions to access snapshot and reference
files. This means that to run mapreduce over<a name="line.60"></a>
-<span class="sourceLineNo">061</span> * snapshot files, the job has to be run
as the HBase user or the user must have group or other<a name="line.61"></a>
-<span class="sourceLineNo">062</span> * priviledges in the filesystem (See HBASE-8369).
Note that, given other users access to read from<a name="line.62"></a>
-<span class="sourceLineNo">063</span> * snapshot/data files will completely circumvent
the access control enforced by HBase.<a name="line.63"></a>
-<span class="sourceLineNo">064</span> * @see org.apache.hadoop.hbase.mapreduce.TableSnapshotInputFormat<a
name="line.64"></a>
-<span class="sourceLineNo">065</span> */<a name="line.65"></a>
-<span class="sourceLineNo">066</span>@InterfaceAudience.Public<a name="line.66"></a>
-<span class="sourceLineNo">067</span>public class TableSnapshotScanner extends
AbstractClientScanner {<a name="line.67"></a>
-<span class="sourceLineNo">068</span><a name="line.68"></a>
-<span class="sourceLineNo">069</span>  private static final Log LOG = LogFactory.getLog(TableSnapshotScanner.class);<a
name="line.69"></a>
-<span class="sourceLineNo">070</span><a name="line.70"></a>
-<span class="sourceLineNo">071</span>  private Configuration conf;<a name="line.71"></a>
-<span class="sourceLineNo">072</span>  private String snapshotName;<a name="line.72"></a>
-<span class="sourceLineNo">073</span>  private FileSystem fs;<a name="line.73"></a>
-<span class="sourceLineNo">074</span>  private Path rootDir;<a name="line.74"></a>
-<span class="sourceLineNo">075</span>  private Path restoreDir;<a name="line.75"></a>
-<span class="sourceLineNo">076</span>  private Scan scan;<a name="line.76"></a>
-<span class="sourceLineNo">077</span>  private ArrayList&lt;HRegionInfo&gt;
regions;<a name="line.77"></a>
-<span class="sourceLineNo">078</span>  private HTableDescriptor htd;<a name="line.78"></a>
-<span class="sourceLineNo">079</span><a name="line.79"></a>
-<span class="sourceLineNo">080</span>  private ClientSideRegionScanner currentRegionScanner
 = null;<a name="line.80"></a>
-<span class="sourceLineNo">081</span>  private int currentRegion = -1;<a name="line.81"></a>
-<span class="sourceLineNo">082</span><a name="line.82"></a>
-<span class="sourceLineNo">083</span>  /**<a name="line.83"></a>
-<span class="sourceLineNo">084</span>   * Creates a TableSnapshotScanner.<a
name="line.84"></a>
-<span class="sourceLineNo">085</span>   * @param conf the configuration<a
name="line.85"></a>
-<span class="sourceLineNo">086</span>   * @param restoreDir a temporary directory
to copy the snapshot files into. Current user should<a name="line.86"></a>
-<span class="sourceLineNo">087</span>   * have write permissions to this directory,
and this should not be a subdirectory of rootdir.<a name="line.87"></a>
-<span class="sourceLineNo">088</span>   * The scanner deletes the contents of
the directory once the scanner is closed.<a name="line.88"></a>
-<span class="sourceLineNo">089</span>   * @param snapshotName the name of the
snapshot to read from<a name="line.89"></a>
-<span class="sourceLineNo">090</span>   * @param scan a Scan representing scan
parameters<a name="line.90"></a>
-<span class="sourceLineNo">091</span>   * @throws IOException in case of error<a
name="line.91"></a>
-<span class="sourceLineNo">092</span>   */<a name="line.92"></a>
-<span class="sourceLineNo">093</span>  public TableSnapshotScanner(Configuration
conf, Path restoreDir,<a name="line.93"></a>
-<span class="sourceLineNo">094</span>      String snapshotName, Scan scan) throws
IOException {<a name="line.94"></a>
-<span class="sourceLineNo">095</span>    this(conf, FSUtils.getRootDir(conf),
restoreDir, snapshotName, scan);<a name="line.95"></a>
-<span class="sourceLineNo">096</span>  }<a name="line.96"></a>
-<span class="sourceLineNo">097</span><a name="line.97"></a>
-<span class="sourceLineNo">098</span>  /**<a name="line.98"></a>
-<span class="sourceLineNo">099</span>   * Creates a TableSnapshotScanner.<a
name="line.99"></a>
-<span class="sourceLineNo">100</span>   * @param conf the configuration<a
name="line.100"></a>
-<span class="sourceLineNo">101</span>   * @param rootDir root directory for HBase.<a
name="line.101"></a>
-<span class="sourceLineNo">102</span>   * @param restoreDir a temporary directory
to copy the snapshot files into. Current user should<a name="line.102"></a>
-<span class="sourceLineNo">103</span>   * have write permissions to this directory,
and this should not be a subdirectory of rootdir.<a name="line.103"></a>
-<span class="sourceLineNo">104</span>   * The scanner deletes the contents of
the directory once the scanner is closed.<a name="line.104"></a>
-<span class="sourceLineNo">105</span>   * @param snapshotName the name of the
snapshot to read from<a name="line.105"></a>
-<span class="sourceLineNo">106</span>   * @param scan a Scan representing scan
parameters<a name="line.106"></a>
-<span class="sourceLineNo">107</span>   * @throws IOException in case of error<a
name="line.107"></a>
-<span class="sourceLineNo">108</span>   */<a name="line.108"></a>
-<span class="sourceLineNo">109</span>  public TableSnapshotScanner(Configuration
conf, Path rootDir,<a name="line.109"></a>
-<span class="sourceLineNo">110</span>      Path restoreDir, String snapshotName,
Scan scan) throws IOException {<a name="line.110"></a>
-<span class="sourceLineNo">111</span>    this.conf = conf;<a name="line.111"></a>
-<span class="sourceLineNo">112</span>    this.snapshotName = snapshotName;<a
name="line.112"></a>
-<span class="sourceLineNo">113</span>    this.rootDir = rootDir;<a name="line.113"></a>
-<span class="sourceLineNo">114</span>    // restoreDir will be deleted in close(),
use a unique sub directory<a name="line.114"></a>
-<span class="sourceLineNo">115</span>    this.restoreDir = new Path(restoreDir,
UUID.randomUUID().toString());<a name="line.115"></a>
-<span class="sourceLineNo">116</span>    this.scan = scan;<a name="line.116"></a>
-<span class="sourceLineNo">117</span>    this.fs = rootDir.getFileSystem(conf);<a
name="line.117"></a>
-<span class="sourceLineNo">118</span>    init();<a name="line.118"></a>
-<span class="sourceLineNo">119</span>  }<a name="line.119"></a>
-<span class="sourceLineNo">120</span><a name="line.120"></a>
-<span class="sourceLineNo">121</span>  private void init() throws IOException
{<a name="line.121"></a>
-<span class="sourceLineNo">122</span>    final RestoreSnapshotHelper.RestoreMetaChanges
meta =<a name="line.122"></a>
-<span class="sourceLineNo">123</span>      RestoreSnapshotHelper.copySnapshotForScanner(<a
name="line.123"></a>
-<span class="sourceLineNo">124</span>        conf, fs, rootDir, restoreDir, snapshotName);<a
name="line.124"></a>
-<span class="sourceLineNo">125</span>    final List&lt;HRegionInfo&gt;
restoredRegions = meta.getRegionsToAdd();<a name="line.125"></a>
-<span class="sourceLineNo">126</span><a name="line.126"></a>
-<span class="sourceLineNo">127</span>    htd = meta.getTableDescriptor();<a
name="line.127"></a>
-<span class="sourceLineNo">128</span>    regions = new ArrayList&lt;&gt;(restoredRegions.size());<a
name="line.128"></a>
-<span class="sourceLineNo">129</span>    for (HRegionInfo hri : restoredRegions)
{<a name="line.129"></a>
-<span class="sourceLineNo">130</span>      if (hri.isOffline() &amp;&amp;
(hri.isSplit() || hri.isSplitParent())) {<a name="line.130"></a>
-<span class="sourceLineNo">131</span>        continue;<a name="line.131"></a>
-<span class="sourceLineNo">132</span>      }<a name="line.132"></a>
-<span class="sourceLineNo">133</span>      if (CellUtil.overlappingKeys(scan.getStartRow(),
scan.getStopRow(), hri.getStartKey(),<a name="line.133"></a>
-<span class="sourceLineNo">134</span>        hri.getEndKey())) {<a name="line.134"></a>
-<span class="sourceLineNo">135</span>        regions.add(hri);<a name="line.135"></a>
-<span class="sourceLineNo">136</span>      }<a name="line.136"></a>
-<span class="sourceLineNo">137</span>    }<a name="line.137"></a>
-<span class="sourceLineNo">138</span><a name="line.138"></a>
-<span class="sourceLineNo">139</span>    // sort for regions according to startKey.<a
name="line.139"></a>
-<span class="sourceLineNo">140</span>    Collections.sort(regions);<a name="line.140"></a>
-<span class="sourceLineNo">141</span>    initScanMetrics(scan);<a name="line.141"></a>
-<span class="sourceLineNo">142</span>  }<a name="line.142"></a>
-<span class="sourceLineNo">143</span><a name="line.143"></a>
-<span class="sourceLineNo">144</span>  @Override<a name="line.144"></a>
-<span class="sourceLineNo">145</span>  public Result next() throws IOException
{<a name="line.145"></a>
-<span class="sourceLineNo">146</span>    Result result = null;<a name="line.146"></a>
-<span class="sourceLineNo">147</span>    while (true) {<a name="line.147"></a>
-<span class="sourceLineNo">148</span>      if (currentRegionScanner == null)
{<a name="line.148"></a>
-<span class="sourceLineNo">149</span>        currentRegion++;<a name="line.149"></a>
-<span class="sourceLineNo">150</span>        if (currentRegion &gt;= regions.size())
{<a name="line.150"></a>
-<span class="sourceLineNo">151</span>          return null;<a name="line.151"></a>
-<span class="sourceLineNo">152</span>        }<a name="line.152"></a>
-<span class="sourceLineNo">153</span><a name="line.153"></a>
-<span class="sourceLineNo">154</span>        HRegionInfo hri = regions.get(currentRegion);<a
name="line.154"></a>
-<span class="sourceLineNo">155</span>        currentRegionScanner = new ClientSideRegionScanner(conf,
fs,<a name="line.155"></a>
-<span class="sourceLineNo">156</span>          restoreDir, htd, hri, scan, scanMetrics);<a
name="line.156"></a>
-<span class="sourceLineNo">157</span>        if (this.scanMetrics != null) {<a
name="line.157"></a>
-<span class="sourceLineNo">158</span>          this.scanMetrics.countOfRegions.incrementAndGet();<a
name="line.158"></a>
-<span class="sourceLineNo">159</span>        }<a name="line.159"></a>
-<span class="sourceLineNo">160</span>      }<a name="line.160"></a>
-<span class="sourceLineNo">161</span><a name="line.161"></a>
-<span class="sourceLineNo">162</span>      try {<a name="line.162"></a>
-<span class="sourceLineNo">163</span>        result = currentRegionScanner.next();<a
name="line.163"></a>
-<span class="sourceLineNo">164</span>        if (result != null) {<a name="line.164"></a>
-<span class="sourceLineNo">165</span>          return result;<a name="line.165"></a>
-<span class="sourceLineNo">166</span>        }<a name="line.166"></a>
-<span class="sourceLineNo">167</span>      } finally {<a name="line.167"></a>
-<span class="sourceLineNo">168</span>        if (result == null) {<a name="line.168"></a>
-<span class="sourceLineNo">169</span>          currentRegionScanner.close();<a
name="line.169"></a>
-<span class="sourceLineNo">170</span>          currentRegionScanner = null;<a
name="line.170"></a>
-<span class="sourceLineNo">171</span>        }<a name="line.171"></a>
-<span class="sourceLineNo">172</span>      }<a name="line.172"></a>
-<span class="sourceLineNo">173</span>    }<a name="line.173"></a>
-<span class="sourceLineNo">174</span>  }<a name="line.174"></a>
-<span class="sourceLineNo">175</span><a name="line.175"></a>
-<span class="sourceLineNo">176</span>  @Override<a name="line.176"></a>
-<span class="sourceLineNo">177</span>  public void close() {<a name="line.177"></a>
-<span class="sourceLineNo">178</span>    if (currentRegionScanner != null) {<a
name="line.178"></a>
-<span class="sourceLineNo">179</span>      currentRegionScanner.close();<a
name="line.179"></a>
-<span class="sourceLineNo">180</span>    }<a name="line.180"></a>
-<span class="sourceLineNo">181</span>    try {<a name="line.181"></a>
-<span class="sourceLineNo">182</span>      fs.delete(this.restoreDir, true);<a
name="line.182"></a>
-<span class="sourceLineNo">183</span>    } catch (IOException ex) {<a name="line.183"></a>
-<span class="sourceLineNo">184</span>      LOG.warn("Could not delete restore
directory for the snapshot:" + ex);<a name="line.184"></a>
-<span class="sourceLineNo">185</span>    }<a name="line.185"></a>
-<span class="sourceLineNo">186</span>  }<a name="line.186"></a>
-<span class="sourceLineNo">187</span><a name="line.187"></a>
-<span class="sourceLineNo">188</span>  @Override<a name="line.188"></a>
-<span class="sourceLineNo">189</span>  public boolean renewLease() {<a name="line.189"></a>
-<span class="sourceLineNo">190</span>    throw new UnsupportedOperationException();<a
name="line.190"></a>
-<span class="sourceLineNo">191</span>  }<a name="line.191"></a>
-<span class="sourceLineNo">192</span><a name="line.192"></a>
-<span class="sourceLineNo">193</span>}<a name="line.193"></a>
+<span class="sourceLineNo">034</span>import org.apache.hadoop.hbase.classification.InterfaceAudience;<a
name="line.34"></a>
+<span class="sourceLineNo">035</span>import org.apache.hadoop.hbase.snapshot.RestoreSnapshotHelper;<a
name="line.35"></a>
+<span class="sourceLineNo">036</span>import org.apache.hadoop.hbase.util.FSUtils;<a
name="line.36"></a>
+<span class="sourceLineNo">037</span><a name="line.37"></a>
+<span class="sourceLineNo">038</span>/**<a name="line.38"></a>
+<span class="sourceLineNo">039</span> * A Scanner which performs a scan over
snapshot files. Using this class requires copying the<a name="line.39"></a>
+<span class="sourceLineNo">040</span> * snapshot to a temporary empty directory,
which will copy the snapshot reference files into that<a name="line.40"></a>
+<span class="sourceLineNo">041</span> * directory. Actual data files are not
copied.<a name="line.41"></a>
+<span class="sourceLineNo">042</span> *<a name="line.42"></a>
+<span class="sourceLineNo">043</span> * &lt;p&gt;<a name="line.43"></a>
+<span class="sourceLineNo">044</span> * This also allows one to run the scan
from an<a name="line.44"></a>
+<span class="sourceLineNo">045</span> * online or offline hbase cluster. The
snapshot files can be exported by using the<a name="line.45"></a>
+<span class="sourceLineNo">046</span> * {@link org.apache.hadoop.hbase.snapshot.ExportSnapshot}
tool,<a name="line.46"></a>
+<span class="sourceLineNo">047</span> * to a pure-hdfs cluster, and this scanner
can be used to<a name="line.47"></a>
+<span class="sourceLineNo">048</span> * run the scan directly over the snapshot
files. The snapshot should not be deleted while there<a name="line.48"></a>
+<span class="sourceLineNo">049</span> * are open scanners reading from snapshot
files.<a name="line.49"></a>
+<span class="sourceLineNo">050</span> *<a name="line.50"></a>
+<span class="sourceLineNo">051</span> * &lt;p&gt;<a name="line.51"></a>
+<span class="sourceLineNo">052</span> * An internal RegionScanner is used to
execute the {@link Scan} obtained<a name="line.52"></a>
+<span class="sourceLineNo">053</span> * from the user for each region in the
snapshot.<a name="line.53"></a>
+<span class="sourceLineNo">054</span> * &lt;p&gt;<a name="line.54"></a>
+<span class="sourceLineNo">055</span> * HBase owns all the data and snapshot
files on the filesystem. Only the HBase user can read from<a name="line.55"></a>
+<span class="sourceLineNo">056</span> * snapshot files and data files. HBase
also enforces security because all the requests are handled<a name="line.56"></a>
+<span class="sourceLineNo">057</span> * by the server layer, and the user cannot
read from the data files directly. To read from snapshot<a name="line.57"></a>
+<span class="sourceLineNo">058</span> * files directly from the file system,
the user who is running the MR job must have sufficient<a name="line.58"></a>
+<span class="sourceLineNo">059</span> * permissions to access snapshot and reference
files. This means that to run mapreduce over<a name="line.59"></a>
+<span class="sourceLineNo">060</span> * snapshot files, the job has to be run
as the HBase user or the user must have group or other<a name="line.60"></a>
+<span class="sourceLineNo">061</span> * priviledges in the filesystem (See HBASE-8369).
Note that, given other users access to read from<a name="line.61"></a>
+<span class="sourceLineNo">062</span> * snapshot/data files will completely circumvent
the access control enforced by HBase.<a name="line.62"></a>
+<span class="sourceLineNo">063</span> * @see org.apache.hadoop.hbase.mapreduce.TableSnapshotInputFormat<a
name="line.63"></a>
+<span class="sourceLineNo">064</span> */<a name="line.64"></a>
+<span class="sourceLineNo">065</span>@InterfaceAudience.Public<a name="line.65"></a>
+<span class="sourceLineNo">066</span>public class TableSnapshotScanner extends
AbstractClientScanner {<a name="line.66"></a>
+<span class="sourceLineNo">067</span><a name="line.67"></a>
+<span class="sourceLineNo">068</span>  private static final Log LOG = LogFactory.getLog(TableSnapshotScanner.class);<a
name="line.68"></a>
+<span class="sourceLineNo">069</span><a name="line.69"></a>
+<span class="sourceLineNo">070</span>  private Configuration conf;<a name="line.70"></a>
+<span class="sourceLineNo">071</span>  private String snapshotName;<a name="line.71"></a>
+<span class="sourceLineNo">072</span>  private FileSystem fs;<a name="line.72"></a>
+<span class="sourceLineNo">073</span>  private Path rootDir;<a name="line.73"></a>
+<span class="sourceLineNo">074</span>  private Path restoreDir;<a name="line.74"></a>
+<span class="sourceLineNo">075</span>  private Scan scan;<a name="line.75"></a>
+<span class="sourceLineNo">076</span>  private ArrayList&lt;HRegionInfo&gt;
regions;<a name="line.76"></a>
+<span class="sourceLineNo">077</span>  private TableDescriptor htd;<a name="line.77"></a>
+<span class="sourceLineNo">078</span><a name="line.78"></a>
+<span class="sourceLineNo">079</span>  private ClientSideRegionScanner currentRegionScanner
 = null;<a name="line.79"></a>
+<span class="sourceLineNo">080</span>  private int currentRegion = -1;<a name="line.80"></a>
+<span class="sourceLineNo">081</span><a name="line.81"></a>
+<span class="sourceLineNo">082</span>  /**<a name="line.82"></a>
+<span class="sourceLineNo">083</span>   * Creates a TableSnapshotScanner.<a
name="line.83"></a>
+<span class="sourceLineNo">084</span>   * @param conf the configuration<a
name="line.84"></a>
+<span class="sourceLineNo">085</span>   * @param restoreDir a temporary directory
to copy the snapshot files into. Current user should<a name="line.85"></a>
+<span class="sourceLineNo">086</span>   * have write permissions to this directory,
and this should not be a subdirectory of rootdir.<a name="line.86"></a>
+<span class="sourceLineNo">087</span>   * The scanner deletes the contents of
the directory once the scanner is closed.<a name="line.87"></a>
+<span class="sourceLineNo">088</span>   * @param snapshotName the name of the
snapshot to read from<a name="line.88"></a>
+<span class="sourceLineNo">089</span>   * @param scan a Scan representing scan
parameters<a name="line.89"></a>
+<span class="sourceLineNo">090</span>   * @throws IOException in case of error<a
name="line.90"></a>
+<span class="sourceLineNo">091</span>   */<a name="line.91"></a>
+<span class="sourceLineNo">092</span>  public TableSnapshotScanner(Configuration
conf, Path restoreDir,<a name="line.92"></a>
+<span class="sourceLineNo">093</span>      String snapshotName, Scan scan) throws
IOException {<a name="line.93"></a>
+<span class="sourceLineNo">094</span>    this(conf, FSUtils.getRootDir(conf),
restoreDir, snapshotName, scan);<a name="line.94"></a>
+<span class="sourceLineNo">095</span>  }<a name="line.95"></a>
+<span class="sourceLineNo">096</span><a name="line.96"></a>
+<span class="sourceLineNo">097</span>  /**<a name="line.97"></a>
+<span class="sourceLineNo">098</span>   * Creates a TableSnapshotScanner.<a
name="line.98"></a>
+<span class="sourceLineNo">099</span>   * @param conf the configuration<a
name="line.99"></a>
+<span class="sourceLineNo">100</span>   * @param rootDir root directory for HBase.<a
name="line.100"></a>
+<span class="sourceLineNo">101</span>   * @param restoreDir a temporary directory
to copy the snapshot files into. Current user should<a name="line.101"></a>
+<span class="sourceLineNo">102</span>   * have write permissions to this directory,
and this should not be a subdirectory of rootdir.<a name="line.102"></a>
+<span class="sourceLineNo">103</span>   * The scanner deletes the contents of
the directory once the scanner is closed.<a name="line.103"></a>
+<span class="sourceLineNo">104</span>   * @param snapshotName the name of the
snapshot to read from<a name="line.104"></a>
+<span class="sourceLineNo">105</span>   * @param scan a Scan representing scan
parameters<a name="line.105"></a>
+<span class="sourceLineNo">106</span>   * @throws IOException in case of error<a
name="line.106"></a>
+<span class="sourceLineNo">107</span>   */<a name="line.107"></a>
+<span class="sourceLineNo">108</span>  public TableSnapshotScanner(Configuration
conf, Path rootDir,<a name="line.108"></a>
+<span class="sourceLineNo">109</span>      Path restoreDir, String snapshotName,
Scan scan) throws IOException {<a name="line.109"></a>
+<span class="sourceLineNo">110</span>    this.conf = conf;<a name="line.110"></a>
+<span class="sourceLineNo">111</span>    this.snapshotName = snapshotName;<a
name="line.111"></a>
+<span class="sourceLineNo">112</span>    this.rootDir = rootDir;<a name="line.112"></a>
+<span class="sourceLineNo">113</span>    // restoreDir will be deleted in close(),
use a unique sub directory<a name="line.113"></a>
+<span class="sourceLineNo">114</span>    this.restoreDir = new Path(restoreDir,
UUID.randomUUID().toString());<a name="line.114"></a>
+<span class="sourceLineNo">115</span>    this.scan = scan;<a name="line.115"></a>
+<span class="sourceLineNo">116</span>    this.fs = rootDir.getFileSystem(conf);<a
name="line.116"></a>
+<span class="sourceLineNo">117</span>    init();<a name="line.117"></a>
+<span class="sourceLineNo">118</span>  }<a name="line.118"></a>
+<span class="sourceLineNo">119</span><a name="line.119"></a>
+<span class="sourceLineNo">120</span>  private void init() throws IOException
{<a name="line.120"></a>
+<span class="sourceLineNo">121</span>    final RestoreSnapshotHelper.RestoreMetaChanges
meta =<a name="line.121"></a>
+<span class="sourceLineNo">122</span>      RestoreSnapshotHelper.copySnapshotForScanner(<a
name="line.122"></a>
+<span class="sourceLineNo">123</span>        conf, fs, rootDir, restoreDir, snapshotName);<a
name="line.123"></a>
+<span class="sourceLineNo">124</span>    final List&lt;HRegionInfo&gt;
restoredRegions = meta.getRegionsToAdd();<a name="line.124"></a>
+<span class="sourceLineNo">125</span><a name="line.125"></a>
+<span class="sourceLineNo">126</span>    htd = meta.getTableDescriptor();<a
name="line.126"></a>
+<span class="sourceLineNo">127</span>    regions = new ArrayList&lt;&gt;(restoredRegions.size());<a
name="line.127"></a>
+<span class="sourceLineNo">128</span>    for (HRegionInfo hri : restoredRegions)
{<a name="line.128"></a>
+<span class="sourceLineNo">129</span>      if (hri.isOffline() &amp;&amp;
(hri.isSplit() || hri.isSplitParent())) {<a name="line.129"></a>
+<span class="sourceLineNo">130</span>        continue;<a name="line.130"></a>
+<span class="sourceLineNo">131</span>      }<a name="line.131"></a>
+<span class="sourceLineNo">132</span>      if (CellUtil.overlappingKeys(scan.getStartRow(),
scan.getStopRow(), hri.getStartKey(),<a name="line.132"></a>
+<span class="sourceLineNo">133</span>        hri.getEndKey())) {<a name="line.133"></a>
+<span class="sourceLineNo">134</span>        regions.add(hri);<a name="line.134"></a>
+<span class="sourceLineNo">135</span>      }<a name="line.135"></a>
+<span class="sourceLineNo">136</span>    }<a name="line.136"></a>
+<span class="sourceLineNo">137</span><a name="line.137"></a>
+<span class="sourceLineNo">138</span>    // sort for regions according to startKey.<a
name="line.138"></a>
+<span class="sourceLineNo">139</span>    Collections.sort(regions);<a name="line.139"></a>
+<span class="sourceLineNo">140</span>    initScanMetrics(scan);<a name="line.140"></a>
+<span class="sourceLineNo">141</span>  }<a name="line.141"></a>
+<span class="sourceLineNo">142</span><a name="line.142"></a>
+<span class="sourceLineNo">143</span>  @Override<a name="line.143"></a>
+<span class="sourceLineNo">144</span>  public Result next() throws IOException
{<a name="line.144"></a>
+<span class="sourceLineNo">145</span>    Result result = null;<a name="line.145"></a>
+<span class="sourceLineNo">146</span>    while (true) {<a name="line.146"></a>
+<span class="sourceLineNo">147</span>      if (currentRegionScanner == null)
{<a name="line.147"></a>
+<span class="sourceLineNo">148</span>        currentRegion++;<a name="line.148"></a>
+<span class="sourceLineNo">149</span>        if (currentRegion &gt;= regions.size())
{<a name="line.149"></a>
+<span class="sourceLineNo">150</span>          return null;<a name="line.150"></a>
+<span class="sourceLineNo">151</span>        }<a name="line.151"></a>
+<span class="sourceLineNo">152</span><a name="line.152"></a>
+<span class="sourceLineNo">153</span>        HRegionInfo hri = regions.get(currentRegion);<a
name="line.153"></a>
+<span class="sourceLineNo">154</span>        currentRegionScanner = new ClientSideRegionScanner(conf,
fs,<a name="line.154"></a>
+<span class="sourceLineNo">155</span>          restoreDir, htd, hri, scan, scanMetrics);<a
name="line.155"></a>
+<span class="sourceLineNo">156</span>        if (this.scanMetrics != null) {<a
name="line.156"></a>
+<span class="sourceLineNo">157</span>          this.scanMetrics.countOfRegions.incrementAndGet();<a
name="line.157"></a>
+<span class="sourceLineNo">158</span>        }<a name="line.158"></a>
+<span class="sourceLineNo">159</span>      }<a name="line.159"></a>
+<span class="sourceLineNo">160</span><a name="line.160"></a>
+<span class="sourceLineNo">161</span>      try {<a name="line.161"></a>
+<span class="sourceLineNo">162</span>        result = currentRegionScanner.next();<a
name="line.162"></a>
+<span class="sourceLineNo">163</span>        if (result != null) {<a name="line.163"></a>
+<span class="sourceLineNo">164</span>          return result;<a name="line.164"></a>
+<span class="sourceLineNo">165</span>        }<a name="line.165"></a>
+<span class="sourceLineNo">166</span>      } finally {<a name="line.166"></a>
+<span class="sourceLineNo">167</span>        if (result == null) {<a name="line.167"></a>
+<span class="sourceLineNo">168</span>          currentRegionScanner.close();<a
name="line.168"></a>
+<span class="sourceLineNo">169</span>          currentRegionScanner = null;<a
name="line.169"></a>
+<span class="sourceLineNo">170</span>        }<a name="line.170"></a>
+<span class="sourceLineNo">171</span>      }<a name="line.171"></a>
+<span class="sourceLineNo">172</span>    }<a name="line.172"></a>
+<span class="sourceLineNo">173</span>  }<a name="line.173"></a>
+<span class="sourceLineNo">174</span><a name="line.174"></a>
+<span class="sourceLineNo">175</span>  @Override<a name="line.175"></a>
+<span class="sourceLineNo">176</span>  public void close() {<a name="line.176"></a>
+<span class="sourceLineNo">177</span>    if (currentRegionScanner != null) {<a
name="line.177"></a>
+<span class="sourceLineNo">178</span>      currentRegionScanner.close();<a
name="line.178"></a>
+<span class="sourceLineNo">179</span>    }<a name="line.179"></a>
+<span class="sourceLineNo">180</span>    try {<a name="line.180"></a>
+<span class="sourceLineNo">181</span>      fs.delete(this.restoreDir, true);<a
name="line.181"></a>
+<span class="sourceLineNo">182</span>    } catch (IOException ex) {<a name="line.182"></a>
+<span class="sourceLineNo">183</span>      LOG.warn("Could not delete restore
directory for the snapshot:" + ex);<a name="line.183"></a>
+<span class="sourceLineNo">184</span>    }<a name="line.184"></a>
+<span class="sourceLineNo">185</span>  }<a name="line.185"></a>
+<span class="sourceLineNo">186</span><a name="line.186"></a>
+<span class="sourceLineNo">187</span>  @Override<a name="line.187"></a>
+<span class="sourceLineNo">188</span>  public boolean renewLease() {<a name="line.188"></a>
+<span class="sourceLineNo">189</span>    throw new UnsupportedOperationException();<a
name="line.189"></a>
+<span class="sourceLineNo">190</span>  }<a name="line.190"></a>
+<span class="sourceLineNo">191</span><a name="line.191"></a>
+<span class="sourceLineNo">192</span>}<a name="line.192"></a>
 
 
 


Mime
View raw message