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.errorhandling.ForeignExceptionDispatcher;
28  import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.SnapshotDescription;
29  import org.apache.hadoop.hbase.util.Bytes;
30  import org.apache.hadoop.hbase.util.FSTableDescriptors;
31  
32  /**
33   * Copy the table info into the snapshot directory
34   */
35  @InterfaceAudience.Private
36  @InterfaceStability.Evolving
37  public class TableInfoCopyTask extends SnapshotTask {
38  
39    public static final Log LOG = LogFactory.getLog(TableInfoCopyTask.class);
40    private final FileSystem fs;
41    private final Path rootDir;
42  
43    /**
44     * Copy the table info for the given table into the snapshot
45     * @param monitor listen for errors while running the snapshot
46     * @param snapshot snapshot for which we are copying the table info
47     * @param fs {@link FileSystem} where the tableinfo is stored (and where the copy will be written)
48     * @param rootDir root of the {@link FileSystem} where the tableinfo is stored
49     */
50    public TableInfoCopyTask(ForeignExceptionDispatcher monitor,
51        SnapshotDescription snapshot, FileSystem fs, Path rootDir) {
52      super(snapshot, monitor);
53      this.rootDir = rootDir;
54      this.fs = fs;
55    }
56  
57    @Override
58    public Void call() throws Exception {
59      LOG.debug("Running table info copy.");
60      this.rethrowException();
61      LOG.debug("Attempting to copy table info for snapshot:"
62          + SnapshotDescriptionUtils.toString(this.snapshot));
63      // get the HTable descriptor
64      HTableDescriptor orig = FSTableDescriptors.getTableDescriptor(fs, rootDir,
65        Bytes.toBytes(this.snapshot.getTable()));
66      this.rethrowException();
67      // write a copy of descriptor to the snapshot directory
68      Path snapshotDir = SnapshotDescriptionUtils.getWorkingSnapshotDir(snapshot, rootDir);
69      FSTableDescriptors.createTableDescriptorForTableDirectory(fs, snapshotDir, orig, false);
70      LOG.debug("Finished copying tableinfo.");
71      return null;
72    }
73  }