Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 package org.apache.hadoop.hbase.snapshot;
 import java.util.List;
DO NOT USE DIRECTLY. USE SnapshotManifest. Snapshot v1 layout format - Each region in the table is represented by a directory with the .hregioninfo file /snapshotName/regionName/.hregioninfo - Each file present in the table is represented by an empty file /snapshotName/regionName/familyName/fileName
 public class SnapshotManifestV1 {
   private static final Log LOG = LogFactory.getLog(SnapshotManifestV1.class);
   public static final int DESCRIPTOR_VERSION = 0;
   private SnapshotManifestV1() {
   static class ManifestBuilder implements SnapshotManifest.RegionVisitor<
                                                           HRegionFileSystemPath> {
     private final Configuration conf;
     private final Path snapshotDir;
     private final FileSystem fs;
     public ManifestBuilder(final Configuration conffinal FileSystem fsfinal Path snapshotDir) {
       this. = snapshotDir;
       this. = conf;
       this. = fs;
     public HRegionFileSystem regionOpen(final HRegionInfo regionInfothrows IOException {
       HRegionFileSystem snapshotRegionFs = HRegionFileSystem.createRegionOnFileSystem(,
       return snapshotRegionFs;
     public void regionClose(final HRegionFileSystem region) {
     public Path familyOpen(final HRegionFileSystem snapshotRegionFsfinal byte[] familyName) {
       Path familyDir = snapshotRegionFs.getStoreDir(Bytes.toString(familyName));
       return familyDir;
     public void familyClose(final HRegionFileSystem regionfinal Path family) {
     public void storeFile(final HRegionFileSystem regionfinal Path familyDir,
         final StoreFileInfo storeFilethrows IOException {
       Path referenceFile = new Path(familyDirstoreFile.getPath().getName());
       boolean success = true;
       if (storeFile.isReference()) {
        // write the Reference object to the snapshot
      } else {
        // create "reference" to this store file.  It is intentionally an empty file -- all
        // necessary information is captured by its fs location and filename.  This allows us to
        // only figure out what needs to be done via a single nn operation (instead of having to
        // open and read the files as well).
        success = .createNewFile(referenceFile);
      if (!success) {
        throw new IOException("Failed to create reference file:" + referenceFile);
      final Executor executor,final FileSystem fsfinal Path snapshotDir,
      final SnapshotDescription descthrows IOException {
    FileStatus[] regions = FSUtils.listStatus(fssnapshotDirnew FSUtils.RegionDirFilter(fs));
    if (regions == null) {
      .info("No regions under directory:" + snapshotDir);
      return null;
    final ExecutorCompletionService<SnapshotRegionManifestcompletionService =
    for (final FileStatus regionregions) {
      completionService.submit(new Callable<SnapshotRegionManifest>() {
        public SnapshotRegionManifest call() throws IOException {
          HRegionInfo hri = HRegionFileSystem.loadRegionInfoFileContent(fsregion.getPath());
          return buildManifestFromDisk(conffssnapshotDirhri);
    ArrayList<SnapshotRegionManifestregionsManifest =
        new ArrayList<SnapshotRegionManifest>(regions.length);
    try {
      for (int i = 0; i < regions.length; ++i) {
    } catch (InterruptedException e) {
      throw new InterruptedIOException(e.getMessage());
    } catch (ExecutionException e) {
      IOException ex = new IOException();
      throw ex;
    return regionsManifest;
  static void deleteRegionManifest(final FileSystem fsfinal Path snapshotDir,
      final SnapshotRegionManifest manifestthrows IOException {
    String regionName = SnapshotManifest.getRegionNameFromManifest(manifest);
    fs.delete(new Path(snapshotDirregionName), true);
      final FileSystem fsfinal Path tableDirfinal HRegionInfo regionInfothrows IOException {
    HRegionFileSystem regionFs = HRegionFileSystem.openRegionFromFileSystem(conffs,
    SnapshotRegionManifest.Builder manifest = SnapshotRegionManifest.newBuilder();
    // 1. dump region meta info into the snapshot directory
    .debug("Storing region-info for snapshot.");
    // 2. iterate through all the stores in the region
    .debug("Creating references for hfiles");
    // This ensures that we have an atomic view of the directory as long as we have < ls limit
    // (batch size of the files in a directory) on the namenode. Otherwise, we get back the files in
    // batches and may miss files being added/deleted. This could be more robust (iteratively
    // checking to see if we have all the files until we are sure), but the limit is currently 1000
    // files/batch, far more than the number of store files under a single column family.
    Collection<StringfamilyNames = regionFs.getFamilies();
    if (familyNames != null) {
      for (String familyNamefamilyNames) {
        Collection<StoreFileInfostoreFiles = regionFs.getStoreFiles(familyNamefalse);
        if (storeFiles == null) {
          .debug("No files under family: " + familyName);
        // 2.1. build the snapshot reference for the store
        SnapshotRegionManifest.FamilyFiles.Builder family =
        if (.isDebugEnabled()) {
          .debug("Adding snapshot references for " + storeFiles  + " hfiles");
        // 2.2. iterate through all the store's files and create "references".
        int i = 0;
        int sz = storeFiles.size();
        for (StoreFileInfo storeFilestoreFiles) {
          // create "reference" to this store file.
          .debug("Adding reference for file ("+ (++i) +"/" + sz + "): " + storeFile.getPath());
          SnapshotRegionManifest.StoreFile.Builder sfManifest =
New to GrepCode? Check out our FAQ X