Java 类org.apache.hadoop.hbase.snapshot.ReferenceRegionHFilesTask 实例源码

项目:LCIndex-HBase-0.94.16    文件:TakeSnapshotHandler.java   
/**
 * Take a snapshot of the specified disabled region
 */
protected void snapshotDisabledRegion(final HRegionInfo regionInfo)
    throws IOException {
  // 1 copy the regionInfo files to the snapshot
  Path snapshotRegionDir = TakeSnapshotUtils.getRegionSnapshotDirectory(snapshot, rootDir,
    regionInfo.getEncodedName());
  HRegion.writeRegioninfoOnFilesystem(regionInfo, snapshotRegionDir, fs, conf);
  // check for error for each region
  monitor.rethrowException();

  // 2 for each region, copy over its recovered.edits directory
  Path regionDir = HRegion.getRegionDir(rootDir, regionInfo);
  new CopyRecoveredEditsTask(snapshot, monitor, fs, regionDir, snapshotRegionDir).call();
  monitor.rethrowException();
  status.setStatus("Completed copying recovered edits for offline snapshot of table: "
      + snapshot.getTable());

  // 3 reference all the files in the region
  new ReferenceRegionHFilesTask(snapshot, monitor, regionDir, fs, snapshotRegionDir).call();
  monitor.rethrowException();
  status.setStatus("Completed referencing HFiles for offline snapshot of table: " +
    snapshot.getTable());
}
项目:HIndex    文件:TakeSnapshotHandler.java   
/**
 * Take a snapshot of the specified disabled region
 */
protected void snapshotDisabledRegion(final HRegionInfo regionInfo)
    throws IOException {
  // 2 copy the regionInfo files to the snapshot
  HRegionFileSystem regionFs = HRegionFileSystem.createRegionOnFileSystem(conf, fs,
    workingDir, regionInfo);

  // check for error for each region
  monitor.rethrowException();

  // 2 for each region, copy over its recovered.edits directory
  Path regionDir = HRegion.getRegionDir(rootDir, regionInfo);
  Path snapshotRegionDir = regionFs.getRegionDir();
  new CopyRecoveredEditsTask(snapshot, monitor, fs, regionDir, snapshotRegionDir).call();
  monitor.rethrowException();
  status.setStatus("Completed copying recovered edits for offline snapshot of table: "
      + snapshotTable);

  // 2 reference all the files in the region
  new ReferenceRegionHFilesTask(snapshot, monitor, regionDir, fs, snapshotRegionDir).call();
  monitor.rethrowException();
  status.setStatus("Completed referencing HFiles for offline snapshot of table: " +
      snapshotTable);
}
项目:IRIndex    文件:TakeSnapshotHandler.java   
/**
 * Take a snapshot of the specified disabled region
 */
protected void snapshotDisabledRegion(final HRegionInfo regionInfo)
    throws IOException {
  // 1 copy the regionInfo files to the snapshot
  Path snapshotRegionDir = TakeSnapshotUtils.getRegionSnapshotDirectory(snapshot, rootDir,
    regionInfo.getEncodedName());
  HRegion.writeRegioninfoOnFilesystem(regionInfo, snapshotRegionDir, fs, conf);
  // check for error for each region
  monitor.rethrowException();

  // 2 for each region, copy over its recovered.edits directory
  Path regionDir = HRegion.getRegionDir(rootDir, regionInfo);
  new CopyRecoveredEditsTask(snapshot, monitor, fs, regionDir, snapshotRegionDir).call();
  monitor.rethrowException();
  status.setStatus("Completed copying recovered edits for offline snapshot of table: "
      + snapshot.getTable());

  // 3 reference all the files in the region
  new ReferenceRegionHFilesTask(snapshot, monitor, regionDir, fs, snapshotRegionDir).call();
  monitor.rethrowException();
  status.setStatus("Completed referencing HFiles for offline snapshot of table: " +
    snapshot.getTable());
}
项目:c5    文件:TakeSnapshotHandler.java   
/**
 * Take a snapshot of the specified disabled region
 */
protected void snapshotDisabledRegion(final HRegionInfo regionInfo)
    throws IOException {
  // 2 copy the regionInfo files to the snapshot
  HRegionFileSystem regionFs = HRegionFileSystem.createRegionOnFileSystem(conf, fs,
    workingDir, regionInfo);

  // check for error for each region
  monitor.rethrowException();

  // 2 for each region, copy over its recovered.edits directory
  Path regionDir = HRegion.getRegionDir(rootDir, regionInfo);
  Path snapshotRegionDir = regionFs.getRegionDir();
  new CopyRecoveredEditsTask(snapshot, monitor, fs, regionDir, snapshotRegionDir).call();
  monitor.rethrowException();
  status.setStatus("Completed copying recovered edits for offline snapshot of table: "
      + snapshotTable);

  // 2 reference all the files in the region
  new ReferenceRegionHFilesTask(snapshot, monitor, regionDir, fs, snapshotRegionDir).call();
  monitor.rethrowException();
  status.setStatus("Completed referencing HFiles for offline snapshot of table: " +
      snapshotTable);
}
项目:LCIndex-HBase-0.94.16    文件:TestReferenceRegionHFilesTask.java   
@Test
public void testRun() throws IOException {
  FileSystem fs = UTIL.getTestFileSystem();
  // setup the region internals
  Path testdir = UTIL.getDataTestDir();
  Path regionDir = new Path(testdir, "region");
  Path family1 = new Path(regionDir, "fam1");
  // make an empty family
  Path family2 = new Path(regionDir, "fam2");
  fs.mkdirs(family2);

  // add some files to family 1
  Path file1 = new Path(family1, "05f99689ae254693836613d1884c6b63");
  fs.createNewFile(file1);
  Path file2 = new Path(family1, "7ac9898bf41d445aa0003e3d699d5d26");
  fs.createNewFile(file2);

  // create the snapshot directory
  Path snapshotRegionDir = new Path(testdir, HConstants.SNAPSHOT_DIR_NAME);
  fs.mkdirs(snapshotRegionDir);

  SnapshotDescription snapshot = SnapshotDescription.newBuilder().setName("name")
      .setTable("table").build();
  ForeignExceptionDispatcher monitor = Mockito.mock(ForeignExceptionDispatcher.class);
  ReferenceRegionHFilesTask task = new ReferenceRegionHFilesTask(snapshot, monitor, regionDir,
      fs, snapshotRegionDir);
  ReferenceRegionHFilesTask taskSpy = Mockito.spy(task);
  task.call();

  // make sure we never get an error
  Mockito.verify(taskSpy, Mockito.never()).snapshotFailure(Mockito.anyString(),
      Mockito.any(Exception.class));

  // verify that all the hfiles get referenced
  List<String> hfiles = new ArrayList<String>(2);
  FileStatus[] regions = FSUtils.listStatus(fs, snapshotRegionDir);
  for (FileStatus region : regions) {
    FileStatus[] fams = FSUtils.listStatus(fs, region.getPath());
    for (FileStatus fam : fams) {
      FileStatus[] files = FSUtils.listStatus(fs, fam.getPath());
      for (FileStatus file : files) {
        hfiles.add(file.getPath().getName());
      }
    }
  }
  assertTrue("Didn't reference :" + file1, hfiles.contains(file1.getName()));
  assertTrue("Didn't reference :" + file1, hfiles.contains(file2.getName()));
}
项目:IRIndex    文件:TestReferenceRegionHFilesTask.java   
@Test
public void testRun() throws IOException {
  FileSystem fs = UTIL.getTestFileSystem();
  // setup the region internals
  Path testdir = UTIL.getDataTestDir();
  Path regionDir = new Path(testdir, "region");
  Path family1 = new Path(regionDir, "fam1");
  // make an empty family
  Path family2 = new Path(regionDir, "fam2");
  fs.mkdirs(family2);

  // add some files to family 1
  Path file1 = new Path(family1, "05f99689ae254693836613d1884c6b63");
  fs.createNewFile(file1);
  Path file2 = new Path(family1, "7ac9898bf41d445aa0003e3d699d5d26");
  fs.createNewFile(file2);

  // create the snapshot directory
  Path snapshotRegionDir = new Path(testdir, HConstants.SNAPSHOT_DIR_NAME);
  fs.mkdirs(snapshotRegionDir);

  SnapshotDescription snapshot = SnapshotDescription.newBuilder().setName("name")
      .setTable("table").build();
  ForeignExceptionDispatcher monitor = Mockito.mock(ForeignExceptionDispatcher.class);
  ReferenceRegionHFilesTask task = new ReferenceRegionHFilesTask(snapshot, monitor, regionDir,
      fs, snapshotRegionDir);
  ReferenceRegionHFilesTask taskSpy = Mockito.spy(task);
  task.call();

  // make sure we never get an error
  Mockito.verify(taskSpy, Mockito.never()).snapshotFailure(Mockito.anyString(),
      Mockito.any(Exception.class));

  // verify that all the hfiles get referenced
  List<String> hfiles = new ArrayList<String>(2);
  FileStatus[] regions = FSUtils.listStatus(fs, snapshotRegionDir);
  for (FileStatus region : regions) {
    FileStatus[] fams = FSUtils.listStatus(fs, region.getPath());
    for (FileStatus fam : fams) {
      FileStatus[] files = FSUtils.listStatus(fs, fam.getPath());
      for (FileStatus file : files) {
        hfiles.add(file.getPath().getName());
      }
    }
  }
  assertTrue("Didn't reference :" + file1, hfiles.contains(file1.getName()));
  assertTrue("Didn't reference :" + file1, hfiles.contains(file2.getName()));
}
项目:HBase-Research    文件:DisabledTableSnapshotHandler.java   
@Override
public void snapshotRegions(List<Pair<HRegionInfo, ServerName>> regionsAndLocations)
    throws IOException, KeeperException {
  try {
    timeoutInjector.start();

    // 1. get all the regions hosting this table.

    // extract each pair to separate lists
    Set<String> serverNames = new HashSet<String>();
    Set<HRegionInfo> regions = new HashSet<HRegionInfo>();
    for (Pair<HRegionInfo, ServerName> p : regionsAndLocations) {
      regions.add(p.getFirst());
      serverNames.add(p.getSecond().toString());
    }

    // 2. for each region, write all the info to disk
    LOG.info("Starting to write region info and WALs for regions for offline snapshot:"
        + SnapshotDescriptionUtils.toString(snapshot));
    for (HRegionInfo regionInfo : regions) {
      // 2.1 copy the regionInfo files to the snapshot
      Path snapshotRegionDir = TakeSnapshotUtils.getRegionSnapshotDirectory(snapshot, rootDir,
        regionInfo.getEncodedName());
      HRegion.writeRegioninfoOnFilesystem(regionInfo, snapshotRegionDir, fs, conf);
      // check for error for each region
      monitor.rethrowException();

      // 2.2 for each region, copy over its recovered.edits directory
      Path regionDir = HRegion.getRegionDir(rootDir, regionInfo);
      new CopyRecoveredEditsTask(snapshot, monitor, fs, regionDir, snapshotRegionDir).call();
      monitor.rethrowException();
      status.setStatus("Completed copying recovered edits for offline snapshot of table: "
          + snapshot.getTable());

      // 2.3 reference all the files in the region
      new ReferenceRegionHFilesTask(snapshot, monitor, regionDir, fs, snapshotRegionDir).call();
      monitor.rethrowException();
      status.setStatus("Completed referencing HFiles for offline snapshot of table: " +
        snapshot.getTable());
    }

    // 3. write the table info to disk
    LOG.info("Starting to copy tableinfo for offline snapshot: " +
    SnapshotDescriptionUtils.toString(snapshot));
    TableInfoCopyTask tableInfoCopyTask = new TableInfoCopyTask(this.monitor, snapshot, fs,
        FSUtils.getRootDir(conf));
    tableInfoCopyTask.call();
    monitor.rethrowException();
    status.setStatus("Finished copying tableinfo for snapshot of table: " + snapshot.getTable());
  } catch (Exception e) {
    // make sure we capture the exception to propagate back to the client later
    String reason = "Failed snapshot " + SnapshotDescriptionUtils.toString(snapshot)
        + " due to exception:" + e.getMessage();
    ForeignException ee = new ForeignException(reason, e);
    monitor.receive(ee);
    status.abort("Snapshot of table: "+ snapshot.getTable() +" failed because " + e.getMessage());
  } finally {
    LOG.debug("Marking snapshot" + SnapshotDescriptionUtils.toString(snapshot)
        + " as finished.");

    // 6. mark the timer as finished - even if we got an exception, we don't need to time the
    // operation any further
    timeoutInjector.complete();
  }
}
项目:HBase-Research    文件:TestReferenceRegionHFilesTask.java   
@Test
public void testRun() throws IOException {
  FileSystem fs = UTIL.getTestFileSystem();
  // setup the region internals
  Path testdir = UTIL.getDataTestDir();
  Path regionDir = new Path(testdir, "region");
  Path family1 = new Path(regionDir, "fam1");
  // make an empty family
  Path family2 = new Path(regionDir, "fam2");
  fs.mkdirs(family2);

  // add some files to family 1
  Path file1 = new Path(family1, "05f99689ae254693836613d1884c6b63");
  fs.createNewFile(file1);
  Path file2 = new Path(family1, "7ac9898bf41d445aa0003e3d699d5d26");
  fs.createNewFile(file2);

  // create the snapshot directory
  Path snapshotRegionDir = new Path(testdir, HConstants.SNAPSHOT_DIR_NAME);
  fs.mkdirs(snapshotRegionDir);

  SnapshotDescription snapshot = SnapshotDescription.newBuilder().setName("name")
      .setTable("table").build();
  ForeignExceptionDispatcher monitor = Mockito.mock(ForeignExceptionDispatcher.class);
  ReferenceRegionHFilesTask task = new ReferenceRegionHFilesTask(snapshot, monitor, regionDir,
      fs, snapshotRegionDir);
  ReferenceRegionHFilesTask taskSpy = Mockito.spy(task);
  task.call();

  // make sure we never get an error
  Mockito.verify(taskSpy, Mockito.never()).snapshotFailure(Mockito.anyString(),
      Mockito.any(Exception.class));

  // verify that all the hfiles get referenced
  List<String> hfiles = new ArrayList<String>(2);
  FileStatus[] regions = FSUtils.listStatus(fs, snapshotRegionDir);
  for (FileStatus region : regions) {
    FileStatus[] fams = FSUtils.listStatus(fs, region.getPath());
    for (FileStatus fam : fams) {
      FileStatus[] files = FSUtils.listStatus(fs, fam.getPath());
      for (FileStatus file : files) {
        hfiles.add(file.getPath().getName());
      }
    }
  }
  assertTrue("Didn't reference :" + file1, hfiles.contains(file1.getName()));
  assertTrue("Didn't reference :" + file1, hfiles.contains(file2.getName()));
}
项目:hbase-0.94.8-qod    文件:DisabledTableSnapshotHandler.java   
@Override
public void snapshotRegions(List<Pair<HRegionInfo, ServerName>> regionsAndLocations)
    throws IOException, KeeperException {
  try {
    timeoutInjector.start();

    // 1. get all the regions hosting this table.

    // extract each pair to separate lists
    Set<String> serverNames = new HashSet<String>();
    Set<HRegionInfo> regions = new HashSet<HRegionInfo>();
    for (Pair<HRegionInfo, ServerName> p : regionsAndLocations) {
      regions.add(p.getFirst());
      serverNames.add(p.getSecond().toString());
    }

    // 2. for each region, write all the info to disk
    LOG.info("Starting to write region info and WALs for regions for offline snapshot:"
        + SnapshotDescriptionUtils.toString(snapshot));
    for (HRegionInfo regionInfo : regions) {
      // 2.1 copy the regionInfo files to the snapshot
      Path snapshotRegionDir = TakeSnapshotUtils.getRegionSnapshotDirectory(snapshot, rootDir,
        regionInfo.getEncodedName());
      HRegion.writeRegioninfoOnFilesystem(regionInfo, snapshotRegionDir, fs, conf);
      // check for error for each region
      monitor.rethrowException();

      // 2.2 for each region, copy over its recovered.edits directory
      Path regionDir = HRegion.getRegionDir(rootDir, regionInfo);
      new CopyRecoveredEditsTask(snapshot, monitor, fs, regionDir, snapshotRegionDir).call();
      monitor.rethrowException();
      status.setStatus("Completed copying recovered edits for offline snapshot of table: "
          + snapshot.getTable());

      // 2.3 reference all the files in the region
      new ReferenceRegionHFilesTask(snapshot, monitor, regionDir, fs, snapshotRegionDir).call();
      monitor.rethrowException();
      status.setStatus("Completed referencing HFiles for offline snapshot of table: " +
        snapshot.getTable());
    }

    // 3. write the table info to disk
    LOG.info("Starting to copy tableinfo for offline snapshot: " +
    SnapshotDescriptionUtils.toString(snapshot));
    TableInfoCopyTask tableInfoCopyTask = new TableInfoCopyTask(this.monitor, snapshot, fs,
        FSUtils.getRootDir(conf));
    tableInfoCopyTask.call();
    monitor.rethrowException();
    status.setStatus("Finished copying tableinfo for snapshot of table: " + snapshot.getTable());
  } catch (Exception e) {
    // make sure we capture the exception to propagate back to the client later
    String reason = "Failed snapshot " + SnapshotDescriptionUtils.toString(snapshot)
        + " due to exception:" + e.getMessage();
    ForeignException ee = new ForeignException(reason, e);
    monitor.receive(ee);
    status.abort("Snapshot of table: "+ snapshot.getTable() +" failed because " + e.getMessage());
  } finally {
    LOG.debug("Marking snapshot" + SnapshotDescriptionUtils.toString(snapshot)
        + " as finished.");

    // 6. mark the timer as finished - even if we got an exception, we don't need to time the
    // operation any further
    timeoutInjector.complete();
  }
}
项目:hbase-0.94.8-qod    文件:TestReferenceRegionHFilesTask.java   
@Test
public void testRun() throws IOException {
  FileSystem fs = UTIL.getTestFileSystem();
  // setup the region internals
  Path testdir = UTIL.getDataTestDir();
  Path regionDir = new Path(testdir, "region");
  Path family1 = new Path(regionDir, "fam1");
  // make an empty family
  Path family2 = new Path(regionDir, "fam2");
  fs.mkdirs(family2);

  // add some files to family 1
  Path file1 = new Path(family1, "05f99689ae254693836613d1884c6b63");
  fs.createNewFile(file1);
  Path file2 = new Path(family1, "7ac9898bf41d445aa0003e3d699d5d26");
  fs.createNewFile(file2);

  // create the snapshot directory
  Path snapshotRegionDir = new Path(testdir, HConstants.SNAPSHOT_DIR_NAME);
  fs.mkdirs(snapshotRegionDir);

  SnapshotDescription snapshot = SnapshotDescription.newBuilder().setName("name")
      .setTable("table").build();
  ForeignExceptionDispatcher monitor = Mockito.mock(ForeignExceptionDispatcher.class);
  ReferenceRegionHFilesTask task = new ReferenceRegionHFilesTask(snapshot, monitor, regionDir,
      fs, snapshotRegionDir);
  ReferenceRegionHFilesTask taskSpy = Mockito.spy(task);
  task.call();

  // make sure we never get an error
  Mockito.verify(taskSpy, Mockito.never()).snapshotFailure(Mockito.anyString(),
      Mockito.any(Exception.class));

  // verify that all the hfiles get referenced
  List<String> hfiles = new ArrayList<String>(2);
  FileStatus[] regions = FSUtils.listStatus(fs, snapshotRegionDir);
  for (FileStatus region : regions) {
    FileStatus[] fams = FSUtils.listStatus(fs, region.getPath());
    for (FileStatus fam : fams) {
      FileStatus[] files = FSUtils.listStatus(fs, fam.getPath());
      for (FileStatus file : files) {
        hfiles.add(file.getPath().getName());
      }
    }
  }
  assertTrue("Didn't reference :" + file1, hfiles.contains(file1.getName()));
  assertTrue("Didn't reference :" + file1, hfiles.contains(file2.getName()));
}
项目:hbase-0.94.8-qod    文件:DisabledTableSnapshotHandler.java   
@Override
public void snapshotRegions(List<Pair<HRegionInfo, ServerName>> regionsAndLocations)
    throws IOException, KeeperException {
  try {
    timeoutInjector.start();

    // 1. get all the regions hosting this table.

    // extract each pair to separate lists
    Set<String> serverNames = new HashSet<String>();
    Set<HRegionInfo> regions = new HashSet<HRegionInfo>();
    for (Pair<HRegionInfo, ServerName> p : regionsAndLocations) {
      regions.add(p.getFirst());
      serverNames.add(p.getSecond().toString());
    }

    // 2. for each region, write all the info to disk
    LOG.info("Starting to write region info and WALs for regions for offline snapshot:"
        + SnapshotDescriptionUtils.toString(snapshot));
    for (HRegionInfo regionInfo : regions) {
      // 2.1 copy the regionInfo files to the snapshot
      Path snapshotRegionDir = TakeSnapshotUtils.getRegionSnapshotDirectory(snapshot, rootDir,
        regionInfo.getEncodedName());
      HRegion.writeRegioninfoOnFilesystem(regionInfo, snapshotRegionDir, fs, conf);
      // check for error for each region
      monitor.rethrowException();

      // 2.2 for each region, copy over its recovered.edits directory
      Path regionDir = HRegion.getRegionDir(rootDir, regionInfo);
      new CopyRecoveredEditsTask(snapshot, monitor, fs, regionDir, snapshotRegionDir).call();
      monitor.rethrowException();
      status.setStatus("Completed copying recovered edits for offline snapshot of table: "
          + snapshot.getTable());

      // 2.3 reference all the files in the region
      new ReferenceRegionHFilesTask(snapshot, monitor, regionDir, fs, snapshotRegionDir).call();
      monitor.rethrowException();
      status.setStatus("Completed referencing HFiles for offline snapshot of table: " +
        snapshot.getTable());
    }

    // 3. write the table info to disk
    LOG.info("Starting to copy tableinfo for offline snapshot: " +
    SnapshotDescriptionUtils.toString(snapshot));
    TableInfoCopyTask tableInfoCopyTask = new TableInfoCopyTask(this.monitor, snapshot, fs,
        FSUtils.getRootDir(conf));
    tableInfoCopyTask.call();
    monitor.rethrowException();
    status.setStatus("Finished copying tableinfo for snapshot of table: " + snapshot.getTable());
  } catch (Exception e) {
    // make sure we capture the exception to propagate back to the client later
    String reason = "Failed snapshot " + SnapshotDescriptionUtils.toString(snapshot)
        + " due to exception:" + e.getMessage();
    ForeignException ee = new ForeignException(reason, e);
    monitor.receive(ee);
    status.abort("Snapshot of table: "+ snapshot.getTable() +" failed because " + e.getMessage());
  } finally {
    LOG.debug("Marking snapshot" + SnapshotDescriptionUtils.toString(snapshot)
        + " as finished.");

    // 6. mark the timer as finished - even if we got an exception, we don't need to time the
    // operation any further
    timeoutInjector.complete();
  }
}
项目:hbase-0.94.8-qod    文件:TestReferenceRegionHFilesTask.java   
@Test
public void testRun() throws IOException {
  FileSystem fs = UTIL.getTestFileSystem();
  // setup the region internals
  Path testdir = UTIL.getDataTestDir();
  Path regionDir = new Path(testdir, "region");
  Path family1 = new Path(regionDir, "fam1");
  // make an empty family
  Path family2 = new Path(regionDir, "fam2");
  fs.mkdirs(family2);

  // add some files to family 1
  Path file1 = new Path(family1, "05f99689ae254693836613d1884c6b63");
  fs.createNewFile(file1);
  Path file2 = new Path(family1, "7ac9898bf41d445aa0003e3d699d5d26");
  fs.createNewFile(file2);

  // create the snapshot directory
  Path snapshotRegionDir = new Path(testdir, HConstants.SNAPSHOT_DIR_NAME);
  fs.mkdirs(snapshotRegionDir);

  SnapshotDescription snapshot = SnapshotDescription.newBuilder().setName("name")
      .setTable("table").build();
  ForeignExceptionDispatcher monitor = Mockito.mock(ForeignExceptionDispatcher.class);
  ReferenceRegionHFilesTask task = new ReferenceRegionHFilesTask(snapshot, monitor, regionDir,
      fs, snapshotRegionDir);
  ReferenceRegionHFilesTask taskSpy = Mockito.spy(task);
  task.call();

  // make sure we never get an error
  Mockito.verify(taskSpy, Mockito.never()).snapshotFailure(Mockito.anyString(),
      Mockito.any(Exception.class));

  // verify that all the hfiles get referenced
  List<String> hfiles = new ArrayList<String>(2);
  FileStatus[] regions = FSUtils.listStatus(fs, snapshotRegionDir);
  for (FileStatus region : regions) {
    FileStatus[] fams = FSUtils.listStatus(fs, region.getPath());
    for (FileStatus fam : fams) {
      FileStatus[] files = FSUtils.listStatus(fs, fam.getPath());
      for (FileStatus file : files) {
        hfiles.add(file.getPath().getName());
      }
    }
  }
  assertTrue("Didn't reference :" + file1, hfiles.contains(file1.getName()));
  assertTrue("Didn't reference :" + file1, hfiles.contains(file2.getName()));
}
项目:hindex    文件:DisabledTableSnapshotHandler.java   
@Override
public void snapshotRegions(List<Pair<HRegionInfo, ServerName>> regionsAndLocations)
    throws IOException, KeeperException {
  try {
    timeoutInjector.start();

    // 1. get all the regions hosting this table.

    // extract each pair to separate lists
    Set<String> serverNames = new HashSet<String>();
    Set<HRegionInfo> regions = new HashSet<HRegionInfo>();
    for (Pair<HRegionInfo, ServerName> p : regionsAndLocations) {
      regions.add(p.getFirst());
      serverNames.add(p.getSecond().toString());
    }

    // 2. for each region, write all the info to disk
    LOG.info("Starting to write region info and WALs for regions for offline snapshot:"
        + SnapshotDescriptionUtils.toString(snapshot));
    for (HRegionInfo regionInfo : regions) {
      // 2.1 copy the regionInfo files to the snapshot
      Path snapshotRegionDir = TakeSnapshotUtils.getRegionSnapshotDirectory(snapshot, rootDir,
        regionInfo.getEncodedName());
      HRegion.writeRegioninfoOnFilesystem(regionInfo, snapshotRegionDir, fs, conf);
      // check for error for each region
      monitor.rethrowException();

      // 2.2 for each region, copy over its recovered.edits directory
      Path regionDir = HRegion.getRegionDir(rootDir, regionInfo);
      new CopyRecoveredEditsTask(snapshot, monitor, fs, regionDir, snapshotRegionDir).call();
      monitor.rethrowException();
      status.setStatus("Completed copying recovered edits for offline snapshot of table: "
          + snapshot.getTable());

      // 2.3 reference all the files in the region
      new ReferenceRegionHFilesTask(snapshot, monitor, regionDir, fs, snapshotRegionDir).call();
      monitor.rethrowException();
      status.setStatus("Completed referencing HFiles for offline snapshot of table: " +
        snapshot.getTable());
    }

    // 3. write the table info to disk
    LOG.info("Starting to copy tableinfo for offline snapshot: " +
    SnapshotDescriptionUtils.toString(snapshot));
    TableInfoCopyTask tableInfoCopyTask = new TableInfoCopyTask(this.monitor, snapshot, fs,
        FSUtils.getRootDir(conf));
    tableInfoCopyTask.call();
    monitor.rethrowException();
    status.setStatus("Finished copying tableinfo for snapshot of table: " + snapshot.getTable());
  } catch (Exception e) {
    // make sure we capture the exception to propagate back to the client later
    String reason = "Failed snapshot " + SnapshotDescriptionUtils.toString(snapshot)
        + " due to exception:" + e.getMessage();
    ForeignException ee = new ForeignException(reason, e);
    monitor.receive(ee);
    status.abort("Snapshot of table: "+ snapshot.getTable() +" failed because " + e.getMessage());
  } finally {
    LOG.debug("Marking snapshot" + SnapshotDescriptionUtils.toString(snapshot)
        + " as finished.");

    // 6. mark the timer as finished - even if we got an exception, we don't need to time the
    // operation any further
    timeoutInjector.complete();
  }
}
项目:hindex    文件:TestReferenceRegionHFilesTask.java   
@Test
public void testRun() throws IOException {
  FileSystem fs = UTIL.getTestFileSystem();
  // setup the region internals
  Path testdir = UTIL.getDataTestDir();
  Path regionDir = new Path(testdir, "region");
  Path family1 = new Path(regionDir, "fam1");
  // make an empty family
  Path family2 = new Path(regionDir, "fam2");
  fs.mkdirs(family2);

  // add some files to family 1
  Path file1 = new Path(family1, "05f99689ae254693836613d1884c6b63");
  fs.createNewFile(file1);
  Path file2 = new Path(family1, "7ac9898bf41d445aa0003e3d699d5d26");
  fs.createNewFile(file2);

  // create the snapshot directory
  Path snapshotRegionDir = new Path(testdir, HConstants.SNAPSHOT_DIR_NAME);
  fs.mkdirs(snapshotRegionDir);

  SnapshotDescription snapshot = SnapshotDescription.newBuilder().setName("name")
      .setTable("table").build();
  ForeignExceptionDispatcher monitor = Mockito.mock(ForeignExceptionDispatcher.class);
  ReferenceRegionHFilesTask task = new ReferenceRegionHFilesTask(snapshot, monitor, regionDir,
      fs, snapshotRegionDir);
  ReferenceRegionHFilesTask taskSpy = Mockito.spy(task);
  task.call();

  // make sure we never get an error
  Mockito.verify(taskSpy, Mockito.never()).snapshotFailure(Mockito.anyString(),
      Mockito.any(Exception.class));

  // verify that all the hfiles get referenced
  List<String> hfiles = new ArrayList<String>(2);
  FileStatus[] regions = FSUtils.listStatus(fs, snapshotRegionDir);
  for (FileStatus region : regions) {
    FileStatus[] fams = FSUtils.listStatus(fs, region.getPath());
    for (FileStatus fam : fams) {
      FileStatus[] files = FSUtils.listStatus(fs, fam.getPath());
      for (FileStatus file : files) {
        hfiles.add(file.getPath().getName());
      }
    }
  }
  assertTrue("Didn't reference :" + file1, hfiles.contains(file1.getName()));
  assertTrue("Didn't reference :" + file1, hfiles.contains(file2.getName()));
}