Package org.apache.hadoop.hbase.snapshot

Examples of org.apache.hadoop.hbase.snapshot.HSnapshotDescription


   * @throws SnapshotCreationException if snapshot failed to be taken
   * @throws IllegalArgumentException if the snapshot request is formatted incorrectly
   */
  public void snapshot(SnapshotDescription snapshot) throws IOException, SnapshotCreationException,
      IllegalArgumentException {
    HSnapshotDescription snapshotWritable = new HSnapshotDescription(snapshot);

    try {
      // actually take the snapshot
      long max = takeSnapshotAsync(snapshot);
      long start = EnvironmentEdgeManager.currentTimeMillis();
View Full Code Here


   * @throws IllegalArgumentException if the snapshot request is formatted incorrectly
   */
  public long takeSnapshotAsync(SnapshotDescription snapshot) throws IOException,
      SnapshotCreationException {
    SnapshotDescriptionUtils.assertSnapshotRequestIsValid(snapshot);
    HSnapshotDescription snapshotWritable = new HSnapshotDescription(snapshot);
    return getMaster().snapshot(snapshotWritable);
  }
View Full Code Here

   * @throws UnknownSnapshotException if the requested snapshot is unknown
   */
  public boolean isSnapshotFinished(final SnapshotDescription snapshot)
      throws IOException, HBaseSnapshotException, UnknownSnapshotException {
    try {
      return getMaster().isSnapshotDone(new HSnapshotDescription(snapshot));
    } catch (RemoteException e) {
      throw RemoteExceptionHandler.decodeRemoteException(e);
    }
  }
View Full Code Here

   * @throws RestoreSnapshotException if snapshot failed to be restored
   * @throws IllegalArgumentException if the restore request is formatted incorrectly
   */
  private void internalRestoreSnapshot(final String snapshotName, final String tableName)
      throws IOException, RestoreSnapshotException {
    HSnapshotDescription snapshot = new HSnapshotDescription(
      SnapshotDescription.newBuilder().setName(snapshotName).setTable(tableName).build());

    try {
      // actually restore the snapshot
      getMaster().restoreSnapshot(snapshot);

      final long maxPauseTime = 5000;
      boolean done = false;
      int tries = 0;
      while (!done) {
        try {
          // sleep a backoff <= pauseTime amount
          long sleep = getPauseTime(tries++);
          sleep = sleep > maxPauseTime ? maxPauseTime : sleep;
          LOG.debug(tries + ") Sleeping: " + sleep + " ms while we wait for snapshot restore to complete.");
          Thread.sleep(sleep);
        } catch (InterruptedException e) {
          LOG.debug("Interrupted while waiting for snapshot " + snapshot + " restore to complete");
          Thread.currentThread().interrupt();
        }
        LOG.debug("Getting current status of snapshot restore from master...");
        done = getMaster().isRestoreSnapshotDone(snapshot);
      }
      if (!done) {
        throw new RestoreSnapshotException("Snapshot '" + snapshot.getName() + "' wasn't restored.");
      }
    } catch (RemoteException e) {
      throw RemoteExceptionHandler.decodeRemoteException(e);
    }
  }
View Full Code Here

    HTableDescriptor.isLegalTableName(snapshotName);
    // do the delete
    SnapshotDescription snapshot = SnapshotDescription.newBuilder()
      .setName(Bytes.toString(snapshotName)).build();
    try {
      getMaster().deleteSnapshot(new HSnapshotDescription(snapshot));
    } catch (RemoteException e) {
      throw RemoteExceptionHandler.decodeRemoteException(e);
    }
  }
View Full Code Here

    List<HSnapshotDescription> availableSnapshots = new ArrayList<HSnapshotDescription>();
    List<SnapshotDescription> snapshots = snapshotManager.getCompletedSnapshots();

    // convert to writables
    for (SnapshotDescription snapshot: snapshots) {
      availableSnapshots.add(new HSnapshotDescription(snapshot));
    }

    return availableSnapshots;
  }
View Full Code Here

  public void testIsDoneContract() throws Exception {

    String snapshotName = "asyncExpectedFailureTest";

    // check that we get an exception when looking up snapshot where one hasn't happened
    SnapshotTestingUtils.expectSnapshotDoneException(master, new HSnapshotDescription(),
      UnknownSnapshotException.class);

    // and that we get the same issue, even if we specify a name
    SnapshotDescription desc = SnapshotDescription.newBuilder()
      .setName(snapshotName).setTable(STRING_TABLE_NAME).build();
    SnapshotTestingUtils.expectSnapshotDoneException(master, new HSnapshotDescription(desc),
      UnknownSnapshotException.class);

    // set a mock handler to simulate a snapshot
    DisabledTableSnapshotHandler mockHandler = Mockito.mock(DisabledTableSnapshotHandler.class);
    Mockito.when(mockHandler.getException()).thenReturn(null);
    Mockito.when(mockHandler.getSnapshot()).thenReturn(desc);
    Mockito.when(mockHandler.isFinished()).thenReturn(new Boolean(true));
    Mockito.when(mockHandler.getCompletionTimestamp())
      .thenReturn(EnvironmentEdgeManager.currentTimeMillis());

    master.getSnapshotManagerForTesting()
        .setSnapshotHandlerForTesting(STRING_TABLE_NAME, mockHandler);

    // if we do a lookup without a snapshot name, we should fail - you should always know your name
    SnapshotTestingUtils.expectSnapshotDoneException(master, new HSnapshotDescription(),
      UnknownSnapshotException.class);

    // then do the lookup for the snapshot that it is done
    boolean isDone = master.isSnapshotDone(new HSnapshotDescription(desc));
    assertTrue("Snapshot didn't complete when it should have.", isDone);

    // now try the case where we are looking for a snapshot we didn't take
    desc = SnapshotDescription.newBuilder().setName("Not A Snapshot").build();
    SnapshotTestingUtils.expectSnapshotDoneException(master, new HSnapshotDescription(desc),
      UnknownSnapshotException.class);

    // then create a snapshot to the fs and make sure that we can find it when checking done
    snapshotName = "completed";
    Path snapshotDir = SnapshotDescriptionUtils.getCompletedSnapshotDir(snapshotName, rootDir);
    desc = desc.toBuilder().setName(snapshotName).build();
    SnapshotDescriptionUtils.writeSnapshotInfo(desc, snapshotDir, fs);

    isDone = master.isSnapshotDone(new HSnapshotDescription(desc));
    assertTrue("Completed, on-disk snapshot not found", isDone);
  }
View Full Code Here

    SnapshotDescriptionUtils.writeSnapshotInfo(snapshot, snapshotDir, fs);

    // check that we get one snapshot
    snapshots = master.getCompletedSnapshots();
    assertEquals("Found unexpected number of snapshots", 1, snapshots.size());
    List<HSnapshotDescription> expected = Lists.newArrayList(new HSnapshotDescription(snapshot));
    assertEquals("Returned snapshots don't match created snapshots", expected, snapshots);

    // write a second snapshot
    snapshotName = "completed_two";
    snapshotDir = SnapshotDescriptionUtils.getCompletedSnapshotDir(snapshotName, rootDir);
    snapshot = SnapshotDescription.newBuilder().setName(snapshotName).build();
    SnapshotDescriptionUtils.writeSnapshotInfo(snapshot, snapshotDir, fs);
    expected.add(new HSnapshotDescription(snapshot));

    // check that we get one snapshot
    snapshots = master.getCompletedSnapshots();
    assertEquals("Found unexpected number of snapshots", 2, snapshots.size());
    assertEquals("Returned snapshots don't match created snapshots", expected, snapshots);
View Full Code Here

    String snapshotName = "completed";
    SnapshotDescription snapshot = SnapshotDescription.newBuilder().setName(snapshotName).build();

    try {
      master.deleteSnapshot(new HSnapshotDescription(snapshot));
      fail("Master didn't throw exception when attempting to delete snapshot that doesn't exist");
    } catch (IOException e) {
      LOG.debug("Correctly failed delete of non-existant snapshot:" + e.getMessage());
    }

    // write one snapshot to the fs
    Path snapshotDir = SnapshotDescriptionUtils.getCompletedSnapshotDir(snapshotName, rootDir);
    SnapshotDescriptionUtils.writeSnapshotInfo(snapshot, snapshotDir, fs);

    // then delete the existing snapshot,which shouldn't cause an exception to be thrown
    master.deleteSnapshot(new HSnapshotDescription(snapshot));
  }
View Full Code Here

    List<HSnapshotDescription> availableSnapshots = new ArrayList<HSnapshotDescription>();
    List<SnapshotDescription> snapshots = snapshotManager.getCompletedSnapshots();

    // convert to writables
    for (SnapshotDescription snapshot: snapshots) {
      availableSnapshots.add(new HSnapshotDescription(snapshot));
    }

    return availableSnapshots;
  }
View Full Code Here

TOP

Related Classes of org.apache.hadoop.hbase.snapshot.HSnapshotDescription

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.