View Javadoc

1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.hadoop.hbase.snapshot;
19  
20  import org.apache.commons.logging.Log;
21  import org.apache.commons.logging.LogFactory;
22  import org.apache.hadoop.classification.InterfaceAudience;
23  import org.apache.hadoop.classification.InterfaceStability;
24  import org.apache.hadoop.fs.FileSystem;
25  import org.apache.hadoop.fs.Path;
26  import org.apache.hadoop.hbase.HTableDescriptor;
27  import org.apache.hadoop.hbase.TableName;
28  import org.apache.hadoop.hbase.errorhandling.ForeignExceptionDispatcher;
29  import org.apache.hadoop.hbase.protobuf.ProtobufUtil;
30  import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.SnapshotDescription;
31  import org.apache.hadoop.hbase.util.FSTableDescriptors;
32  
33  /**
34   * Copy the table info into the snapshot directory
35   */
36  @InterfaceAudience.Private
37  @InterfaceStability.Evolving
38  public class TableInfoCopyTask extends SnapshotTask {
39  
40    public static final Log LOG = LogFactory.getLog(TableInfoCopyTask.class);
41    private final FileSystem fs;
42    private final Path rootDir;
43  
44    /**
45     * Copy the table info for the given table into the snapshot
46     * @param monitor listen for errors while running the snapshot
47     * @param snapshot snapshot for which we are copying the table info
48     * @param fs {@link FileSystem} where the tableinfo is stored (and where the copy will be written)
49     * @param rootDir root of the {@link FileSystem} where the tableinfo is stored
50     */
51    public TableInfoCopyTask(ForeignExceptionDispatcher monitor,
52        SnapshotDescription snapshot, FileSystem fs, Path rootDir) {
53      super(snapshot, monitor);
54      this.rootDir = rootDir;
55      this.fs = fs;
56    }
57  
58    @Override
59    public Void call() throws Exception {
60      LOG.debug("Running table info copy.");
61      this.rethrowException();
62      LOG.debug("Attempting to copy table info for snapshot:"
63          + ClientSnapshotDescriptionUtils.toString(this.snapshot));
64      // get the HTable descriptor
65      HTableDescriptor orig = FSTableDescriptors.getTableDescriptorFromFs(fs, rootDir,
66          TableName.valueOf(this.snapshot.getTable()));
67      this.rethrowException();
68      // write a copy of descriptor to the snapshot directory
69      Path snapshotDir = SnapshotDescriptionUtils.getWorkingSnapshotDir(snapshot, rootDir);
70      new FSTableDescriptors(fs, rootDir)
71        .createTableDescriptorForTableDirectory(snapshotDir, orig, false);
72      LOG.debug("Finished copying tableinfo.");
73      return null;
74    }
75  }