当前位置: 首页>>代码示例>>Java>>正文


Java SnapshotDescription类代码示例

本文整理汇总了Java中org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.SnapshotDescription的典型用法代码示例。如果您正苦于以下问题:Java SnapshotDescription类的具体用法?Java SnapshotDescription怎么用?Java SnapshotDescription使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


SnapshotDescription类属于org.apache.hadoop.hbase.protobuf.generated.HBaseProtos包,在下文中一共展示了SnapshotDescription类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createSnapshotAndValidate

import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.SnapshotDescription; //导入依赖的package包/类
/**
 * Take a snapshot of the specified table and verify the given families.
 * Note that this will leave the table disabled in the case of an offline snapshot.
 */
public static void createSnapshotAndValidate(Admin admin,
    TableName tableName, List<byte[]> nonEmptyFamilyNames, List<byte[]> emptyFamilyNames,
    String snapshotNameString, Path rootDir, FileSystem fs, boolean onlineSnapshot)
      throws Exception {
  if (!onlineSnapshot) {
    try {
      admin.disableTable(tableName);
    } catch (TableNotEnabledException tne) {
      LOG.info("In attempting to disable " + tableName + " it turns out that the this table is " +
          "already disabled.");
    }
  }
  admin.snapshot(snapshotNameString, tableName);

  List<SnapshotDescription> snapshots = SnapshotTestingUtils.assertExistsMatchingSnapshot(admin,
    snapshotNameString, tableName);
  if (snapshots == null || snapshots.size() != 1) {
    Assert.fail("Incorrect number of snapshots for table " + tableName);
  }

  SnapshotTestingUtils.confirmSnapshotValid(snapshots.get(0), tableName, nonEmptyFamilyNames,
    emptyFamilyNames, rootDir, admin, fs);
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:28,代码来源:SnapshotTestingUtils.java

示例2: testAsyncFlushSnapshot

import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.SnapshotDescription; //导入依赖的package包/类
@Test(timeout = 300000)
public void testAsyncFlushSnapshot() throws Exception {
  Admin admin = UTIL.getHBaseAdmin();
  SnapshotDescription snapshot = SnapshotDescription.newBuilder().setName("asyncSnapshot")
      .setTable(TABLE_NAME.getNameAsString())
      .setType(SnapshotDescription.Type.FLUSH)
      .build();

  // take the snapshot async
  admin.takeSnapshotAsync(snapshot);

  // constantly loop, looking for the snapshot to complete
  HMaster master = UTIL.getMiniHBaseCluster().getMaster();
  SnapshotTestingUtils.waitForSnapshotToComplete(master, snapshot, 200);
  LOG.info(" === Async Snapshot Completed ===");
  UTIL.getHBaseCluster().getMaster().getMasterFileSystem().logFileSystemState(LOG);

  // make sure we get the snapshot
  SnapshotTestingUtils.assertOneSnapshotThatMatches(admin, snapshot);
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:21,代码来源:TestFlushSnapshotFromClient.java

示例3: deleteSnapshot

import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.SnapshotDescription; //导入依赖的package包/类
/**
 * Delete an existing snapshot.
 * @param snapshotName name of the snapshot
 * @throws IOException if a remote or network exception occurs
 */
@Override
public void deleteSnapshot(final String snapshotName) throws IOException {
  // make sure the snapshot is possibly valid
  TableName.isLegalFullyQualifiedTableName(Bytes.toBytes(snapshotName));
  // do the delete
  executeCallable(new MasterCallable<Void>(getConnection()) {
    @Override
    public Void call(int callTimeout) throws ServiceException {
      PayloadCarryingRpcController controller = rpcControllerFactory.newController();
      controller.setCallTimeout(callTimeout);
      master.deleteSnapshot(controller,
        DeleteSnapshotRequest.newBuilder().
          setSnapshot(SnapshotDescription.newBuilder().setName(snapshotName).build()).build()
      );
      return null;
    }
  });
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:24,代码来源:HBaseAdmin.java

示例4: isTakingSnapshot

import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.SnapshotDescription; //导入依赖的package包/类
/**
 * Check to see if there is a snapshot in progress with the same name or on the same table.
 * Currently we have a limitation only allowing a single snapshot per table at a time. Also we
 * don't allow snapshot with the same name.
 * @param snapshot description of the snapshot being checked.
 * @return <tt>true</tt> if there is a snapshot in progress with the same name or on the same
 *         table.
 */
synchronized boolean isTakingSnapshot(final SnapshotDescription snapshot) {
  TableName snapshotTable = TableName.valueOf(snapshot.getTable());
  if (isTakingSnapshot(snapshotTable)) {
    return true;
  }
  Iterator<Map.Entry<TableName, SnapshotSentinel>> it = this.snapshotHandlers.entrySet().iterator();
  while (it.hasNext()) {
    Map.Entry<TableName, SnapshotSentinel> entry = it.next();
    SnapshotSentinel sentinel = entry.getValue();
    if (snapshot.getName().equals(sentinel.getSnapshot().getName()) && !sentinel.isFinished()) {
      return true;
    }
  }
  return false;
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:24,代码来源:SnapshotManager.java

示例5: snapshotTable

import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.SnapshotDescription; //导入依赖的package包/类
/**
 * Take a snapshot using the specified handler.
 * On failure the snapshot temporary working directory is removed.
 * NOTE: prepareToTakeSnapshot() called before this one takes care of the rejecting the
 *       snapshot request if the table is busy with another snapshot/restore operation.
 * @param snapshot the snapshot description
 * @param handler the snapshot handler
 */
private synchronized void snapshotTable(SnapshotDescription snapshot,
    final TakeSnapshotHandler handler) throws HBaseSnapshotException {
  try {
    handler.prepare();
    this.executorService.submit(handler);
    this.snapshotHandlers.put(TableName.valueOf(snapshot.getTable()), handler);
  } catch (Exception e) {
    // cleanup the working directory by trying to delete it from the fs.
    Path workingDir = SnapshotDescriptionUtils.getWorkingSnapshotDir(snapshot, rootDir);
    try {
      if (!this.master.getMasterFileSystem().getFileSystem().delete(workingDir, true)) {
        LOG.error("Couldn't delete working directory (" + workingDir + " for snapshot:" +
            ClientSnapshotDescriptionUtils.toString(snapshot));
      }
    } catch (IOException e1) {
      LOG.error("Couldn't delete working directory (" + workingDir + " for snapshot:" +
          ClientSnapshotDescriptionUtils.toString(snapshot));
    }
    // fail the snapshot
    throw new SnapshotCreationException("Could not build snapshot handler", e, snapshot);
  }
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:31,代码来源:SnapshotManager.java

示例6: removeSentinelIfFinished

import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.SnapshotDescription; //导入依赖的package包/类
/**
 * Return the handler if it is currently live and has the same snapshot target name.
 * The handler is removed from the sentinels map if completed.
 * @param sentinels live handlers
 * @param snapshot snapshot description
 * @return null if doesn't match, else a live handler.
 */
private synchronized SnapshotSentinel removeSentinelIfFinished(
    final Map<TableName, SnapshotSentinel> sentinels,
    final SnapshotDescription snapshot) {
  if (!snapshot.hasTable()) {
    return null;
  }

  TableName snapshotTable = TableName.valueOf(snapshot.getTable());
  SnapshotSentinel h = sentinels.get(snapshotTable);
  if (h == null) {
    return null;
  }

  if (!h.getSnapshot().getName().equals(snapshot.getName())) {
    // specified snapshot is to the one currently running
    return null;
  }

  // Remove from the "in-progress" list once completed
  if (h.isFinished()) {
    sentinels.remove(snapshotTable);
  }

  return h;
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:33,代码来源:SnapshotManager.java

示例7: RestoreSnapshotHandler

import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.SnapshotDescription; //导入依赖的package包/类
public RestoreSnapshotHandler(final MasterServices masterServices,
    final SnapshotDescription snapshot, final HTableDescriptor htd) throws IOException {
  super(EventType.C_M_RESTORE_SNAPSHOT, htd.getTableName(), masterServices, masterServices);

  // Snapshot information
  this.snapshot = snapshot;

  // Monitor
  this.monitor = new ForeignExceptionDispatcher();

  // Check table exists.
  getTableDescriptor();

  // This is the new schema we are going to write out as this modification.
  this.hTableDescriptor = htd;

  this.status = TaskMonitor.get().createStatus(
    "Restoring  snapshot '" + snapshot.getName() + "' to table "
        + hTableDescriptor.getTableName());
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:21,代码来源:RestoreSnapshotHandler.java

示例8: takeSnapshotAsync

import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.SnapshotDescription; //导入依赖的package包/类
/**
 * Take a snapshot without waiting for the server to complete that snapshot (asynchronous)
 * <p>
 * Only a single snapshot should be taken at a time, or results may be undefined.
 * @param snapshot snapshot to take
 * @return response from the server indicating the max time to wait for the snapshot
 * @throws IOException if the snapshot did not succeed or we lose contact with the master.
 * @throws SnapshotCreationException if snapshot creation failed
 * @throws IllegalArgumentException if the snapshot request is formatted incorrectly
 */
@Override
public SnapshotResponse takeSnapshotAsync(SnapshotDescription snapshot) throws IOException,
    SnapshotCreationException {
  ClientSnapshotDescriptionUtils.assertSnapshotRequestIsValid(snapshot);
  final SnapshotRequest request = SnapshotRequest.newBuilder().setSnapshot(snapshot)
      .build();
  // run the snapshot on the master
  return executeCallable(new MasterCallable<SnapshotResponse>(getConnection()) {
    @Override
    public SnapshotResponse call(int callTimeout) throws ServiceException {
      PayloadCarryingRpcController controller = rpcControllerFactory.newController();
      controller.setCallTimeout(callTimeout);
      return master.snapshot(controller, request);
    }
  });
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:27,代码来源:HBaseAdmin.java

示例9: snapshot

import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.SnapshotDescription; //导入依赖的package包/类
public static void snapshot(Admin admin,
    final String snapshotName, final String tableName,
    SnapshotDescription.Type type, int numTries) throws IOException {
  int tries = 0;
  CorruptedSnapshotException lastEx = null;
  while (tries++ < numTries) {
    try {
      admin.snapshot(snapshotName, TableName.valueOf(tableName), type);
      return;
    } catch (CorruptedSnapshotException cse) {
      LOG.warn("Got CorruptedSnapshotException", cse);
      lastEx = cse;
    }
  }
  throw lastEx;
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:17,代码来源:SnapshotTestingUtils.java

示例10: testCompleteSnapshotWithNoSnapshotDirectoryFailure

import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.SnapshotDescription; //导入依赖的package包/类
/**
 * Test that we throw an exception if there is no working snapshot directory when we attempt to
 * 'complete' the snapshot
 * @throws Exception on failure
 */
@Test
public void testCompleteSnapshotWithNoSnapshotDirectoryFailure() throws Exception {
  Path snapshotDir = new Path(root, HConstants.SNAPSHOT_DIR_NAME);
  Path tmpDir = new Path(snapshotDir, ".tmp");
  Path workingDir = new Path(tmpDir, "not_a_snapshot");
  assertFalse("Already have working snapshot dir: " + workingDir
      + " but shouldn't. Test file leak?", fs.exists(workingDir));
  SnapshotDescription snapshot = SnapshotDescription.newBuilder().setName("snapshot").build();
  try {
    SnapshotDescriptionUtils.completeSnapshot(snapshot, root, workingDir, fs);
    fail("Shouldn't successfully complete move of a non-existent directory.");
  } catch (IOException e) {
    LOG.info("Correctly failed to move non-existant directory: " + e.getMessage());
  }
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:21,代码来源:TestSnapshotDescriptionUtils.java

示例11: assertExistsMatchingSnapshot

import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.SnapshotDescription; //导入依赖的package包/类
/**
 * Make sure that there is only one snapshot returned from the master and its
 * name and table match the passed in parameters.
 */
public static List<SnapshotDescription> assertExistsMatchingSnapshot(
    Admin admin, String snapshotName, TableName tableName)
    throws IOException {
  // list the snapshot
  List<SnapshotDescription> snapshots = admin.listSnapshots();

  List<SnapshotDescription> returnedSnapshots = new ArrayList<SnapshotDescription>();
  for (SnapshotDescription sd : snapshots) {
    if (snapshotName.equals(sd.getName()) &&
        tableName.equals(TableName.valueOf(sd.getTable()))) {
      returnedSnapshots.add(sd);
    }
  }

  Assert.assertTrue("No matching snapshots found.", returnedSnapshots.size()>0);
  return returnedSnapshots;
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:22,代码来源:SnapshotTestingUtils.java

示例12: waitForSnapshotToComplete

import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.SnapshotDescription; //导入依赖的package包/类
/**
 * Helper method for testing async snapshot operations. Just waits for the
 * given snapshot to complete on the server by repeatedly checking the master.
 *
 * @param master: the master running the snapshot
 * @param snapshot: the snapshot to check
 * @param sleep: amount to sleep between checks to see if the snapshot is done
 * @throws ServiceException if the snapshot fails
 */
public static void waitForSnapshotToComplete(HMaster master,
    SnapshotDescription snapshot, long sleep) throws ServiceException {
  final IsSnapshotDoneRequest request = IsSnapshotDoneRequest.newBuilder()
      .setSnapshot(snapshot).build();
  IsSnapshotDoneResponse done = IsSnapshotDoneResponse.newBuilder()
      .buildPartial();
  while (!done.getDone()) {
    done = master.getMasterRpcServices().isSnapshotDone(null, request);
    try {
      Thread.sleep(sleep);
    } catch (InterruptedException e) {
      throw new ServiceException(e);
    }
  }
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:25,代码来源:SnapshotTestingUtils.java

示例13: validate

import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.SnapshotDescription; //导入依赖的package包/类
/**
 * Convert the passed snapshot description into a 'full' snapshot description based on default
 * parameters, if none have been supplied. This resolves any 'optional' parameters that aren't
 * supplied to their default values.
 * @param snapshot general snapshot descriptor
 * @param conf Configuration to read configured snapshot defaults if snapshot is not complete
 * @return a valid snapshot description
 * @throws IllegalArgumentException if the {@link SnapshotDescription} is not a complete
 *           {@link SnapshotDescription}.
 */
public static SnapshotDescription validate(SnapshotDescription snapshot, Configuration conf)
    throws IllegalArgumentException {
  if (!snapshot.hasTable()) {
    throw new IllegalArgumentException(
      "Descriptor doesn't apply to a table, so we can't build it.");
  }

  // set the creation time, if one hasn't been set
  long time = snapshot.getCreationTime();
  if (time == SnapshotDescriptionUtils.NO_SNAPSHOT_START_TIME_SPECIFIED) {
    time = EnvironmentEdgeManager.currentTime();
    LOG.debug("Creation time not specified, setting to:" + time + " (current time:"
        + EnvironmentEdgeManager.currentTime() + ").");
    SnapshotDescription.Builder builder = snapshot.toBuilder();
    builder.setCreationTime(time);
    snapshot = builder.build();
  }
  return snapshot;
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:30,代码来源:SnapshotDescriptionUtils.java

示例14: writeSnapshotInfo

import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.SnapshotDescription; //导入依赖的package包/类
/**
 * Write the snapshot description into the working directory of a snapshot
 * @param snapshot description of the snapshot being taken
 * @param workingDir working directory of the snapshot
 * @param fs {@link FileSystem} on which the snapshot should be taken
 * @throws IOException if we can't reach the filesystem and the file cannot be cleaned up on
 *           failure
 */
public static void writeSnapshotInfo(SnapshotDescription snapshot, Path workingDir, FileSystem fs)
    throws IOException {
  FsPermission perms = FSUtils.getFilePermissions(fs, fs.getConf(),
    HConstants.DATA_FILE_UMASK_KEY);
  Path snapshotInfo = new Path(workingDir, SnapshotDescriptionUtils.SNAPSHOTINFO_FILE);
  try {
    FSDataOutputStream out = FSUtils.create(fs, snapshotInfo, perms, true);
    try {
      snapshot.writeTo(out);
    } finally {
      out.close();
    }
  } catch (IOException e) {
    // if we get an exception, try to remove the snapshot info
    if (!fs.delete(snapshotInfo, false)) {
      String msg = "Couldn't delete snapshot info file: " + snapshotInfo;
      LOG.error(msg);
      throw new IOException(msg);
    }
  }
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:30,代码来源:SnapshotDescriptionUtils.java

示例15: readSnapshotInfo

import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.SnapshotDescription; //导入依赖的package包/类
/**
 * Read in the {@link org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.SnapshotDescription} stored for the snapshot in the passed directory
 * @param fs filesystem where the snapshot was taken
 * @param snapshotDir directory where the snapshot was stored
 * @return the stored snapshot description
 * @throws CorruptedSnapshotException if the
 * snapshot cannot be read
 */
public static SnapshotDescription readSnapshotInfo(FileSystem fs, Path snapshotDir)
    throws CorruptedSnapshotException {
  Path snapshotInfo = new Path(snapshotDir, SNAPSHOTINFO_FILE);
  try {
    FSDataInputStream in = null;
    try {
      in = fs.open(snapshotInfo);
      SnapshotDescription desc = SnapshotDescription.parseFrom(in);
      return desc;
    } finally {
      if (in != null) in.close();
    }
  } catch (IOException e) {
    throw new CorruptedSnapshotException("Couldn't read snapshot info from:" + snapshotInfo, e);
  }
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:25,代码来源:SnapshotDescriptionUtils.java


注:本文中的org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.SnapshotDescription类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。