hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mi...@apache.org
Subject [37/51] [partial] hbase-site git commit: Published site at 4bf6f8379d7f85413b914dddf607d016780d40ce.
Date Thu, 21 Jan 2016 17:22:56 GMT
http://git-wip-us.apache.org/repos/asf/hbase-site/blob/75eda567/apidocs/src-html/org/apache/hadoop/hbase/snapshot/ExportSnapshot.html
----------------------------------------------------------------------
diff --git a/apidocs/src-html/org/apache/hadoop/hbase/snapshot/ExportSnapshot.html b/apidocs/src-html/org/apache/hadoop/hbase/snapshot/ExportSnapshot.html
index 5da37ee..14327de 100644
--- a/apidocs/src-html/org/apache/hadoop/hbase/snapshot/ExportSnapshot.html
+++ b/apidocs/src-html/org/apache/hadoop/hbase/snapshot/ExportSnapshot.html
@@ -651,446 +651,445 @@
 <span class="sourceLineNo">643</span>    @Override<a name="line.643"></a>
 <span class="sourceLineNo">644</span>    public List&lt;InputSplit&gt; getSplits(JobContext context) throws IOException, InterruptedException {<a name="line.644"></a>
 <span class="sourceLineNo">645</span>      Configuration conf = context.getConfiguration();<a name="line.645"></a>
-<span class="sourceLineNo">646</span>      String snapshotName = conf.get(CONF_SNAPSHOT_NAME);<a name="line.646"></a>
-<span class="sourceLineNo">647</span>      Path snapshotDir = new Path(conf.get(CONF_SNAPSHOT_DIR));<a name="line.647"></a>
-<span class="sourceLineNo">648</span>      FileSystem fs = FileSystem.get(snapshotDir.toUri(), conf);<a name="line.648"></a>
-<span class="sourceLineNo">649</span><a name="line.649"></a>
-<span class="sourceLineNo">650</span>      List&lt;Pair&lt;SnapshotFileInfo, Long&gt;&gt; snapshotFiles = getSnapshotFiles(conf, fs, snapshotDir);<a name="line.650"></a>
-<span class="sourceLineNo">651</span>      int mappers = conf.getInt(CONF_NUM_SPLITS, 0);<a name="line.651"></a>
-<span class="sourceLineNo">652</span>      if (mappers == 0 &amp;&amp; snapshotFiles.size() &gt; 0) {<a name="line.652"></a>
-<span class="sourceLineNo">653</span>        mappers = 1 + (snapshotFiles.size() / conf.getInt(CONF_MAP_GROUP, 10));<a name="line.653"></a>
-<span class="sourceLineNo">654</span>        mappers = Math.min(mappers, snapshotFiles.size());<a name="line.654"></a>
-<span class="sourceLineNo">655</span>        conf.setInt(CONF_NUM_SPLITS, mappers);<a name="line.655"></a>
-<span class="sourceLineNo">656</span>        conf.setInt(MR_NUM_MAPS, mappers);<a name="line.656"></a>
-<span class="sourceLineNo">657</span>      }<a name="line.657"></a>
-<span class="sourceLineNo">658</span><a name="line.658"></a>
-<span class="sourceLineNo">659</span>      List&lt;List&lt;Pair&lt;SnapshotFileInfo, Long&gt;&gt;&gt; groups = getBalancedSplits(snapshotFiles, mappers);<a name="line.659"></a>
-<span class="sourceLineNo">660</span>      List&lt;InputSplit&gt; splits = new ArrayList(groups.size());<a name="line.660"></a>
-<span class="sourceLineNo">661</span>      for (List&lt;Pair&lt;SnapshotFileInfo, Long&gt;&gt; files: groups) {<a name="line.661"></a>
-<span class="sourceLineNo">662</span>        splits.add(new ExportSnapshotInputSplit(files));<a name="line.662"></a>
-<span class="sourceLineNo">663</span>      }<a name="line.663"></a>
-<span class="sourceLineNo">664</span>      return splits;<a name="line.664"></a>
-<span class="sourceLineNo">665</span>    }<a name="line.665"></a>
-<span class="sourceLineNo">666</span><a name="line.666"></a>
-<span class="sourceLineNo">667</span>    private static class ExportSnapshotInputSplit extends InputSplit implements Writable {<a name="line.667"></a>
-<span class="sourceLineNo">668</span>      private List&lt;Pair&lt;BytesWritable, Long&gt;&gt; files;<a name="line.668"></a>
-<span class="sourceLineNo">669</span>      private long length;<a name="line.669"></a>
-<span class="sourceLineNo">670</span><a name="line.670"></a>
-<span class="sourceLineNo">671</span>      public ExportSnapshotInputSplit() {<a name="line.671"></a>
-<span class="sourceLineNo">672</span>        this.files = null;<a name="line.672"></a>
-<span class="sourceLineNo">673</span>      }<a name="line.673"></a>
-<span class="sourceLineNo">674</span><a name="line.674"></a>
-<span class="sourceLineNo">675</span>      public ExportSnapshotInputSplit(final List&lt;Pair&lt;SnapshotFileInfo, Long&gt;&gt; snapshotFiles) {<a name="line.675"></a>
-<span class="sourceLineNo">676</span>        this.files = new ArrayList(snapshotFiles.size());<a name="line.676"></a>
-<span class="sourceLineNo">677</span>        for (Pair&lt;SnapshotFileInfo, Long&gt; fileInfo: snapshotFiles) {<a name="line.677"></a>
-<span class="sourceLineNo">678</span>          this.files.add(new Pair&lt;BytesWritable, Long&gt;(<a name="line.678"></a>
-<span class="sourceLineNo">679</span>            new BytesWritable(fileInfo.getFirst().toByteArray()), fileInfo.getSecond()));<a name="line.679"></a>
-<span class="sourceLineNo">680</span>          this.length += fileInfo.getSecond();<a name="line.680"></a>
-<span class="sourceLineNo">681</span>        }<a name="line.681"></a>
-<span class="sourceLineNo">682</span>      }<a name="line.682"></a>
-<span class="sourceLineNo">683</span><a name="line.683"></a>
-<span class="sourceLineNo">684</span>      private List&lt;Pair&lt;BytesWritable, Long&gt;&gt; getSplitKeys() {<a name="line.684"></a>
-<span class="sourceLineNo">685</span>        return files;<a name="line.685"></a>
-<span class="sourceLineNo">686</span>      }<a name="line.686"></a>
-<span class="sourceLineNo">687</span><a name="line.687"></a>
-<span class="sourceLineNo">688</span>      @Override<a name="line.688"></a>
-<span class="sourceLineNo">689</span>      public long getLength() throws IOException, InterruptedException {<a name="line.689"></a>
-<span class="sourceLineNo">690</span>        return length;<a name="line.690"></a>
-<span class="sourceLineNo">691</span>      }<a name="line.691"></a>
-<span class="sourceLineNo">692</span><a name="line.692"></a>
-<span class="sourceLineNo">693</span>      @Override<a name="line.693"></a>
-<span class="sourceLineNo">694</span>      public String[] getLocations() throws IOException, InterruptedException {<a name="line.694"></a>
-<span class="sourceLineNo">695</span>        return new String[] {};<a name="line.695"></a>
-<span class="sourceLineNo">696</span>      }<a name="line.696"></a>
-<span class="sourceLineNo">697</span><a name="line.697"></a>
-<span class="sourceLineNo">698</span>      @Override<a name="line.698"></a>
-<span class="sourceLineNo">699</span>      public void readFields(DataInput in) throws IOException {<a name="line.699"></a>
-<span class="sourceLineNo">700</span>        int count = in.readInt();<a name="line.700"></a>
-<span class="sourceLineNo">701</span>        files = new ArrayList&lt;Pair&lt;BytesWritable, Long&gt;&gt;(count);<a name="line.701"></a>
-<span class="sourceLineNo">702</span>        length = 0;<a name="line.702"></a>
-<span class="sourceLineNo">703</span>        for (int i = 0; i &lt; count; ++i) {<a name="line.703"></a>
-<span class="sourceLineNo">704</span>          BytesWritable fileInfo = new BytesWritable();<a name="line.704"></a>
-<span class="sourceLineNo">705</span>          fileInfo.readFields(in);<a name="line.705"></a>
-<span class="sourceLineNo">706</span>          long size = in.readLong();<a name="line.706"></a>
-<span class="sourceLineNo">707</span>          files.add(new Pair&lt;BytesWritable, Long&gt;(fileInfo, size));<a name="line.707"></a>
-<span class="sourceLineNo">708</span>          length += size;<a name="line.708"></a>
-<span class="sourceLineNo">709</span>        }<a name="line.709"></a>
-<span class="sourceLineNo">710</span>      }<a name="line.710"></a>
-<span class="sourceLineNo">711</span><a name="line.711"></a>
-<span class="sourceLineNo">712</span>      @Override<a name="line.712"></a>
-<span class="sourceLineNo">713</span>      public void write(DataOutput out) throws IOException {<a name="line.713"></a>
-<span class="sourceLineNo">714</span>        out.writeInt(files.size());<a name="line.714"></a>
-<span class="sourceLineNo">715</span>        for (final Pair&lt;BytesWritable, Long&gt; fileInfo: files) {<a name="line.715"></a>
-<span class="sourceLineNo">716</span>          fileInfo.getFirst().write(out);<a name="line.716"></a>
-<span class="sourceLineNo">717</span>          out.writeLong(fileInfo.getSecond());<a name="line.717"></a>
-<span class="sourceLineNo">718</span>        }<a name="line.718"></a>
-<span class="sourceLineNo">719</span>      }<a name="line.719"></a>
-<span class="sourceLineNo">720</span>    }<a name="line.720"></a>
-<span class="sourceLineNo">721</span><a name="line.721"></a>
-<span class="sourceLineNo">722</span>    private static class ExportSnapshotRecordReader<a name="line.722"></a>
-<span class="sourceLineNo">723</span>        extends RecordReader&lt;BytesWritable, NullWritable&gt; {<a name="line.723"></a>
-<span class="sourceLineNo">724</span>      private final List&lt;Pair&lt;BytesWritable, Long&gt;&gt; files;<a name="line.724"></a>
-<span class="sourceLineNo">725</span>      private long totalSize = 0;<a name="line.725"></a>
-<span class="sourceLineNo">726</span>      private long procSize = 0;<a name="line.726"></a>
-<span class="sourceLineNo">727</span>      private int index = -1;<a name="line.727"></a>
-<span class="sourceLineNo">728</span><a name="line.728"></a>
-<span class="sourceLineNo">729</span>      ExportSnapshotRecordReader(final List&lt;Pair&lt;BytesWritable, Long&gt;&gt; files) {<a name="line.729"></a>
-<span class="sourceLineNo">730</span>        this.files = files;<a name="line.730"></a>
-<span class="sourceLineNo">731</span>        for (Pair&lt;BytesWritable, Long&gt; fileInfo: files) {<a name="line.731"></a>
-<span class="sourceLineNo">732</span>          totalSize += fileInfo.getSecond();<a name="line.732"></a>
-<span class="sourceLineNo">733</span>        }<a name="line.733"></a>
-<span class="sourceLineNo">734</span>      }<a name="line.734"></a>
-<span class="sourceLineNo">735</span><a name="line.735"></a>
-<span class="sourceLineNo">736</span>      @Override<a name="line.736"></a>
-<span class="sourceLineNo">737</span>      public void close() { }<a name="line.737"></a>
-<span class="sourceLineNo">738</span><a name="line.738"></a>
-<span class="sourceLineNo">739</span>      @Override<a name="line.739"></a>
-<span class="sourceLineNo">740</span>      public BytesWritable getCurrentKey() { return files.get(index).getFirst(); }<a name="line.740"></a>
-<span class="sourceLineNo">741</span><a name="line.741"></a>
-<span class="sourceLineNo">742</span>      @Override<a name="line.742"></a>
-<span class="sourceLineNo">743</span>      public NullWritable getCurrentValue() { return NullWritable.get(); }<a name="line.743"></a>
-<span class="sourceLineNo">744</span><a name="line.744"></a>
-<span class="sourceLineNo">745</span>      @Override<a name="line.745"></a>
-<span class="sourceLineNo">746</span>      public float getProgress() { return (float)procSize / totalSize; }<a name="line.746"></a>
-<span class="sourceLineNo">747</span><a name="line.747"></a>
-<span class="sourceLineNo">748</span>      @Override<a name="line.748"></a>
-<span class="sourceLineNo">749</span>      public void initialize(InputSplit split, TaskAttemptContext tac) { }<a name="line.749"></a>
-<span class="sourceLineNo">750</span><a name="line.750"></a>
-<span class="sourceLineNo">751</span>      @Override<a name="line.751"></a>
-<span class="sourceLineNo">752</span>      public boolean nextKeyValue() {<a name="line.752"></a>
-<span class="sourceLineNo">753</span>        if (index &gt;= 0) {<a name="line.753"></a>
-<span class="sourceLineNo">754</span>          procSize += files.get(index).getSecond();<a name="line.754"></a>
-<span class="sourceLineNo">755</span>        }<a name="line.755"></a>
-<span class="sourceLineNo">756</span>        return(++index &lt; files.size());<a name="line.756"></a>
-<span class="sourceLineNo">757</span>      }<a name="line.757"></a>
-<span class="sourceLineNo">758</span>    }<a name="line.758"></a>
-<span class="sourceLineNo">759</span>  }<a name="line.759"></a>
-<span class="sourceLineNo">760</span><a name="line.760"></a>
-<span class="sourceLineNo">761</span>  // ==========================================================================<a name="line.761"></a>
-<span class="sourceLineNo">762</span>  //  Tool<a name="line.762"></a>
-<span class="sourceLineNo">763</span>  // ==========================================================================<a name="line.763"></a>
-<span class="sourceLineNo">764</span><a name="line.764"></a>
-<span class="sourceLineNo">765</span>  /**<a name="line.765"></a>
-<span class="sourceLineNo">766</span>   * Run Map-Reduce Job to perform the files copy.<a name="line.766"></a>
-<span class="sourceLineNo">767</span>   */<a name="line.767"></a>
-<span class="sourceLineNo">768</span>  private void runCopyJob(final Path inputRoot, final Path outputRoot,<a name="line.768"></a>
-<span class="sourceLineNo">769</span>      final String snapshotName, final Path snapshotDir, final boolean verifyChecksum,<a name="line.769"></a>
-<span class="sourceLineNo">770</span>      final String filesUser, final String filesGroup, final int filesMode,<a name="line.770"></a>
-<span class="sourceLineNo">771</span>      final int mappers, final int bandwidthMB)<a name="line.771"></a>
-<span class="sourceLineNo">772</span>          throws IOException, InterruptedException, ClassNotFoundException {<a name="line.772"></a>
-<span class="sourceLineNo">773</span>    Configuration conf = getConf();<a name="line.773"></a>
-<span class="sourceLineNo">774</span>    if (filesGroup != null) conf.set(CONF_FILES_GROUP, filesGroup);<a name="line.774"></a>
-<span class="sourceLineNo">775</span>    if (filesUser != null) conf.set(CONF_FILES_USER, filesUser);<a name="line.775"></a>
-<span class="sourceLineNo">776</span>    if (mappers &gt; 0) {<a name="line.776"></a>
-<span class="sourceLineNo">777</span>      conf.setInt(CONF_NUM_SPLITS, mappers);<a name="line.777"></a>
-<span class="sourceLineNo">778</span>      conf.setInt(MR_NUM_MAPS, mappers);<a name="line.778"></a>
-<span class="sourceLineNo">779</span>    }<a name="line.779"></a>
-<span class="sourceLineNo">780</span>    conf.setInt(CONF_FILES_MODE, filesMode);<a name="line.780"></a>
-<span class="sourceLineNo">781</span>    conf.setBoolean(CONF_CHECKSUM_VERIFY, verifyChecksum);<a name="line.781"></a>
-<span class="sourceLineNo">782</span>    conf.set(CONF_OUTPUT_ROOT, outputRoot.toString());<a name="line.782"></a>
-<span class="sourceLineNo">783</span>    conf.set(CONF_INPUT_ROOT, inputRoot.toString());<a name="line.783"></a>
-<span class="sourceLineNo">784</span>    conf.setInt(CONF_BANDWIDTH_MB, bandwidthMB);<a name="line.784"></a>
-<span class="sourceLineNo">785</span>    conf.set(CONF_SNAPSHOT_NAME, snapshotName);<a name="line.785"></a>
-<span class="sourceLineNo">786</span>    conf.set(CONF_SNAPSHOT_DIR, snapshotDir.toString());<a name="line.786"></a>
-<span class="sourceLineNo">787</span><a name="line.787"></a>
-<span class="sourceLineNo">788</span>    Job job = new Job(conf);<a name="line.788"></a>
-<span class="sourceLineNo">789</span>    job.setJobName("ExportSnapshot-" + snapshotName);<a name="line.789"></a>
-<span class="sourceLineNo">790</span>    job.setJarByClass(ExportSnapshot.class);<a name="line.790"></a>
-<span class="sourceLineNo">791</span>    TableMapReduceUtil.addDependencyJars(job);<a name="line.791"></a>
-<span class="sourceLineNo">792</span>    job.setMapperClass(ExportMapper.class);<a name="line.792"></a>
-<span class="sourceLineNo">793</span>    job.setInputFormatClass(ExportSnapshotInputFormat.class);<a name="line.793"></a>
-<span class="sourceLineNo">794</span>    job.setOutputFormatClass(NullOutputFormat.class);<a name="line.794"></a>
-<span class="sourceLineNo">795</span>    job.setMapSpeculativeExecution(false);<a name="line.795"></a>
-<span class="sourceLineNo">796</span>    job.setNumReduceTasks(0);<a name="line.796"></a>
-<span class="sourceLineNo">797</span><a name="line.797"></a>
-<span class="sourceLineNo">798</span>    // Acquire the delegation Tokens<a name="line.798"></a>
-<span class="sourceLineNo">799</span>    Configuration srcConf = HBaseConfiguration.createClusterConf(conf, null, CONF_SOURCE_PREFIX);<a name="line.799"></a>
-<span class="sourceLineNo">800</span>    TokenCache.obtainTokensForNamenodes(job.getCredentials(),<a name="line.800"></a>
-<span class="sourceLineNo">801</span>      new Path[] { inputRoot }, srcConf);<a name="line.801"></a>
-<span class="sourceLineNo">802</span>    Configuration destConf = HBaseConfiguration.createClusterConf(conf, null, CONF_DEST_PREFIX);<a name="line.802"></a>
-<span class="sourceLineNo">803</span>    TokenCache.obtainTokensForNamenodes(job.getCredentials(),<a name="line.803"></a>
-<span class="sourceLineNo">804</span>        new Path[] { outputRoot }, destConf);<a name="line.804"></a>
-<span class="sourceLineNo">805</span><a name="line.805"></a>
-<span class="sourceLineNo">806</span>    // Run the MR Job<a name="line.806"></a>
-<span class="sourceLineNo">807</span>    if (!job.waitForCompletion(true)) {<a name="line.807"></a>
-<span class="sourceLineNo">808</span>      // TODO: Replace the fixed string with job.getStatus().getFailureInfo()<a name="line.808"></a>
-<span class="sourceLineNo">809</span>      // when it will be available on all the supported versions.<a name="line.809"></a>
-<span class="sourceLineNo">810</span>      throw new ExportSnapshotException("Copy Files Map-Reduce Job failed");<a name="line.810"></a>
-<span class="sourceLineNo">811</span>    }<a name="line.811"></a>
-<span class="sourceLineNo">812</span>  }<a name="line.812"></a>
-<span class="sourceLineNo">813</span><a name="line.813"></a>
-<span class="sourceLineNo">814</span>  private void verifySnapshot(final Configuration baseConf,<a name="line.814"></a>
-<span class="sourceLineNo">815</span>      final FileSystem fs, final Path rootDir, final Path snapshotDir) throws IOException {<a name="line.815"></a>
-<span class="sourceLineNo">816</span>    // Update the conf with the current root dir, since may be a different cluster<a name="line.816"></a>
-<span class="sourceLineNo">817</span>    Configuration conf = new Configuration(baseConf);<a name="line.817"></a>
-<span class="sourceLineNo">818</span>    FSUtils.setRootDir(conf, rootDir);<a name="line.818"></a>
-<span class="sourceLineNo">819</span>    FSUtils.setFsDefault(conf, FSUtils.getRootDir(conf));<a name="line.819"></a>
-<span class="sourceLineNo">820</span>    SnapshotDescription snapshotDesc = SnapshotDescriptionUtils.readSnapshotInfo(fs, snapshotDir);<a name="line.820"></a>
-<span class="sourceLineNo">821</span>    SnapshotReferenceUtil.verifySnapshot(conf, fs, snapshotDir, snapshotDesc);<a name="line.821"></a>
-<span class="sourceLineNo">822</span>  }<a name="line.822"></a>
-<span class="sourceLineNo">823</span><a name="line.823"></a>
-<span class="sourceLineNo">824</span>  /**<a name="line.824"></a>
-<span class="sourceLineNo">825</span>   * Set path ownership.<a name="line.825"></a>
-<span class="sourceLineNo">826</span>   */<a name="line.826"></a>
-<span class="sourceLineNo">827</span>  private void setOwner(final FileSystem fs, final Path path, final String user,<a name="line.827"></a>
-<span class="sourceLineNo">828</span>      final String group, final boolean recursive) throws IOException {<a name="line.828"></a>
-<span class="sourceLineNo">829</span>    if (user != null || group != null) {<a name="line.829"></a>
-<span class="sourceLineNo">830</span>      if (recursive &amp;&amp; fs.isDirectory(path)) {<a name="line.830"></a>
-<span class="sourceLineNo">831</span>        for (FileStatus child : fs.listStatus(path)) {<a name="line.831"></a>
-<span class="sourceLineNo">832</span>          setOwner(fs, child.getPath(), user, group, recursive);<a name="line.832"></a>
-<span class="sourceLineNo">833</span>        }<a name="line.833"></a>
-<span class="sourceLineNo">834</span>      }<a name="line.834"></a>
-<span class="sourceLineNo">835</span>      fs.setOwner(path, user, group);<a name="line.835"></a>
-<span class="sourceLineNo">836</span>    }<a name="line.836"></a>
-<span class="sourceLineNo">837</span>  }<a name="line.837"></a>
-<span class="sourceLineNo">838</span><a name="line.838"></a>
-<span class="sourceLineNo">839</span>  /**<a name="line.839"></a>
-<span class="sourceLineNo">840</span>   * Set path permission.<a name="line.840"></a>
-<span class="sourceLineNo">841</span>   */<a name="line.841"></a>
-<span class="sourceLineNo">842</span>  private void setPermission(final FileSystem fs, final Path path, final short filesMode,<a name="line.842"></a>
-<span class="sourceLineNo">843</span>      final boolean recursive) throws IOException {<a name="line.843"></a>
-<span class="sourceLineNo">844</span>    if (filesMode &gt; 0) {<a name="line.844"></a>
-<span class="sourceLineNo">845</span>      FsPermission perm = new FsPermission(filesMode);<a name="line.845"></a>
-<span class="sourceLineNo">846</span>      if (recursive &amp;&amp; fs.isDirectory(path)) {<a name="line.846"></a>
-<span class="sourceLineNo">847</span>        for (FileStatus child : fs.listStatus(path)) {<a name="line.847"></a>
-<span class="sourceLineNo">848</span>          setPermission(fs, child.getPath(), filesMode, recursive);<a name="line.848"></a>
-<span class="sourceLineNo">849</span>        }<a name="line.849"></a>
-<span class="sourceLineNo">850</span>      }<a name="line.850"></a>
-<span class="sourceLineNo">851</span>      fs.setPermission(path, perm);<a name="line.851"></a>
-<span class="sourceLineNo">852</span>    }<a name="line.852"></a>
-<span class="sourceLineNo">853</span>  }<a name="line.853"></a>
-<span class="sourceLineNo">854</span><a name="line.854"></a>
-<span class="sourceLineNo">855</span>  /**<a name="line.855"></a>
-<span class="sourceLineNo">856</span>   * Execute the export snapshot by copying the snapshot metadata, hfiles and wals.<a name="line.856"></a>
-<span class="sourceLineNo">857</span>   * @return 0 on success, and != 0 upon failure.<a name="line.857"></a>
-<span class="sourceLineNo">858</span>   */<a name="line.858"></a>
-<span class="sourceLineNo">859</span>  @Override<a name="line.859"></a>
-<span class="sourceLineNo">860</span>  public int run(String[] args) throws IOException {<a name="line.860"></a>
-<span class="sourceLineNo">861</span>    boolean verifyTarget = true;<a name="line.861"></a>
-<span class="sourceLineNo">862</span>    boolean verifyChecksum = true;<a name="line.862"></a>
-<span class="sourceLineNo">863</span>    String snapshotName = null;<a name="line.863"></a>
-<span class="sourceLineNo">864</span>    String targetName = null;<a name="line.864"></a>
-<span class="sourceLineNo">865</span>    boolean overwrite = false;<a name="line.865"></a>
-<span class="sourceLineNo">866</span>    String filesGroup = null;<a name="line.866"></a>
-<span class="sourceLineNo">867</span>    String filesUser = null;<a name="line.867"></a>
-<span class="sourceLineNo">868</span>    Path outputRoot = null;<a name="line.868"></a>
-<span class="sourceLineNo">869</span>    int bandwidthMB = Integer.MAX_VALUE;<a name="line.869"></a>
-<span class="sourceLineNo">870</span>    int filesMode = 0;<a name="line.870"></a>
-<span class="sourceLineNo">871</span>    int mappers = 0;<a name="line.871"></a>
-<span class="sourceLineNo">872</span><a name="line.872"></a>
-<span class="sourceLineNo">873</span>    Configuration conf = getConf();<a name="line.873"></a>
-<span class="sourceLineNo">874</span>    Path inputRoot = FSUtils.getRootDir(conf);<a name="line.874"></a>
-<span class="sourceLineNo">875</span><a name="line.875"></a>
-<span class="sourceLineNo">876</span>    // Process command line args<a name="line.876"></a>
-<span class="sourceLineNo">877</span>    for (int i = 0; i &lt; args.length; i++) {<a name="line.877"></a>
-<span class="sourceLineNo">878</span>      String cmd = args[i];<a name="line.878"></a>
-<span class="sourceLineNo">879</span>      if (cmd.equals("-snapshot")) {<a name="line.879"></a>
-<span class="sourceLineNo">880</span>        snapshotName = args[++i];<a name="line.880"></a>
-<span class="sourceLineNo">881</span>      } else if (cmd.equals("-target")) {<a name="line.881"></a>
-<span class="sourceLineNo">882</span>        targetName = args[++i];<a name="line.882"></a>
-<span class="sourceLineNo">883</span>      } else if (cmd.equals("-copy-to")) {<a name="line.883"></a>
-<span class="sourceLineNo">884</span>        outputRoot = new Path(args[++i]);<a name="line.884"></a>
-<span class="sourceLineNo">885</span>      } else if (cmd.equals("-copy-from")) {<a name="line.885"></a>
-<span class="sourceLineNo">886</span>        inputRoot = new Path(args[++i]);<a name="line.886"></a>
-<span class="sourceLineNo">887</span>        FSUtils.setRootDir(conf, inputRoot);<a name="line.887"></a>
-<span class="sourceLineNo">888</span>      } else if (cmd.equals("-no-checksum-verify")) {<a name="line.888"></a>
-<span class="sourceLineNo">889</span>        verifyChecksum = false;<a name="line.889"></a>
-<span class="sourceLineNo">890</span>      } else if (cmd.equals("-no-target-verify")) {<a name="line.890"></a>
-<span class="sourceLineNo">891</span>        verifyTarget = false;<a name="line.891"></a>
-<span class="sourceLineNo">892</span>      } else if (cmd.equals("-mappers")) {<a name="line.892"></a>
-<span class="sourceLineNo">893</span>        mappers = Integer.parseInt(args[++i]);<a name="line.893"></a>
-<span class="sourceLineNo">894</span>      } else if (cmd.equals("-chuser")) {<a name="line.894"></a>
-<span class="sourceLineNo">895</span>        filesUser = args[++i];<a name="line.895"></a>
-<span class="sourceLineNo">896</span>      } else if (cmd.equals("-chgroup")) {<a name="line.896"></a>
-<span class="sourceLineNo">897</span>        filesGroup = args[++i];<a name="line.897"></a>
-<span class="sourceLineNo">898</span>      } else if (cmd.equals("-bandwidth")) {<a name="line.898"></a>
-<span class="sourceLineNo">899</span>        bandwidthMB = Integer.parseInt(args[++i]);<a name="line.899"></a>
-<span class="sourceLineNo">900</span>      } else if (cmd.equals("-chmod")) {<a name="line.900"></a>
-<span class="sourceLineNo">901</span>        filesMode = Integer.parseInt(args[++i], 8);<a name="line.901"></a>
-<span class="sourceLineNo">902</span>      } else if (cmd.equals("-overwrite")) {<a name="line.902"></a>
-<span class="sourceLineNo">903</span>        overwrite = true;<a name="line.903"></a>
-<span class="sourceLineNo">904</span>      } else if (cmd.equals("-h") || cmd.equals("--help")) {<a name="line.904"></a>
-<span class="sourceLineNo">905</span>        printUsageAndExit();<a name="line.905"></a>
-<span class="sourceLineNo">906</span>      } else {<a name="line.906"></a>
-<span class="sourceLineNo">907</span>        System.err.println("UNEXPECTED: " + cmd);<a name="line.907"></a>
-<span class="sourceLineNo">908</span>        printUsageAndExit();<a name="line.908"></a>
-<span class="sourceLineNo">909</span>      }<a name="line.909"></a>
-<span class="sourceLineNo">910</span>    }<a name="line.910"></a>
-<span class="sourceLineNo">911</span><a name="line.911"></a>
-<span class="sourceLineNo">912</span>    // Check user options<a name="line.912"></a>
-<span class="sourceLineNo">913</span>    if (snapshotName == null) {<a name="line.913"></a>
-<span class="sourceLineNo">914</span>      System.err.println("Snapshot name not provided.");<a name="line.914"></a>
-<span class="sourceLineNo">915</span>      printUsageAndExit();<a name="line.915"></a>
-<span class="sourceLineNo">916</span>    }<a name="line.916"></a>
-<span class="sourceLineNo">917</span><a name="line.917"></a>
-<span class="sourceLineNo">918</span>    if (outputRoot == null) {<a name="line.918"></a>
-<span class="sourceLineNo">919</span>      System.err.println("Destination file-system not provided.");<a name="line.919"></a>
-<span class="sourceLineNo">920</span>      printUsageAndExit();<a name="line.920"></a>
-<span class="sourceLineNo">921</span>    }<a name="line.921"></a>
-<span class="sourceLineNo">922</span><a name="line.922"></a>
-<span class="sourceLineNo">923</span>    if (targetName == null) {<a name="line.923"></a>
-<span class="sourceLineNo">924</span>      targetName = snapshotName;<a name="line.924"></a>
-<span class="sourceLineNo">925</span>    }<a name="line.925"></a>
-<span class="sourceLineNo">926</span><a name="line.926"></a>
-<span class="sourceLineNo">927</span>    Configuration srcConf = HBaseConfiguration.createClusterConf(conf, null, CONF_SOURCE_PREFIX);<a name="line.927"></a>
-<span class="sourceLineNo">928</span>    srcConf.setBoolean("fs." + inputRoot.toUri().getScheme() + ".impl.disable.cache", true);<a name="line.928"></a>
-<span class="sourceLineNo">929</span>    FileSystem inputFs = FileSystem.get(inputRoot.toUri(), srcConf);<a name="line.929"></a>
-<span class="sourceLineNo">930</span>    LOG.debug("inputFs=" + inputFs.getUri().toString() + " inputRoot=" + inputRoot);<a name="line.930"></a>
-<span class="sourceLineNo">931</span>    Configuration destConf = HBaseConfiguration.createClusterConf(conf, null, CONF_DEST_PREFIX);<a name="line.931"></a>
-<span class="sourceLineNo">932</span>    destConf.setBoolean("fs." + outputRoot.toUri().getScheme() + ".impl.disable.cache", true);<a name="line.932"></a>
-<span class="sourceLineNo">933</span>    FileSystem outputFs = FileSystem.get(outputRoot.toUri(), destConf);<a name="line.933"></a>
-<span class="sourceLineNo">934</span>    LOG.debug("outputFs=" + outputFs.getUri().toString() + " outputRoot=" + outputRoot.toString());<a name="line.934"></a>
-<span class="sourceLineNo">935</span><a name="line.935"></a>
-<span class="sourceLineNo">936</span>    boolean skipTmp = conf.getBoolean(CONF_SKIP_TMP, false);<a name="line.936"></a>
-<span class="sourceLineNo">937</span><a name="line.937"></a>
-<span class="sourceLineNo">938</span>    Path snapshotDir = SnapshotDescriptionUtils.getCompletedSnapshotDir(snapshotName, inputRoot);<a name="line.938"></a>
-<span class="sourceLineNo">939</span>    Path snapshotTmpDir = SnapshotDescriptionUtils.getWorkingSnapshotDir(targetName, outputRoot);<a name="line.939"></a>
-<span class="sourceLineNo">940</span>    Path outputSnapshotDir = SnapshotDescriptionUtils.getCompletedSnapshotDir(targetName, outputRoot);<a name="line.940"></a>
-<span class="sourceLineNo">941</span>    Path initialOutputSnapshotDir = skipTmp ? outputSnapshotDir : snapshotTmpDir;<a name="line.941"></a>
-<span class="sourceLineNo">942</span><a name="line.942"></a>
-<span class="sourceLineNo">943</span>    // Check if the snapshot already exists<a name="line.943"></a>
-<span class="sourceLineNo">944</span>    if (outputFs.exists(outputSnapshotDir)) {<a name="line.944"></a>
-<span class="sourceLineNo">945</span>      if (overwrite) {<a name="line.945"></a>
-<span class="sourceLineNo">946</span>        if (!outputFs.delete(outputSnapshotDir, true)) {<a name="line.946"></a>
-<span class="sourceLineNo">947</span>          System.err.println("Unable to remove existing snapshot directory: " + outputSnapshotDir);<a name="line.947"></a>
-<span class="sourceLineNo">948</span>          return 1;<a name="line.948"></a>
-<span class="sourceLineNo">949</span>        }<a name="line.949"></a>
-<span class="sourceLineNo">950</span>      } else {<a name="line.950"></a>
-<span class="sourceLineNo">951</span>        System.err.println("The snapshot '" + targetName +<a name="line.951"></a>
-<span class="sourceLineNo">952</span>          "' already exists in the destination: " + outputSnapshotDir);<a name="line.952"></a>
-<span class="sourceLineNo">953</span>        return 1;<a name="line.953"></a>
-<span class="sourceLineNo">954</span>      }<a name="line.954"></a>
-<span class="sourceLineNo">955</span>    }<a name="line.955"></a>
-<span class="sourceLineNo">956</span><a name="line.956"></a>
-<span class="sourceLineNo">957</span>    if (!skipTmp) {<a name="line.957"></a>
-<span class="sourceLineNo">958</span>      // Check if the snapshot already in-progress<a name="line.958"></a>
-<span class="sourceLineNo">959</span>      if (outputFs.exists(snapshotTmpDir)) {<a name="line.959"></a>
-<span class="sourceLineNo">960</span>        if (overwrite) {<a name="line.960"></a>
-<span class="sourceLineNo">961</span>          if (!outputFs.delete(snapshotTmpDir, true)) {<a name="line.961"></a>
-<span class="sourceLineNo">962</span>            System.err.println("Unable to remove existing snapshot tmp directory: "+snapshotTmpDir);<a name="line.962"></a>
-<span class="sourceLineNo">963</span>            return 1;<a name="line.963"></a>
-<span class="sourceLineNo">964</span>          }<a name="line.964"></a>
-<span class="sourceLineNo">965</span>        } else {<a name="line.965"></a>
-<span class="sourceLineNo">966</span>          System.err.println("A snapshot with the same name '"+ targetName +"' may be in-progress");<a name="line.966"></a>
-<span class="sourceLineNo">967</span>          System.err.println("Please check "+snapshotTmpDir+". If the snapshot has completed, ");<a name="line.967"></a>
-<span class="sourceLineNo">968</span>          System.err.println("consider removing "+snapshotTmpDir+" by using the -overwrite option");<a name="line.968"></a>
-<span class="sourceLineNo">969</span>          return 1;<a name="line.969"></a>
-<span class="sourceLineNo">970</span>        }<a name="line.970"></a>
-<span class="sourceLineNo">971</span>      }<a name="line.971"></a>
-<span class="sourceLineNo">972</span>    }<a name="line.972"></a>
-<span class="sourceLineNo">973</span><a name="line.973"></a>
-<span class="sourceLineNo">974</span>    // Step 1 - Copy fs1:/.snapshot/&lt;snapshot&gt; to  fs2:/.snapshot/.tmp/&lt;snapshot&gt;<a name="line.974"></a>
-<span class="sourceLineNo">975</span>    // The snapshot references must be copied before the hfiles otherwise the cleaner<a name="line.975"></a>
-<span class="sourceLineNo">976</span>    // will remove them because they are unreferenced.<a name="line.976"></a>
-<span class="sourceLineNo">977</span>    try {<a name="line.977"></a>
-<span class="sourceLineNo">978</span>      LOG.info("Copy Snapshot Manifest");<a name="line.978"></a>
-<span class="sourceLineNo">979</span>      FileUtil.copy(inputFs, snapshotDir, outputFs, initialOutputSnapshotDir, false, false, conf);<a name="line.979"></a>
-<span class="sourceLineNo">980</span>      if (filesUser != null || filesGroup != null) {<a name="line.980"></a>
-<span class="sourceLineNo">981</span>        setOwner(outputFs, snapshotTmpDir, filesUser, filesGroup, true);<a name="line.981"></a>
-<span class="sourceLineNo">982</span>      }<a name="line.982"></a>
-<span class="sourceLineNo">983</span>      if (filesMode &gt; 0) {<a name="line.983"></a>
-<span class="sourceLineNo">984</span>        setPermission(outputFs, snapshotTmpDir, (short)filesMode, true);<a name="line.984"></a>
-<span class="sourceLineNo">985</span>      }<a name="line.985"></a>
-<span class="sourceLineNo">986</span>    } catch (IOException e) {<a name="line.986"></a>
-<span class="sourceLineNo">987</span>      throw new ExportSnapshotException("Failed to copy the snapshot directory: from=" +<a name="line.987"></a>
-<span class="sourceLineNo">988</span>        snapshotDir + " to=" + initialOutputSnapshotDir, e);<a name="line.988"></a>
-<span class="sourceLineNo">989</span>    }<a name="line.989"></a>
-<span class="sourceLineNo">990</span><a name="line.990"></a>
-<span class="sourceLineNo">991</span>    // Write a new .snapshotinfo if the target name is different from the source name<a name="line.991"></a>
-<span class="sourceLineNo">992</span>    if (!targetName.equals(snapshotName)) {<a name="line.992"></a>
-<span class="sourceLineNo">993</span>      SnapshotDescription snapshotDesc =<a name="line.993"></a>
-<span class="sourceLineNo">994</span>        SnapshotDescriptionUtils.readSnapshotInfo(inputFs, snapshotDir)<a name="line.994"></a>
-<span class="sourceLineNo">995</span>          .toBuilder()<a name="line.995"></a>
-<span class="sourceLineNo">996</span>          .setName(targetName)<a name="line.996"></a>
-<span class="sourceLineNo">997</span>          .build();<a name="line.997"></a>
-<span class="sourceLineNo">998</span>      SnapshotDescriptionUtils.writeSnapshotInfo(snapshotDesc, snapshotTmpDir, outputFs);<a name="line.998"></a>
-<span class="sourceLineNo">999</span>    }<a name="line.999"></a>
-<span class="sourceLineNo">1000</span><a name="line.1000"></a>
-<span class="sourceLineNo">1001</span>    // Step 2 - Start MR Job to copy files<a name="line.1001"></a>
-<span class="sourceLineNo">1002</span>    // The snapshot references must be copied before the files otherwise the files gets removed<a name="line.1002"></a>
-<span class="sourceLineNo">1003</span>    // by the HFileArchiver, since they have no references.<a name="line.1003"></a>
-<span class="sourceLineNo">1004</span>    try {<a name="line.1004"></a>
-<span class="sourceLineNo">1005</span>      runCopyJob(inputRoot, outputRoot, snapshotName, snapshotDir, verifyChecksum,<a name="line.1005"></a>
-<span class="sourceLineNo">1006</span>                 filesUser, filesGroup, filesMode, mappers, bandwidthMB);<a name="line.1006"></a>
-<span class="sourceLineNo">1007</span><a name="line.1007"></a>
-<span class="sourceLineNo">1008</span>      LOG.info("Finalize the Snapshot Export");<a name="line.1008"></a>
-<span class="sourceLineNo">1009</span>      if (!skipTmp) {<a name="line.1009"></a>
-<span class="sourceLineNo">1010</span>        // Step 3 - Rename fs2:/.snapshot/.tmp/&lt;snapshot&gt; fs2:/.snapshot/&lt;snapshot&gt;<a name="line.1010"></a>
-<span class="sourceLineNo">1011</span>        if (!outputFs.rename(snapshotTmpDir, outputSnapshotDir)) {<a name="line.1011"></a>
-<span class="sourceLineNo">1012</span>          throw new ExportSnapshotException("Unable to rename snapshot directory from=" +<a name="line.1012"></a>
-<span class="sourceLineNo">1013</span>            snapshotTmpDir + " to=" + outputSnapshotDir);<a name="line.1013"></a>
-<span class="sourceLineNo">1014</span>        }<a name="line.1014"></a>
-<span class="sourceLineNo">1015</span>      }<a name="line.1015"></a>
-<span class="sourceLineNo">1016</span><a name="line.1016"></a>
-<span class="sourceLineNo">1017</span>      // Step 4 - Verify snapshot integrity<a name="line.1017"></a>
-<span class="sourceLineNo">1018</span>      if (verifyTarget) {<a name="line.1018"></a>
-<span class="sourceLineNo">1019</span>        LOG.info("Verify snapshot integrity");<a name="line.1019"></a>
-<span class="sourceLineNo">1020</span>        verifySnapshot(destConf, outputFs, outputRoot, outputSnapshotDir);<a name="line.1020"></a>
-<span class="sourceLineNo">1021</span>      }<a name="line.1021"></a>
-<span class="sourceLineNo">1022</span><a name="line.1022"></a>
-<span class="sourceLineNo">1023</span>      LOG.info("Export Completed: " + targetName);<a name="line.1023"></a>
-<span class="sourceLineNo">1024</span>      return 0;<a name="line.1024"></a>
-<span class="sourceLineNo">1025</span>    } catch (Exception e) {<a name="line.1025"></a>
-<span class="sourceLineNo">1026</span>      LOG.error("Snapshot export failed", e);<a name="line.1026"></a>
-<span class="sourceLineNo">1027</span>      if (!skipTmp) {<a name="line.1027"></a>
-<span class="sourceLineNo">1028</span>        outputFs.delete(snapshotTmpDir, true);<a name="line.1028"></a>
-<span class="sourceLineNo">1029</span>      }<a name="line.1029"></a>
-<span class="sourceLineNo">1030</span>      outputFs.delete(outputSnapshotDir, true);<a name="line.1030"></a>
-<span class="sourceLineNo">1031</span>      return 1;<a name="line.1031"></a>
-<span class="sourceLineNo">1032</span>    } finally {<a name="line.1032"></a>
-<span class="sourceLineNo">1033</span>      IOUtils.closeStream(inputFs);<a name="line.1033"></a>
-<span class="sourceLineNo">1034</span>      IOUtils.closeStream(outputFs);<a name="line.1034"></a>
-<span class="sourceLineNo">1035</span>    }<a name="line.1035"></a>
-<span class="sourceLineNo">1036</span>  }<a name="line.1036"></a>
-<span class="sourceLineNo">1037</span><a name="line.1037"></a>
-<span class="sourceLineNo">1038</span>  // ExportSnapshot<a name="line.1038"></a>
-<span class="sourceLineNo">1039</span>  private void printUsageAndExit() {<a name="line.1039"></a>
-<span class="sourceLineNo">1040</span>    System.err.printf("Usage: bin/hbase %s [options]%n", getClass().getName());<a name="line.1040"></a>
-<span class="sourceLineNo">1041</span>    System.err.println(" where [options] are:");<a name="line.1041"></a>
-<span class="sourceLineNo">1042</span>    System.err.println("  -h|-help                Show this help and exit.");<a name="line.1042"></a>
-<span class="sourceLineNo">1043</span>    System.err.println("  -snapshot NAME          Snapshot to restore.");<a name="line.1043"></a>
-<span class="sourceLineNo">1044</span>    System.err.println("  -copy-to NAME           Remote destination hdfs://");<a name="line.1044"></a>
-<span class="sourceLineNo">1045</span>    System.err.println("  -copy-from NAME         Input folder hdfs:// (default hbase.rootdir)");<a name="line.1045"></a>
-<span class="sourceLineNo">1046</span>    System.err.println("  -no-checksum-verify     Do not verify checksum, use name+length only.");<a name="line.1046"></a>
-<span class="sourceLineNo">1047</span>    System.err.println("  -no-target-verify       Do not verify the integrity of the \\" +<a name="line.1047"></a>
-<span class="sourceLineNo">1048</span>        "exported snapshot.");<a name="line.1048"></a>
-<span class="sourceLineNo">1049</span>    System.err.println("  -overwrite              Rewrite the snapshot manifest if already exists");<a name="line.1049"></a>
-<span class="sourceLineNo">1050</span>    System.err.println("  -chuser USERNAME        Change the owner of the files " +<a name="line.1050"></a>
-<span class="sourceLineNo">1051</span>        "to the specified one.");<a name="line.1051"></a>
-<span class="sourceLineNo">1052</span>    System.err.println("  -chgroup GROUP          Change the group of the files to " +<a name="line.1052"></a>
-<span class="sourceLineNo">1053</span>        "the specified one.");<a name="line.1053"></a>
-<span class="sourceLineNo">1054</span>    System.err.println("  -chmod MODE             Change the permission of the files " +<a name="line.1054"></a>
-<span class="sourceLineNo">1055</span>        "to the specified one.");<a name="line.1055"></a>
-<span class="sourceLineNo">1056</span>    System.err.println("  -mappers                Number of mappers to use during the " +<a name="line.1056"></a>
-<span class="sourceLineNo">1057</span>        "copy (mapreduce.job.maps).");<a name="line.1057"></a>
-<span class="sourceLineNo">1058</span>    System.err.println("  -bandwidth              Limit bandwidth to this value in MB/second.");<a name="line.1058"></a>
-<span class="sourceLineNo">1059</span>    System.err.println();<a name="line.1059"></a>
-<span class="sourceLineNo">1060</span>    System.err.println("Examples:");<a name="line.1060"></a>
-<span class="sourceLineNo">1061</span>    System.err.println("  hbase " + getClass().getName() + " \\");<a name="line.1061"></a>
-<span class="sourceLineNo">1062</span>    System.err.println("    -snapshot MySnapshot -copy-to hdfs://srv2:8082/hbase \\");<a name="line.1062"></a>
-<span class="sourceLineNo">1063</span>    System.err.println("    -chuser MyUser -chgroup MyGroup -chmod 700 -mappers 16");<a name="line.1063"></a>
-<span class="sourceLineNo">1064</span>    System.err.println();<a name="line.1064"></a>
-<span class="sourceLineNo">1065</span>    System.err.println("  hbase " + getClass().getName() + " \\");<a name="line.1065"></a>
-<span class="sourceLineNo">1066</span>    System.err.println("    -snapshot MySnapshot -copy-from hdfs://srv2:8082/hbase \\");<a name="line.1066"></a>
-<span class="sourceLineNo">1067</span>    System.err.println("    -copy-to hdfs://srv1:50070/hbase \\");<a name="line.1067"></a>
-<span class="sourceLineNo">1068</span>    System.exit(1);<a name="line.1068"></a>
-<span class="sourceLineNo">1069</span>  }<a name="line.1069"></a>
-<span class="sourceLineNo">1070</span><a name="line.1070"></a>
-<span class="sourceLineNo">1071</span>  /**<a name="line.1071"></a>
-<span class="sourceLineNo">1072</span>   * The guts of the {@link #main} method.<a name="line.1072"></a>
-<span class="sourceLineNo">1073</span>   * Call this method to avoid the {@link #main(String[])} System.exit.<a name="line.1073"></a>
-<span class="sourceLineNo">1074</span>   * @param args<a name="line.1074"></a>
-<span class="sourceLineNo">1075</span>   * @return errCode<a name="line.1075"></a>
-<span class="sourceLineNo">1076</span>   * @throws Exception<a name="line.1076"></a>
-<span class="sourceLineNo">1077</span>   */<a name="line.1077"></a>
-<span class="sourceLineNo">1078</span>  static int innerMain(final Configuration conf, final String [] args) throws Exception {<a name="line.1078"></a>
-<span class="sourceLineNo">1079</span>    return ToolRunner.run(conf, new ExportSnapshot(), args);<a name="line.1079"></a>
-<span class="sourceLineNo">1080</span>  }<a name="line.1080"></a>
-<span class="sourceLineNo">1081</span><a name="line.1081"></a>
-<span class="sourceLineNo">1082</span>  public static void main(String[] args) throws Exception {<a name="line.1082"></a>
-<span class="sourceLineNo">1083</span>    System.exit(innerMain(HBaseConfiguration.create(), args));<a name="line.1083"></a>
-<span class="sourceLineNo">1084</span>  }<a name="line.1084"></a>
-<span class="sourceLineNo">1085</span>}<a name="line.1085"></a>
+<span class="sourceLineNo">646</span>      Path snapshotDir = new Path(conf.get(CONF_SNAPSHOT_DIR));<a name="line.646"></a>
+<span class="sourceLineNo">647</span>      FileSystem fs = FileSystem.get(snapshotDir.toUri(), conf);<a name="line.647"></a>
+<span class="sourceLineNo">648</span><a name="line.648"></a>
+<span class="sourceLineNo">649</span>      List&lt;Pair&lt;SnapshotFileInfo, Long&gt;&gt; snapshotFiles = getSnapshotFiles(conf, fs, snapshotDir);<a name="line.649"></a>
+<span class="sourceLineNo">650</span>      int mappers = conf.getInt(CONF_NUM_SPLITS, 0);<a name="line.650"></a>
+<span class="sourceLineNo">651</span>      if (mappers == 0 &amp;&amp; snapshotFiles.size() &gt; 0) {<a name="line.651"></a>
+<span class="sourceLineNo">652</span>        mappers = 1 + (snapshotFiles.size() / conf.getInt(CONF_MAP_GROUP, 10));<a name="line.652"></a>
+<span class="sourceLineNo">653</span>        mappers = Math.min(mappers, snapshotFiles.size());<a name="line.653"></a>
+<span class="sourceLineNo">654</span>        conf.setInt(CONF_NUM_SPLITS, mappers);<a name="line.654"></a>
+<span class="sourceLineNo">655</span>        conf.setInt(MR_NUM_MAPS, mappers);<a name="line.655"></a>
+<span class="sourceLineNo">656</span>      }<a name="line.656"></a>
+<span class="sourceLineNo">657</span><a name="line.657"></a>
+<span class="sourceLineNo">658</span>      List&lt;List&lt;Pair&lt;SnapshotFileInfo, Long&gt;&gt;&gt; groups = getBalancedSplits(snapshotFiles, mappers);<a name="line.658"></a>
+<span class="sourceLineNo">659</span>      List&lt;InputSplit&gt; splits = new ArrayList(groups.size());<a name="line.659"></a>
+<span class="sourceLineNo">660</span>      for (List&lt;Pair&lt;SnapshotFileInfo, Long&gt;&gt; files: groups) {<a name="line.660"></a>
+<span class="sourceLineNo">661</span>        splits.add(new ExportSnapshotInputSplit(files));<a name="line.661"></a>
+<span class="sourceLineNo">662</span>      }<a name="line.662"></a>
+<span class="sourceLineNo">663</span>      return splits;<a name="line.663"></a>
+<span class="sourceLineNo">664</span>    }<a name="line.664"></a>
+<span class="sourceLineNo">665</span><a name="line.665"></a>
+<span class="sourceLineNo">666</span>    private static class ExportSnapshotInputSplit extends InputSplit implements Writable {<a name="line.666"></a>
+<span class="sourceLineNo">667</span>      private List&lt;Pair&lt;BytesWritable, Long&gt;&gt; files;<a name="line.667"></a>
+<span class="sourceLineNo">668</span>      private long length;<a name="line.668"></a>
+<span class="sourceLineNo">669</span><a name="line.669"></a>
+<span class="sourceLineNo">670</span>      public ExportSnapshotInputSplit() {<a name="line.670"></a>
+<span class="sourceLineNo">671</span>        this.files = null;<a name="line.671"></a>
+<span class="sourceLineNo">672</span>      }<a name="line.672"></a>
+<span class="sourceLineNo">673</span><a name="line.673"></a>
+<span class="sourceLineNo">674</span>      public ExportSnapshotInputSplit(final List&lt;Pair&lt;SnapshotFileInfo, Long&gt;&gt; snapshotFiles) {<a name="line.674"></a>
+<span class="sourceLineNo">675</span>        this.files = new ArrayList(snapshotFiles.size());<a name="line.675"></a>
+<span class="sourceLineNo">676</span>        for (Pair&lt;SnapshotFileInfo, Long&gt; fileInfo: snapshotFiles) {<a name="line.676"></a>
+<span class="sourceLineNo">677</span>          this.files.add(new Pair&lt;BytesWritable, Long&gt;(<a name="line.677"></a>
+<span class="sourceLineNo">678</span>            new BytesWritable(fileInfo.getFirst().toByteArray()), fileInfo.getSecond()));<a name="line.678"></a>
+<span class="sourceLineNo">679</span>          this.length += fileInfo.getSecond();<a name="line.679"></a>
+<span class="sourceLineNo">680</span>        }<a name="line.680"></a>
+<span class="sourceLineNo">681</span>      }<a name="line.681"></a>
+<span class="sourceLineNo">682</span><a name="line.682"></a>
+<span class="sourceLineNo">683</span>      private List&lt;Pair&lt;BytesWritable, Long&gt;&gt; getSplitKeys() {<a name="line.683"></a>
+<span class="sourceLineNo">684</span>        return files;<a name="line.684"></a>
+<span class="sourceLineNo">685</span>      }<a name="line.685"></a>
+<span class="sourceLineNo">686</span><a name="line.686"></a>
+<span class="sourceLineNo">687</span>      @Override<a name="line.687"></a>
+<span class="sourceLineNo">688</span>      public long getLength() throws IOException, InterruptedException {<a name="line.688"></a>
+<span class="sourceLineNo">689</span>        return length;<a name="line.689"></a>
+<span class="sourceLineNo">690</span>      }<a name="line.690"></a>
+<span class="sourceLineNo">691</span><a name="line.691"></a>
+<span class="sourceLineNo">692</span>      @Override<a name="line.692"></a>
+<span class="sourceLineNo">693</span>      public String[] getLocations() throws IOException, InterruptedException {<a name="line.693"></a>
+<span class="sourceLineNo">694</span>        return new String[] {};<a name="line.694"></a>
+<span class="sourceLineNo">695</span>      }<a name="line.695"></a>
+<span class="sourceLineNo">696</span><a name="line.696"></a>
+<span class="sourceLineNo">697</span>      @Override<a name="line.697"></a>
+<span class="sourceLineNo">698</span>      public void readFields(DataInput in) throws IOException {<a name="line.698"></a>
+<span class="sourceLineNo">699</span>        int count = in.readInt();<a name="line.699"></a>
+<span class="sourceLineNo">700</span>        files = new ArrayList&lt;Pair&lt;BytesWritable, Long&gt;&gt;(count);<a name="line.700"></a>
+<span class="sourceLineNo">701</span>        length = 0;<a name="line.701"></a>
+<span class="sourceLineNo">702</span>        for (int i = 0; i &lt; count; ++i) {<a name="line.702"></a>
+<span class="sourceLineNo">703</span>          BytesWritable fileInfo = new BytesWritable();<a name="line.703"></a>
+<span class="sourceLineNo">704</span>          fileInfo.readFields(in);<a name="line.704"></a>
+<span class="sourceLineNo">705</span>          long size = in.readLong();<a name="line.705"></a>
+<span class="sourceLineNo">706</span>          files.add(new Pair&lt;BytesWritable, Long&gt;(fileInfo, size));<a name="line.706"></a>
+<span class="sourceLineNo">707</span>          length += size;<a name="line.707"></a>
+<span class="sourceLineNo">708</span>        }<a name="line.708"></a>
+<span class="sourceLineNo">709</span>      }<a name="line.709"></a>
+<span class="sourceLineNo">710</span><a name="line.710"></a>
+<span class="sourceLineNo">711</span>      @Override<a name="line.711"></a>
+<span class="sourceLineNo">712</span>      public void write(DataOutput out) throws IOException {<a name="line.712"></a>
+<span class="sourceLineNo">713</span>        out.writeInt(files.size());<a name="line.713"></a>
+<span class="sourceLineNo">714</span>        for (final Pair&lt;BytesWritable, Long&gt; fileInfo: files) {<a name="line.714"></a>
+<span class="sourceLineNo">715</span>          fileInfo.getFirst().write(out);<a name="line.715"></a>
+<span class="sourceLineNo">716</span>          out.writeLong(fileInfo.getSecond());<a name="line.716"></a>
+<span class="sourceLineNo">717</span>        }<a name="line.717"></a>
+<span class="sourceLineNo">718</span>      }<a name="line.718"></a>
+<span class="sourceLineNo">719</span>    }<a name="line.719"></a>
+<span class="sourceLineNo">720</span><a name="line.720"></a>
+<span class="sourceLineNo">721</span>    private static class ExportSnapshotRecordReader<a name="line.721"></a>
+<span class="sourceLineNo">722</span>        extends RecordReader&lt;BytesWritable, NullWritable&gt; {<a name="line.722"></a>
+<span class="sourceLineNo">723</span>      private final List&lt;Pair&lt;BytesWritable, Long&gt;&gt; files;<a name="line.723"></a>
+<span class="sourceLineNo">724</span>      private long totalSize = 0;<a name="line.724"></a>
+<span class="sourceLineNo">725</span>      private long procSize = 0;<a name="line.725"></a>
+<span class="sourceLineNo">726</span>      private int index = -1;<a name="line.726"></a>
+<span class="sourceLineNo">727</span><a name="line.727"></a>
+<span class="sourceLineNo">728</span>      ExportSnapshotRecordReader(final List&lt;Pair&lt;BytesWritable, Long&gt;&gt; files) {<a name="line.728"></a>
+<span class="sourceLineNo">729</span>        this.files = files;<a name="line.729"></a>
+<span class="sourceLineNo">730</span>        for (Pair&lt;BytesWritable, Long&gt; fileInfo: files) {<a name="line.730"></a>
+<span class="sourceLineNo">731</span>          totalSize += fileInfo.getSecond();<a name="line.731"></a>
+<span class="sourceLineNo">732</span>        }<a name="line.732"></a>
+<span class="sourceLineNo">733</span>      }<a name="line.733"></a>
+<span class="sourceLineNo">734</span><a name="line.734"></a>
+<span class="sourceLineNo">735</span>      @Override<a name="line.735"></a>
+<span class="sourceLineNo">736</span>      public void close() { }<a name="line.736"></a>
+<span class="sourceLineNo">737</span><a name="line.737"></a>
+<span class="sourceLineNo">738</span>      @Override<a name="line.738"></a>
+<span class="sourceLineNo">739</span>      public BytesWritable getCurrentKey() { return files.get(index).getFirst(); }<a name="line.739"></a>
+<span class="sourceLineNo">740</span><a name="line.740"></a>
+<span class="sourceLineNo">741</span>      @Override<a name="line.741"></a>
+<span class="sourceLineNo">742</span>      public NullWritable getCurrentValue() { return NullWritable.get(); }<a name="line.742"></a>
+<span class="sourceLineNo">743</span><a name="line.743"></a>
+<span class="sourceLineNo">744</span>      @Override<a name="line.744"></a>
+<span class="sourceLineNo">745</span>      public float getProgress() { return (float)procSize / totalSize; }<a name="line.745"></a>
+<span class="sourceLineNo">746</span><a name="line.746"></a>
+<span class="sourceLineNo">747</span>      @Override<a name="line.747"></a>
+<span class="sourceLineNo">748</span>      public void initialize(InputSplit split, TaskAttemptContext tac) { }<a name="line.748"></a>
+<span class="sourceLineNo">749</span><a name="line.749"></a>
+<span class="sourceLineNo">750</span>      @Override<a name="line.750"></a>
+<span class="sourceLineNo">751</span>      public boolean nextKeyValue() {<a name="line.751"></a>
+<span class="sourceLineNo">752</span>        if (index &gt;= 0) {<a name="line.752"></a>
+<span class="sourceLineNo">753</span>          procSize += files.get(index).getSecond();<a name="line.753"></a>
+<span class="sourceLineNo">754</span>        }<a name="line.754"></a>
+<span class="sourceLineNo">755</span>        return(++index &lt; files.size());<a name="line.755"></a>
+<span class="sourceLineNo">756</span>      }<a name="line.756"></a>
+<span class="sourceLineNo">757</span>    }<a name="line.757"></a>
+<span class="sourceLineNo">758</span>  }<a name="line.758"></a>
+<span class="sourceLineNo">759</span><a name="line.759"></a>
+<span class="sourceLineNo">760</span>  // ==========================================================================<a name="line.760"></a>
+<span class="sourceLineNo">761</span>  //  Tool<a name="line.761"></a>
+<span class="sourceLineNo">762</span>  // ==========================================================================<a name="line.762"></a>
+<span class="sourceLineNo">763</span><a name="line.763"></a>
+<span class="sourceLineNo">764</span>  /**<a name="line.764"></a>
+<span class="sourceLineNo">765</span>   * Run Map-Reduce Job to perform the files copy.<a name="line.765"></a>
+<span class="sourceLineNo">766</span>   */<a name="line.766"></a>
+<span class="sourceLineNo">767</span>  private void runCopyJob(final Path inputRoot, final Path outputRoot,<a name="line.767"></a>
+<span class="sourceLineNo">768</span>      final String snapshotName, final Path snapshotDir, final boolean verifyChecksum,<a name="line.768"></a>
+<span class="sourceLineNo">769</span>      final String filesUser, final String filesGroup, final int filesMode,<a name="line.769"></a>
+<span class="sourceLineNo">770</span>      final int mappers, final int bandwidthMB)<a name="line.770"></a>
+<span class="sourceLineNo">771</span>          throws IOException, InterruptedException, ClassNotFoundException {<a name="line.771"></a>
+<span class="sourceLineNo">772</span>    Configuration conf = getConf();<a name="line.772"></a>
+<span class="sourceLineNo">773</span>    if (filesGroup != null) conf.set(CONF_FILES_GROUP, filesGroup);<a name="line.773"></a>
+<span class="sourceLineNo">774</span>    if (filesUser != null) conf.set(CONF_FILES_USER, filesUser);<a name="line.774"></a>
+<span class="sourceLineNo">775</span>    if (mappers &gt; 0) {<a name="line.775"></a>
+<span class="sourceLineNo">776</span>      conf.setInt(CONF_NUM_SPLITS, mappers);<a name="line.776"></a>
+<span class="sourceLineNo">777</span>      conf.setInt(MR_NUM_MAPS, mappers);<a name="line.777"></a>
+<span class="sourceLineNo">778</span>    }<a name="line.778"></a>
+<span class="sourceLineNo">779</span>    conf.setInt(CONF_FILES_MODE, filesMode);<a name="line.779"></a>
+<span class="sourceLineNo">780</span>    conf.setBoolean(CONF_CHECKSUM_VERIFY, verifyChecksum);<a name="line.780"></a>
+<span class="sourceLineNo">781</span>    conf.set(CONF_OUTPUT_ROOT, outputRoot.toString());<a name="line.781"></a>
+<span class="sourceLineNo">782</span>    conf.set(CONF_INPUT_ROOT, inputRoot.toString());<a name="line.782"></a>
+<span class="sourceLineNo">783</span>    conf.setInt(CONF_BANDWIDTH_MB, bandwidthMB);<a name="line.783"></a>
+<span class="sourceLineNo">784</span>    conf.set(CONF_SNAPSHOT_NAME, snapshotName);<a name="line.784"></a>
+<span class="sourceLineNo">785</span>    conf.set(CONF_SNAPSHOT_DIR, snapshotDir.toString());<a name="line.785"></a>
+<span class="sourceLineNo">786</span><a name="line.786"></a>
+<span class="sourceLineNo">787</span>    Job job = new Job(conf);<a name="line.787"></a>
+<span class="sourceLineNo">788</span>    job.setJobName("ExportSnapshot-" + snapshotName);<a name="line.788"></a>
+<span class="sourceLineNo">789</span>    job.setJarByClass(ExportSnapshot.class);<a name="line.789"></a>
+<span class="sourceLineNo">790</span>    TableMapReduceUtil.addDependencyJars(job);<a name="line.790"></a>
+<span class="sourceLineNo">791</span>    job.setMapperClass(ExportMapper.class);<a name="line.791"></a>
+<span class="sourceLineNo">792</span>    job.setInputFormatClass(ExportSnapshotInputFormat.class);<a name="line.792"></a>
+<span class="sourceLineNo">793</span>    job.setOutputFormatClass(NullOutputFormat.class);<a name="line.793"></a>
+<span class="sourceLineNo">794</span>    job.setMapSpeculativeExecution(false);<a name="line.794"></a>
+<span class="sourceLineNo">795</span>    job.setNumReduceTasks(0);<a name="line.795"></a>
+<span class="sourceLineNo">796</span><a name="line.796"></a>
+<span class="sourceLineNo">797</span>    // Acquire the delegation Tokens<a name="line.797"></a>
+<span class="sourceLineNo">798</span>    Configuration srcConf = HBaseConfiguration.createClusterConf(conf, null, CONF_SOURCE_PREFIX);<a name="line.798"></a>
+<span class="sourceLineNo">799</span>    TokenCache.obtainTokensForNamenodes(job.getCredentials(),<a name="line.799"></a>
+<span class="sourceLineNo">800</span>      new Path[] { inputRoot }, srcConf);<a name="line.800"></a>
+<span class="sourceLineNo">801</span>    Configuration destConf = HBaseConfiguration.createClusterConf(conf, null, CONF_DEST_PREFIX);<a name="line.801"></a>
+<span class="sourceLineNo">802</span>    TokenCache.obtainTokensForNamenodes(job.getCredentials(),<a name="line.802"></a>
+<span class="sourceLineNo">803</span>        new Path[] { outputRoot }, destConf);<a name="line.803"></a>
+<span class="sourceLineNo">804</span><a name="line.804"></a>
+<span class="sourceLineNo">805</span>    // Run the MR Job<a name="line.805"></a>
+<span class="sourceLineNo">806</span>    if (!job.waitForCompletion(true)) {<a name="line.806"></a>
+<span class="sourceLineNo">807</span>      // TODO: Replace the fixed string with job.getStatus().getFailureInfo()<a name="line.807"></a>
+<span class="sourceLineNo">808</span>      // when it will be available on all the supported versions.<a name="line.808"></a>
+<span class="sourceLineNo">809</span>      throw new ExportSnapshotException("Copy Files Map-Reduce Job failed");<a name="line.809"></a>
+<span class="sourceLineNo">810</span>    }<a name="line.810"></a>
+<span class="sourceLineNo">811</span>  }<a name="line.811"></a>
+<span class="sourceLineNo">812</span><a name="line.812"></a>
+<span class="sourceLineNo">813</span>  private void verifySnapshot(final Configuration baseConf,<a name="line.813"></a>
+<span class="sourceLineNo">814</span>      final FileSystem fs, final Path rootDir, final Path snapshotDir) throws IOException {<a name="line.814"></a>
+<span class="sourceLineNo">815</span>    // Update the conf with the current root dir, since may be a different cluster<a name="line.815"></a>
+<span class="sourceLineNo">816</span>    Configuration conf = new Configuration(baseConf);<a name="line.816"></a>
+<span class="sourceLineNo">817</span>    FSUtils.setRootDir(conf, rootDir);<a name="line.817"></a>
+<span class="sourceLineNo">818</span>    FSUtils.setFsDefault(conf, FSUtils.getRootDir(conf));<a name="line.818"></a>
+<span class="sourceLineNo">819</span>    SnapshotDescription snapshotDesc = SnapshotDescriptionUtils.readSnapshotInfo(fs, snapshotDir);<a name="line.819"></a>
+<span class="sourceLineNo">820</span>    SnapshotReferenceUtil.verifySnapshot(conf, fs, snapshotDir, snapshotDesc);<a name="line.820"></a>
+<span class="sourceLineNo">821</span>  }<a name="line.821"></a>
+<span class="sourceLineNo">822</span><a name="line.822"></a>
+<span class="sourceLineNo">823</span>  /**<a name="line.823"></a>
+<span class="sourceLineNo">824</span>   * Set path ownership.<a name="line.824"></a>
+<span class="sourceLineNo">825</span>   */<a name="line.825"></a>
+<span class="sourceLineNo">826</span>  private void setOwner(final FileSystem fs, final Path path, final String user,<a name="line.826"></a>
+<span class="sourceLineNo">827</span>      final String group, final boolean recursive) throws IOException {<a name="line.827"></a>
+<span class="sourceLineNo">828</span>    if (user != null || group != null) {<a name="line.828"></a>
+<span class="sourceLineNo">829</span>      if (recursive &amp;&amp; fs.isDirectory(path)) {<a name="line.829"></a>
+<span class="sourceLineNo">830</span>        for (FileStatus child : fs.listStatus(path)) {<a name="line.830"></a>
+<span class="sourceLineNo">831</span>          setOwner(fs, child.getPath(), user, group, recursive);<a name="line.831"></a>
+<span class="sourceLineNo">832</span>        }<a name="line.832"></a>
+<span class="sourceLineNo">833</span>      }<a name="line.833"></a>
+<span class="sourceLineNo">834</span>      fs.setOwner(path, user, group);<a name="line.834"></a>
+<span class="sourceLineNo">835</span>    }<a name="line.835"></a>
+<span class="sourceLineNo">836</span>  }<a name="line.836"></a>
+<span class="sourceLineNo">837</span><a name="line.837"></a>
+<span class="sourceLineNo">838</span>  /**<a name="line.838"></a>
+<span class="sourceLineNo">839</span>   * Set path permission.<a name="line.839"></a>
+<span class="sourceLineNo">840</span>   */<a name="line.840"></a>
+<span class="sourceLineNo">841</span>  private void setPermission(final FileSystem fs, final Path path, final short filesMode,<a name="line.841"></a>
+<span class="sourceLineNo">842</span>      final boolean recursive) throws IOException {<a name="line.842"></a>
+<span class="sourceLineNo">843</span>    if (filesMode &gt; 0) {<a name="line.843"></a>
+<span class="sourceLineNo">844</span>      FsPermission perm = new FsPermission(filesMode);<a name="line.844"></a>
+<span class="sourceLineNo">845</span>      if (recursive &amp;&amp; fs.isDirectory(path)) {<a name="line.845"></a>
+<span class="sourceLineNo">846</span>        for (FileStatus child : fs.listStatus(path)) {<a name="line.846"></a>
+<span class="sourceLineNo">847</span>          setPermission(fs, child.getPath(), filesMode, recursive);<a name="line.847"></a>
+<span class="sourceLineNo">848</span>        }<a name="line.848"></a>
+<span class="sourceLineNo">849</span>      }<a name="line.849"></a>
+<span class="sourceLineNo">850</span>      fs.setPermission(path, perm);<a name="line.850"></a>
+<span class="sourceLineNo">851</span>    }<a name="line.851"></a>
+<span class="sourceLineNo">852</span>  }<a name="line.852"></a>
+<span class="sourceLineNo">853</span><a name="line.853"></a>
+<span class="sourceLineNo">854</span>  /**<a name="line.854"></a>
+<span class="sourceLineNo">855</span>   * Execute the export snapshot by copying the snapshot metadata, hfiles and wals.<a name="line.855"></a>
+<span class="sourceLineNo">856</span>   * @return 0 on success, and != 0 upon failure.<a name="line.856"></a>
+<span class="sourceLineNo">857</span>   */<a name="line.857"></a>
+<span class="sourceLineNo">858</span>  @Override<a name="line.858"></a>
+<span class="sourceLineNo">859</span>  public int run(String[] args) throws IOException {<a name="line.859"></a>
+<span class="sourceLineNo">860</span>    boolean verifyTarget = true;<a name="line.860"></a>
+<span class="sourceLineNo">861</span>    boolean verifyChecksum = true;<a name="line.861"></a>
+<span class="sourceLineNo">862</span>    String snapshotName = null;<a name="line.862"></a>
+<span class="sourceLineNo">863</span>    String targetName = null;<a name="line.863"></a>
+<span class="sourceLineNo">864</span>    boolean overwrite = false;<a name="line.864"></a>
+<span class="sourceLineNo">865</span>    String filesGroup = null;<a name="line.865"></a>
+<span class="sourceLineNo">866</span>    String filesUser = null;<a name="line.866"></a>
+<span class="sourceLineNo">867</span>    Path outputRoot = null;<a name="line.867"></a>
+<span class="sourceLineNo">868</span>    int bandwidthMB = Integer.MAX_VALUE;<a name="line.868"></a>
+<span class="sourceLineNo">869</span>    int filesMode = 0;<a name="line.869"></a>
+<span class="sourceLineNo">870</span>    int mappers = 0;<a name="line.870"></a>
+<span class="sourceLineNo">871</span><a name="line.871"></a>
+<span class="sourceLineNo">872</span>    Configuration conf = getConf();<a name="line.872"></a>
+<span class="sourceLineNo">873</span>    Path inputRoot = FSUtils.getRootDir(conf);<a name="line.873"></a>
+<span class="sourceLineNo">874</span><a name="line.874"></a>
+<span class="sourceLineNo">875</span>    // Process command line args<a name="line.875"></a>
+<span class="sourceLineNo">876</span>    for (int i = 0; i &lt; args.length; i++) {<a name="line.876"></a>
+<span class="sourceLineNo">877</span>      String cmd = args[i];<a name="line.877"></a>
+<span class="sourceLineNo">878</span>      if (cmd.equals("-snapshot")) {<a name="line.878"></a>
+<span class="sourceLineNo">879</span>        snapshotName = args[++i];<a name="line.879"></a>
+<span class="sourceLineNo">880</span>      } else if (cmd.equals("-target")) {<a name="line.880"></a>
+<span class="sourceLineNo">881</span>        targetName = args[++i];<a name="line.881"></a>
+<span class="sourceLineNo">882</span>      } else if (cmd.equals("-copy-to")) {<a name="line.882"></a>
+<span class="sourceLineNo">883</span>        outputRoot = new Path(args[++i]);<a name="line.883"></a>
+<span class="sourceLineNo">884</span>      } else if (cmd.equals("-copy-from")) {<a name="line.884"></a>
+<span class="sourceLineNo">885</span>        inputRoot = new Path(args[++i]);<a name="line.885"></a>
+<span class="sourceLineNo">886</span>        FSUtils.setRootDir(conf, inputRoot);<a name="line.886"></a>
+<span class="sourceLineNo">887</span>      } else if (cmd.equals("-no-checksum-verify")) {<a name="line.887"></a>
+<span class="sourceLineNo">888</span>        verifyChecksum = false;<a name="line.888"></a>
+<span class="sourceLineNo">889</span>      } else if (cmd.equals("-no-target-verify")) {<a name="line.889"></a>
+<span class="sourceLineNo">890</span>        verifyTarget = false;<a name="line.890"></a>
+<span class="sourceLineNo">891</span>      } else if (cmd.equals("-mappers")) {<a name="line.891"></a>
+<span class="sourceLineNo">892</span>        mappers = Integer.parseInt(args[++i]);<a name="line.892"></a>
+<span class="sourceLineNo">893</span>      } else if (cmd.equals("-chuser")) {<a name="line.893"></a>
+<span class="sourceLineNo">894</span>        filesUser = args[++i];<a name="line.894"></a>
+<span class="sourceLineNo">895</span>      } else if (cmd.equals("-chgroup")) {<a name="line.895"></a>
+<span class="sourceLineNo">896</span>        filesGroup = args[++i];<a name="line.896"></a>
+<span class="sourceLineNo">897</span>      } else if (cmd.equals("-bandwidth")) {<a name="line.897"></a>
+<span class="sourceLineNo">898</span>        bandwidthMB = Integer.parseInt(args[++i]);<a name="line.898"></a>
+<span class="sourceLineNo">899</span>      } else if (cmd.equals("-chmod")) {<a name="line.899"></a>
+<span class="sourceLineNo">900</span>        filesMode = Integer.parseInt(args[++i], 8);<a name="line.900"></a>
+<span class="sourceLineNo">901</span>      } else if (cmd.equals("-overwrite")) {<a name="line.901"></a>
+<span class="sourceLineNo">902</span>        overwrite = true;<a name="line.902"></a>
+<span class="sourceLineNo">903</span>      } else if (cmd.equals("-h") || cmd.equals("--help")) {<a name="line.903"></a>
+<span class="sourceLineNo">904</span>        printUsageAndExit();<a name="line.904"></a>
+<span class="sourceLineNo">905</span>      } else {<a name="line.905"></a>
+<span class="sourceLineNo">906</span>        System.err.println("UNEXPECTED: " + cmd);<a name="line.906"></a>
+<span class="sourceLineNo">907</span>        printUsageAndExit();<a name="line.907"></a>
+<span class="sourceLineNo">908</span>      }<a name="line.908"></a>
+<span class="sourceLineNo">909</span>    }<a name="line.909"></a>
+<span class="sourceLineNo">910</span><a name="line.910"></a>
+<span class="sourceLineNo">911</span>    // Check user options<a name="line.911"></a>
+<span class="sourceLineNo">912</span>    if (snapshotName == null) {<a name="line.912"></a>
+<span class="sourceLineNo">913</span>      System.err.println("Snapshot name not provided.");<a name="line.913"></a>
+<span class="sourceLineNo">914</span>      printUsageAndExit();<a name="line.914"></a>
+<span class="sourceLineNo">915</span>    }<a name="line.915"></a>
+<span class="sourceLineNo">916</span><a name="line.916"></a>
+<span class="sourceLineNo">917</span>    if (outputRoot == null) {<a name="line.917"></a>
+<span class="sourceLineNo">918</span>      System.err.println("Destination file-system not provided.");<a name="line.918"></a>
+<span class="sourceLineNo">919</span>      printUsageAndExit();<a name="line.919"></a>
+<span class="sourceLineNo">920</span>    }<a name="line.920"></a>
+<span class="sourceLineNo">921</span><a name="line.921"></a>
+<span class="sourceLineNo">922</span>    if (targetName == null) {<a name="line.922"></a>
+<span class="sourceLineNo">923</span>      targetName = snapshotName;<a name="line.923"></a>
+<span class="sourceLineNo">924</span>    }<a name="line.924"></a>
+<span class="sourceLineNo">925</span><a name="line.925"></a>
+<span class="sourceLineNo">926</span>    Configuration srcConf = HBaseConfiguration.createClusterConf(conf, null, CONF_SOURCE_PREFIX);<a name="line.926"></a>
+<span class="sourceLineNo">927</span>    srcConf.setBoolean("fs." + inputRoot.toUri().getScheme() + ".impl.disable.cache", true);<a name="line.927"></a>
+<span class="sourceLineNo">928</span>    FileSystem inputFs = FileSystem.get(inputRoot.toUri(), srcConf);<a name="line.928"></a>
+<span class="sourceLineNo">929</span>    LOG.debug("inputFs=" + inputFs.getUri().toString() + " inputRoot=" + inputRoot);<a name="line.929"></a>
+<span class="sourceLineNo">930</span>    Configuration destConf = HBaseConfiguration.createClusterConf(conf, null, CONF_DEST_PREFIX);<a name="line.930"></a>
+<span class="sourceLineNo">931</span>    destConf.setBoolean("fs." + outputRoot.toUri().getScheme() + ".impl.disable.cache", true);<a name="line.931"></a>
+<span class="sourceLineNo">932</span>    FileSystem outputFs = FileSystem.get(outputRoot.toUri(), destConf);<a name="line.932"></a>
+<span class="sourceLineNo">933</span>    LOG.debug("outputFs=" + outputFs.getUri().toString() + " outputRoot=" + outputRoot.toString());<a name="line.933"></a>
+<span class="sourceLineNo">934</span><a name="line.934"></a>
+<span class="sourceLineNo">935</span>    boolean skipTmp = conf.getBoolean(CONF_SKIP_TMP, false);<a name="line.935"></a>
+<span class="sourceLineNo">936</span><a name="line.936"></a>
+<span class="sourceLineNo">937</span>    Path snapshotDir = SnapshotDescriptionUtils.getCompletedSnapshotDir(snapshotName, inputRoot);<a name="line.937"></a>
+<span class="sourceLineNo">938</span>    Path snapshotTmpDir = SnapshotDescriptionUtils.getWorkingSnapshotDir(targetName, outputRoot);<a name="line.938"></a>
+<span class="sourceLineNo">939</span>    Path outputSnapshotDir = SnapshotDescriptionUtils.getCompletedSnapshotDir(targetName, outputRoot);<a name="line.939"></a>
+<span class="sourceLineNo">940</span>    Path initialOutputSnapshotDir = skipTmp ? outputSnapshotDir : snapshotTmpDir;<a name="line.940"></a>
+<span class="sourceLineNo">941</span><a name="line.941"></a>
+<span class="sourceLineNo">942</span>    // Check if the snapshot already exists<a name="line.942"></a>
+<span class="sourceLineNo">943</span>    if (outputFs.exists(outputSnapshotDir)) {<a name="line.943"></a>
+<span class="sourceLineNo">944</span>      if (overwrite) {<a name="line.944"></a>
+<span class="sourceLineNo">945</span>        if (!outputFs.delete(outputSnapshotDir, true)) {<a name="line.945"></a>
+<span class="sourceLineNo">946</span>          System.err.println("Unable to remove existing snapshot directory: " + outputSnapshotDir);<a name="line.946"></a>
+<span class="sourceLineNo">947</span>          return 1;<a name="line.947"></a>
+<span class="sourceLineNo">948</span>        }<a name="line.948"></a>
+<span class="sourceLineNo">949</span>      } else {<a name="line.949"></a>
+<span class="sourceLineNo">950</span>        System.err.println("The snapshot '" + targetName +<a name="line.950"></a>
+<span class="sourceLineNo">951</span>          "' already exists in the destination: " + outputSnapshotDir);<a name="line.951"></a>
+<span class="sourceLineNo">952</span>        return 1;<a name="line.952"></a>
+<span class="sourceLineNo">953</span>      }<a name="line.953"></a>
+<span class="sourceLineNo">954</span>    }<a name="line.954"></a>
+<span class="sourceLineNo">955</span><a name="line.955"></a>
+<span class="sourceLineNo">956</span>    if (!skipTmp) {<a name="line.956"></a>
+<span class="sourceLineNo">957</span>      // Check if the snapshot already in-progress<a name="line.957"></a>
+<span class="sourceLineNo">958</span>      if (outputFs.exists(snapshotTmpDir)) {<a name="line.958"></a>
+<span class="sourceLineNo">959</span>        if (overwrite) {<a name="line.959"></a>
+<span class="sourceLineNo">960</span>          if (!outputFs.delete(snapshotTmpDir, true)) {<a name="line.960"></a>
+<span class="sourceLineNo">961</span>            System.err.println("Unable to remove existing snapshot tmp directory: "+snapshotTmpDir);<a name="line.961"></a>
+<span class="sourceLineNo">962</span>            return 1;<a name="line.962"></a>
+<span class="sourceLineNo">963</span>          }<a name="line.963"></a>
+<span class="sourceLineNo">964</span>        } else {<a name="line.964"></a>
+<span class="sourceLineNo">965</span>          System.err.println("A snapshot with the same name '"+ targetName +"' may be in-progress");<a name="line.965"></a>
+<span class="sourceLineNo">966</span>          System.err.println("Please check "+snapshotTmpDir+". If the snapshot has completed, ");<a name="line.966"></a>
+<span class="sourceLineNo">967</span>          System.err.println("consider removing "+snapshotTmpDir+" by using the -overwrite option");<a name="line.967"></a>
+<span class="sourceLineNo">968</span>          return 1;<a name="line.968"></a>
+<span class="sourceLineNo">969</span>        }<a name="line.969"></a>
+<span class="sourceLineNo">970</span>      }<a name="line.970"></a>
+<span class="sourceLineNo">971</span>    }<a name="line.971"></a>
+<span class="sourceLineNo">972</span><a name="line.972"></a>
+<span class="sourceLineNo">973</span>    // Step 1 - Copy fs1:/.snapshot/&lt;snapshot&gt; to  fs2:/.snapshot/.tmp/&lt;snapshot&gt;<a name="line.973"></a>
+<span class="sourceLineNo">974</span>    // The snapshot references must be copied before the hfiles otherwise the cleaner<a name="line.974"></a>
+<span class="sourceLineNo">975</span>    // will remove them because they are unreferenced.<a name="line.975"></a>
+<span class="sourceLineNo">976</span>    try {<a name="line.976"></a>
+<span class="sourceLineNo">977</span>      LOG.info("Copy Snapshot Manifest");<a name="line.977"></a>
+<span class="sourceLineNo">978</span>      FileUtil.copy(inputFs, snapshotDir, outputFs, initialOutputSnapshotDir, false, false, conf);<a name="line.978"></a>
+<span class="sourceLineNo">979</span>      if (filesUser != null || filesGroup != null) {<a name="line.979"></a>
+<span class="sourceLineNo">980</span>        setOwner(outputFs, snapshotTmpDir, filesUser, filesGroup, true);<a name="line.980"></a>
+<span class="sourceLineNo">981</span>      }<a name="line.981"></a>
+<span class="sourceLineNo">982</span>      if (filesMode &gt; 0) {<a name="line.982"></a>
+<span class="sourceLineNo">983</span>        setPermission(outputFs, snapshotTmpDir, (short)filesMode, true);<a name="line.983"></a>
+<span class="sourceLineNo">984</span>      }<a name="line.984"></a>
+<span class="sourceLineNo">985</span>    } catch (IOException e) {<a name="line.985"></a>
+<span class="sourceLineNo">986</span>      throw new ExportSnapshotException("Failed to copy the snapshot directory: from=" +<a name="line.986"></a>
+<span class="sourceLineNo">987</span>        snapshotDir + " to=" + initialOutputSnapshotDir, e);<a name="line.987"></a>
+<span class="sourceLineNo">988</span>    }<a name="line.988"></a>
+<span class="sourceLineNo">989</span><a name="line.989"></a>
+<span class="sourceLineNo">990</span>    // Write a new .snapshotinfo if the target name is different from the source name<a name="line.990"></a>
+<span class="sourceLineNo">991</span>    if (!targetName.equals(snapshotName)) {<a name="line.991"></a>
+<span class="sourceLineNo">992</span>      SnapshotDescription snapshotDesc =<a name="line.992"></a>
+<span class="sourceLineNo">993</span>        SnapshotDescriptionUtils.readSnapshotInfo(inputFs, snapshotDir)<a name="line.993"></a>
+<span class="sourceLineNo">994</span>          .toBuilder()<a name="line.994"></a>
+<span class="sourceLineNo">995</span>          .setName(targetName)<a name="line.995"></a>
+<span class="sourceLineNo">996</span>          .build();<a name="line.996"></a>
+<span class="sourceLineNo">997</span>      SnapshotDescriptionUtils.writeSnapshotInfo(snapshotDesc, snapshotTmpDir, outputFs);<a name="line.997"></a>
+<span class="sourceLineNo">998</span>    }<a name="line.998"></a>
+<span class="sourceLineNo">999</span><a name="line.999"></a>
+<span class="sourceLineNo">1000</span>    // Step 2 - Start MR Job to copy files<a name="line.1000"></a>
+<span class="sourceLineNo">1001</span>    // The snapshot references must be copied before the files otherwise the files gets removed<a name="line.1001"></a>
+<span class="sourceLineNo">1002</span>    // by the HFileArchiver, since they have no references.<a name="line.1002"></a>
+<span class="sourceLineNo">1003</span>    try {<a name="line.1003"></a>
+<span class="sourceLineNo">1004</span>      runCopyJob(inputRoot, outputRoot, snapshotName, snapshotDir, verifyChecksum,<a name="line.1004"></a>
+<span class="sourceLineNo">1005</span>                 filesUser, filesGroup, filesMode, mappers, bandwidthMB);<a name="line.1005"></a>
+<span class="sourceLineNo">1006</span><a name="line.1006"></a>
+<span class="sourceLineNo">1007</span>      LOG.info("Finalize the Snapshot Export");<a name="line.1007"></a>
+<span class="sourceLineNo">1008</span>      if (!skipTmp) {<a name="line.1008"></a>
+<span class="sourceLineNo">1009</span>        // Step 3 - Rename fs2:/.snapshot/.tmp/&lt;snapshot&gt; fs2:/.snapshot/&lt;snapshot&gt;<a name="line.1009"></a>
+<span class="sourceLineNo">1010</span>        if (!outputFs.rename(snapshotTmpDir, outputSnapshotDir)) {<a name="line.1010"></a>
+<span class="sourceLineNo">1011</span>          throw new ExportSnapshotException("Unable to rename snapshot directory from=" +<a name="line.1011"></a>
+<span class="sourceLineNo">1012</span>            snapshotTmpDir + " to=" + outputSnapshotDir);<a name="line.1012"></a>
+<span class="sourceLineNo">1013</span>        }<a name="line.1013"></a>
+<span class="sourceLineNo">1014</span>      }<a name="line.1014"></a>
+<span class="sourceLineNo">1015</span><a name="line.1015"></a>
+<span class="sourceLineNo">1016</span>      // Step 4 - Verify snapshot integrity<a name="line.1016"></a>
+<span class="sourceLineNo">1017</span>      if (verifyTarget) {<a name="line.1017"></a>
+<span class="sourceLineNo">1018</span>        LOG.info("Verify snapshot integrity");<a name="line.1018"></a>
+<span class="sourceLineNo">1019</span>        verifySnapshot(destConf, outputFs, outputRoot, outputSnapshotDir);<a name="line.1019"></a>
+<span class="sourceLineNo">1020</span>      }<a name="line.1020"></a>
+<span class="sourceLineNo">1021</span><a name="line.1021"></a>
+<span class="sourceLineNo">1022</span>      LOG.info("Export Completed: " + targetName);<a name="line.1022"></a>
+<span class="sourceLineNo">1023</span>      return 0;<a name="line.1023"></a>
+<span class="sourceLineNo">1024</span>    } catch (Exception e) {<a name="line.1024"></a>
+<span class="sourceLineNo">1025</span>      LOG.error("Snapshot export failed", e);<a name="line.1025"></a>
+<span class="sourceLineNo">1026</span>      if (!skipTmp) {<a name="line.1026"></a>
+<span class="sourceLineNo">1027</span>        outputFs.delete(snapshotTmpDir, true);<a name="line.1027"></a>
+<span class="sourceLineNo">1028</span>      }<a name="line.1028"></a>
+<span class="sourceLineNo">1029</span>      outputFs.delete(outputSnapshotDir, true);<a name="line.1029"></a>
+<span class="sourceLineNo">1030</span>      return 1;<a name="line.1030"></a>
+<span class="sourceLineNo">1031</span>    } finally {<a name="line.1031"></a>
+<span class="sourceLineNo">1032</span>      IOUtils.closeStream(inputFs);<a name="line.1032"></a>
+<span class="sourceLineNo">1033</span>      IOUtils.closeStream(outputFs);<a name="line.1033"></a>
+<span class="sourceLineNo">1034</span>    }<a name="line.1034"></a>
+<span class="sourceLineNo">1035</span>  }<a name="line.1035"></a>
+<span class="sourceLineNo">1036</span><a name="line.1036"></a>
+<span class="sourceLineNo">1037</span>  // ExportSnapshot<a name="line.1037"></a>
+<span class="sourceLineNo">1038</span>  private void printUsageAndExit() {<a name="line.1038"></a>
+<span class="sourceLineNo">1039</span>    System.err.printf("Usage: bin/hbase %s [options]%n", getClass().getName());<a name="line.1039"></a>
+<span class="sourceLineNo">1040</span>    System.err.println(" where [options] are:");<a name="line.1040"></a>
+<span class="sourceLineNo">1041</span>    System.err.println("  -h|-help                Show this help and exit.");<a name="line.1041"></a>
+<span class="sourceLineNo">1042</span>    System.err.println("  -snapshot NAME          Snapshot to restore.");<a name="line.1042"></a>
+<span class="sourceLineNo">1043</span>    System.err.println("  -copy-to NAME           Remote destination hdfs://");<a name="line.1043"></a>
+<span class="sourceLineNo">1044</span>    System.err.println("  -copy-from NAME         Input folder hdfs:// (default hbase.rootdir)");<a name="line.1044"></a>
+<span class="sourceLineNo">1045</span>    System.err.println("  -no-checksum-verify     Do not verify checksum, use name+length only.");<a name="line.1045"></a>
+<span class="sourceLineNo">1046</span>    System.err.println("  -no-target-verify       Do not verify the integrity of the \\" +<a name="line.1046"></a>
+<span class="sourceLineNo">1047</span>        "exported snapshot.");<a name="line.1047"></a>
+<span class="sourceLineNo">1048</span>    System.err.println("  -overwrite              Rewrite the snapshot manifest if already exists");<a name="line.1048"></a>
+<span class="sourceLineNo">1049</span>    System.err.println("  -chuser USERNAME        Change the owner of the files " +<a name="line.1049"></a>
+<span class="sourceLineNo">1050</span>        "to the specified one.");<a name="line.1050"></a>
+<span class="sourceLineNo">1051</span>    System.err.println("  -chgroup GROUP          Change the group of the files to " +<a name="line.1051"></a>
+<span class="sourceLineNo">1052</span>        "the specified one.");<a name="line.1052"></a>
+<span class="sourceLineNo">1053</span>    System.err.println("  -chmod MODE             Change the permission of the files " +<a name="line.1053"></a>
+<span class="sourceLineNo">1054</span>        "to the specified one.");<a name="line.1054"></a>
+<span class="sourceLineNo">1055</span>    System.err.println("  -mappers                Number of mappers to use during the " +<a name="line.1055"></a>
+<span class="sourceLineNo">1056</span>        "copy (mapreduce.job.maps).");<a name="line.1056"></a>
+<span class="sourceLineNo">1057</span>    System.err.println("  -bandwidth              Limit bandwidth to this value in MB/second.");<a name="line.1057"></a>
+<span class="sourceLineNo">1058</span>    System.err.println();<a name="line.1058"></a>
+<span class="sourceLineNo">1059</span>    System.err.println("Examples:");<a name="line.1059"></a>
+<span class="sourceLineNo">1060</span>    System.err.println("  hbase " + getClass().getName() + " \\");<a name="line.1060"></a>
+<span class="sourceLineNo">1061</span>    System.err.println("    -snapshot MySnapshot -copy-to hdfs://srv2:8082/hbase \\");<a name="line.1061"></a>
+<span class="sourceLineNo">1062</span>    System.err.println("    -chuser MyUser -chgroup MyGroup -chmod 700 -mappers 16");<a name="line.1062"></a>
+<span class="sourceLineNo">1063</span>    System.err.println();<a name="line.1063"></a>
+<span class="sourceLineNo">1064</span>    System.err.println("  hbase " + getClass().getName() + " \\");<a name="line.1064"></a>
+<span class="sourceLineNo">1065</span>    System.err.println("    -snapshot MySnapshot -copy-from hdfs://srv2:8082/hbase \\");<a name="line.1065"></a>
+<span class="sourceLineNo">1066</span>    System.err.println("    -copy-to hdfs://srv1:50070/hbase \\");<a name="line.1066"></a>
+<span class="sourceLineNo">1067</span>    System.exit(1);<a name="line.1067"></a>
+<span class="sourceLineNo">1068</span>  }<a name="line.1068"></a>
+<span class="sourceLineNo">1069</span><a name="line.1069"></a>
+<span class="sourceLineNo">1070</span>  /**<a name="line.1070"></a>
+<span class="sourceLineNo">1071</span>   * The guts of the {@link #main} method.<a name="line.1071"></a>
+<span class="sourceLineNo">1072</span>   * Call this method to avoid the {@link #main(String[])} System.exit.<a name="line.1072"></a>
+<span class="sourceLineNo">1073</span>   * @param args<a name="line.1073"></a>
+<span class="sourceLineNo">1074</span>   * @return errCode<a name="line.1074"></a>
+<span class="sourceLineNo">1075</span>   * @throws Exception<a name="line.1075"></a>
+<span class="sourceLineNo">1076</span>   */<a name="line.1076"></a>
+<span class="sourceLineNo">1077</span>  static int innerMain

<TRUNCATED>

Mime
View raw message