/** * Check to see if the snapshot is one of the currently completed snapshots * Returns true if the snapshot exists in the "completed snapshots folder". * * @param snapshot expected snapshot to check * @return <tt>true</tt> if the snapshot is stored on the {@link FileSystem}, <tt>false</tt> if is * not stored * @throws IOException if the filesystem throws an unexpected exception, * @throws IllegalArgumentException if snapshot name is invalid. */ private boolean isSnapshotCompleted(SnapshotDescription snapshot) throws IOException { try { final Path snapshotDir = SnapshotDescriptionUtils.getCompletedSnapshotDir(snapshot, rootDir); FileSystem fs = master.getMasterFileSystem().getFileSystem(); // check to see if the snapshot already exists return fs.exists(snapshotDir); } catch (IllegalArgumentException iae) { throw new UnknownSnapshotException("Unexpected exception thrown", iae); } }
@Override public boolean isSnapshotFinished(final SnapshotDescription snapshotDesc) throws IOException, HBaseSnapshotException, UnknownSnapshotException { final SnapshotProtos.SnapshotDescription snapshot = ProtobufUtil.createHBaseProtosSnapshotDesc(snapshotDesc); return executeCallable(new MasterCallable<IsSnapshotDoneResponse>(getConnection(), getRpcControllerFactory()) { @Override protected IsSnapshotDoneResponse rpcCall() throws Exception { return master.isSnapshotDone(getRpcController(), IsSnapshotDoneRequest.newBuilder().setSnapshot(snapshot).build()); } }).getDone(); }
/** * Check if the specified snapshot is done * * @param expected * @return true if snapshot is ready to be restored, false if it is still being taken. * @throws IOException IOException if error from HDFS or RPC * @throws UnknownSnapshotException if snapshot is invalid or does not exist. */ public boolean isSnapshotDone(SnapshotDescription expected) throws IOException { // check the request to make sure it has a snapshot if (expected == null) { throw new UnknownSnapshotException( "No snapshot name passed in request, can't figure out which snapshot you want to check."); } String ssString = ClientSnapshotDescriptionUtils.toString(expected); // check to see if the sentinel exists, // and if the task is complete removes it from the in-progress snapshots map. SnapshotSentinel handler = removeSentinelIfFinished(this.snapshotHandlers, expected); // stop tracking "abandoned" handlers cleanupSentinels(); if (handler == null) { // If there's no handler in the in-progress map, it means one of the following: // - someone has already requested the snapshot state // - the requested snapshot was completed long time ago (cleanupSentinels() timeout) // - the snapshot was never requested // In those cases returns to the user the "done state" if the snapshots exists on disk, // otherwise raise an exception saying that the snapshot is not running and doesn't exist. if (!isSnapshotCompleted(expected)) { throw new UnknownSnapshotException("Snapshot " + ssString + " is not currently running or one of the known completed snapshots."); } // was done, return true; return true; } // pass on any failure we find in the sentinel try { handler.rethrowExceptionIfFailed(); } catch (ForeignException e) { // Give some procedure info on an exception. String status; Procedure p = coordinator.getProcedure(expected.getName()); if (p != null) { status = p.getStatus(); } else { status = expected.getName() + " not found in proclist " + coordinator.getProcedureNames(); } throw new HBaseSnapshotException("Snapshot " + ssString + " had an error. " + status, e, expected); } // check to see if we are done if (handler.isFinished()) { LOG.debug("Snapshot '" + ssString + "' has completed, notifying client."); return true; } else if (LOG.isDebugEnabled()) { LOG.debug("Snapshoting '" + ssString + "' is still in progress!"); } return false; }
/** * Test that the contract from the master for checking on a snapshot are valid. * <p> * <ol> * <li>If a snapshot fails with an error, we expect to get the source error.</li> * <li>If there is no snapshot name supplied, we should get an error.</li> * <li>If asking about a snapshot has hasn't occurred, you should get an error.</li> * </ol> */ @Test(timeout = 300000) public void testIsDoneContract() throws Exception { IsSnapshotDoneRequest.Builder builder = IsSnapshotDoneRequest.newBuilder(); String snapshotName = "asyncExpectedFailureTest"; // check that we get an exception when looking up snapshot where one hasn't happened SnapshotTestingUtils.expectSnapshotDoneException(master, builder.build(), UnknownSnapshotException.class); // and that we get the same issue, even if we specify a name SnapshotDescription desc = SnapshotDescription.newBuilder() .setName(snapshotName).setTable(TABLE_NAME.getNameAsString()).build(); builder.setSnapshot(desc); SnapshotTestingUtils.expectSnapshotDoneException(master, builder.build(), 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.currentTime()); master.getSnapshotManagerForTesting() .setSnapshotHandlerForTesting(TABLE_NAME, mockHandler); // if we do a lookup without a snapshot name, we should fail - you should always know your name builder = IsSnapshotDoneRequest.newBuilder(); SnapshotTestingUtils.expectSnapshotDoneException(master, builder.build(), UnknownSnapshotException.class); // then do the lookup for the snapshot that it is done builder.setSnapshot(desc); IsSnapshotDoneResponse response = master.getMasterRpcServices().isSnapshotDone(null, builder.build()); assertTrue("Snapshot didn't complete when it should have.", response.getDone()); // now try the case where we are looking for a snapshot we didn't take builder.setSnapshot(SnapshotDescription.newBuilder().setName("Not A Snapshot").build()); SnapshotTestingUtils.expectSnapshotDoneException(master, builder.build(), 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); builder.setSnapshot(desc); response = master.getMasterRpcServices().isSnapshotDone(null, builder.build()); assertTrue("Completed, on-disk snapshot not found", response.getDone()); }
@Override public boolean isSnapshotFinished(SnapshotDescription sd) throws IOException, HBaseSnapshotException, UnknownSnapshotException { return wrappedHbaseAdmin.isSnapshotFinished(sd); }
/** * Check if the specified snapshot is done * * @param expected * @return true if snapshot is ready to be restored, false if it is still being taken. * @throws IOException IOException if error from HDFS or RPC * @throws UnknownSnapshotException if snapshot is invalid or does not exist. */ public boolean isSnapshotDone(SnapshotDescription expected) throws IOException { // check the request to make sure it has a snapshot if (expected == null) { throw new UnknownSnapshotException( "No snapshot name passed in request, can't figure out which snapshot you want to check."); } String ssString = SnapshotDescriptionUtils.toString(expected); // check to see if the sentinel exists, // and if the task is complete removes it from the in-progress snapshots map. SnapshotSentinel handler = removeSentinelIfFinished(this.snapshotHandlers, expected); // stop tracking "abandoned" handlers cleanupSentinels(); if (handler == null) { // If there's no handler in the in-progress map, it means one of the following: // - someone has already requested the snapshot state // - the requested snapshot was completed long time ago (cleanupSentinels() timeout) // - the snapshot was never requested // In those cases returns to the user the "done state" if the snapshots exists on disk, // otherwise raise an exception saying that the snapshot is not running and doesn't exist. if (!isSnapshotCompleted(expected)) { throw new UnknownSnapshotException("Snapshot " + ssString + " is not currently running or one of the known completed snapshots."); } // was done, return true; return true; } // pass on any failure we find in the sentinel try { handler.rethrowExceptionIfFailed(); } catch (ForeignException e) { // Give some procedure info on an exception. String status; Procedure p = coordinator.getProcedure(expected.getName()); if (p != null) { status = p.getStatus(); } else { status = expected.getName() + " not found in proclist " + coordinator.getProcedureNames(); } throw new HBaseSnapshotException("Snapshot " + ssString + " had an error. " + status, e, expected); } // check to see if we are done if (handler.isFinished()) { LOG.debug("Snapshot '" + ssString + "' has completed, notifying client."); return true; } else if (LOG.isDebugEnabled()) { LOG.debug("Snapshoting '" + ssString + "' is still in progress!"); } return false; }
/** * Test that the contract from the master for checking on a snapshot are valid. * <p> * <ol> * <li>If a snapshot fails with an error, we expect to get the source error.</li> * <li>If there is no snapshot name supplied, we should get an error.</li> * <li>If asking about a snapshot has hasn't occurred, you should get an error.</li> * </ol> */ @Test(timeout = 60000) 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); }
@Override public boolean isSnapshotFinished(HBaseProtos.SnapshotDescription snapshot) throws IOException, HBaseSnapshotException, UnknownSnapshotException { throw new UnsupportedOperationException("isSnapshotFinished"); // TODO }
/** * Test that the contract from the master for checking on a snapshot are valid. * <p> * <ol> * <li>If a snapshot fails with an error, we expect to get the source error.</li> * <li>If there is no snapshot name supplied, we should get an error.</li> * <li>If asking about a snapshot has hasn't occurred, you should get an error.</li> * </ol> */ @Test(timeout = 300000) public void testIsDoneContract() throws Exception { IsSnapshotDoneRequest.Builder builder = IsSnapshotDoneRequest.newBuilder(); String snapshotName = "asyncExpectedFailureTest"; // check that we get an exception when looking up snapshot where one hasn't happened SnapshotTestingUtils.expectSnapshotDoneException(master, builder.build(), UnknownSnapshotException.class); // and that we get the same issue, even if we specify a name SnapshotDescription desc = SnapshotDescription.newBuilder() .setName(snapshotName).setTable(TABLE_NAME.getNameAsString()).build(); builder.setSnapshot(desc); SnapshotTestingUtils.expectSnapshotDoneException(master, builder.build(), 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(TABLE_NAME, mockHandler); // if we do a lookup without a snapshot name, we should fail - you should always know your name builder = IsSnapshotDoneRequest.newBuilder(); SnapshotTestingUtils.expectSnapshotDoneException(master, builder.build(), UnknownSnapshotException.class); // then do the lookup for the snapshot that it is done builder.setSnapshot(desc); IsSnapshotDoneResponse response = master.isSnapshotDone(null, builder.build()); assertTrue("Snapshot didn't complete when it should have.", response.getDone()); // now try the case where we are looking for a snapshot we didn't take builder.setSnapshot(SnapshotDescription.newBuilder().setName("Not A Snapshot").build()); SnapshotTestingUtils.expectSnapshotDoneException(master, builder.build(), 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); builder.setSnapshot(desc); response = master.isSnapshotDone(null, builder.build()); assertTrue("Completed, on-disk snapshot not found", response.getDone()); }
public boolean isSnapshotFinished(SnapshotDescription snapshot) throws IOException, HBaseSnapshotException, UnknownSnapshotException { return delegate.isSnapshotFinished(snapshot); }
boolean isSnapshotFinished(SnapshotDescription snapshot) throws IOException, HBaseSnapshotException, UnknownSnapshotException;
/** * Check if the specified snapshot is done * * @param expected * @return true if snapshot is ready to be restored, false if it is still being taken. * @throws IOException IOException if error from HDFS or RPC * @throws UnknownSnapshotException if snapshot is invalid or does not exist. */ public boolean isSnapshotDone(SnapshotDescription expected) throws IOException { // check the request to make sure it has a snapshot if (expected == null) { throw new UnknownSnapshotException( "No snapshot name passed in request, can't figure out which snapshot you want to check."); } String ssString = ClientSnapshotDescriptionUtils.toString(expected); // check to see if the sentinel exists, // and if the task is complete removes it from the in-progress snapshots map. SnapshotSentinel handler = removeSentinelIfFinished(this.snapshotHandlers, expected); // stop tracking "abandoned" handlers cleanupSentinels(); if (handler == null) { // If there's no handler in the in-progress map, it means one of the following: // - someone has already requested the snapshot state // - the requested snapshot was completed long time ago (cleanupSentinels() timeout) // - the snapshot was never requested // In those cases returns to the user the "done state" if the snapshots exists on disk, // otherwise raise an exception saying that the snapshot is not running and doesn't exist. if (!isSnapshotCompleted(expected)) { throw new UnknownSnapshotException("Snapshot " + ssString + " is not currently running or one of the known completed snapshots."); } // was done, return true; return true; } // pass on any failure we find in the sentinel try { handler.rethrowExceptionIfFailed(); } catch (ForeignException e) { // Give some procedure info on an exception. String status; Procedure p = coordinator.getProcedure(expected.getName()); if (p != null) { status = p.getStatus(); } else { status = expected.getName() + " not found in proclist " + coordinator.getProcedureNames(); } throw new HBaseSnapshotException("Snapshot " + ssString + " had an error. " + status, e, ProtobufUtil.createSnapshotDesc(expected)); } // check to see if we are done if (handler.isFinished()) { LOG.debug("Snapshot '" + ssString + "' has completed, notifying client."); return true; } else if (LOG.isDebugEnabled()) { LOG.debug("Snapshoting '" + ssString + "' is still in progress!"); } return false; }
/** * Test that the contract from the master for checking on a snapshot are valid. * <p> * <ol> * <li>If a snapshot fails with an error, we expect to get the source error.</li> * <li>If there is no snapshot name supplied, we should get an error.</li> * <li>If asking about a snapshot has hasn't occurred, you should get an error.</li> * </ol> */ @Test(timeout = 300000) public void testIsDoneContract() throws Exception { IsSnapshotDoneRequest.Builder builder = IsSnapshotDoneRequest.newBuilder(); String snapshotName = "asyncExpectedFailureTest"; // check that we get an exception when looking up snapshot where one hasn't happened SnapshotTestingUtils.expectSnapshotDoneException(master, builder.build(), UnknownSnapshotException.class); // and that we get the same issue, even if we specify a name SnapshotDescription desc = SnapshotDescription.newBuilder() .setName(snapshotName).setTable(TABLE_NAME.getNameAsString()).build(); builder.setSnapshot(desc); SnapshotTestingUtils.expectSnapshotDoneException(master, builder.build(), 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(Boolean.TRUE); Mockito.when(mockHandler.getCompletionTimestamp()) .thenReturn(EnvironmentEdgeManager.currentTime()); master.getSnapshotManager() .setSnapshotHandlerForTesting(TABLE_NAME, mockHandler); // if we do a lookup without a snapshot name, we should fail - you should always know your name builder = IsSnapshotDoneRequest.newBuilder(); SnapshotTestingUtils.expectSnapshotDoneException(master, builder.build(), UnknownSnapshotException.class); // then do the lookup for the snapshot that it is done builder.setSnapshot(desc); IsSnapshotDoneResponse response = master.getMasterRpcServices().isSnapshotDone(null, builder.build()); assertTrue("Snapshot didn't complete when it should have.", response.getDone()); // now try the case where we are looking for a snapshot we didn't take builder.setSnapshot(SnapshotDescription.newBuilder().setName("Not A Snapshot").build()); SnapshotTestingUtils.expectSnapshotDoneException(master, builder.build(), UnknownSnapshotException.class); // then create a snapshot to the fs and make sure that we can find it when checking done snapshotName = "completed"; desc = createSnapshot(snapshotName); builder.setSnapshot(desc); response = master.getMasterRpcServices().isSnapshotDone(null, builder.build()); assertTrue("Completed, on-disk snapshot not found", response.getDone()); }
/** * Unsupported. */ public boolean isSnapshotFinished(SnapshotDescription snapshot) throws IOException, HBaseSnapshotException, UnknownSnapshotException { throw new UnsupportedOperationException(); }
/** * Test that the contract from the master for checking on a snapshot are valid. * <p> * <ol> * <li>If a snapshot fails with an error, we expect to get the source error.</li> * <li>If there is no snapshot name supplied, we should get an error.</li> * <li>If asking about a snapshot has hasn't occurred, you should get an error.</li> * </ol> */ @Test(timeout = 300000) public void testIsDoneContract() throws Exception { IsSnapshotDoneRequest.Builder builder = IsSnapshotDoneRequest.newBuilder(); String snapshotName = "asyncExpectedFailureTest"; // check that we get an exception when looking up snapshot where one hasn't happened SnapshotTestingUtils.expectSnapshotDoneException(master, builder.build(), UnknownSnapshotException.class); // and that we get the same issue, even if we specify a name SnapshotDescription desc = SnapshotDescription.newBuilder() .setName(snapshotName).setTable(TABLE_NAME.getNameAsString()).build(); builder.setSnapshot(desc); SnapshotTestingUtils.expectSnapshotDoneException(master, builder.build(), 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(TABLE_NAME, mockHandler); // if we do a lookup without a snapshot name, we should fail - you should always know your name builder = IsSnapshotDoneRequest.newBuilder(); SnapshotTestingUtils.expectSnapshotDoneException(master, builder.build(), UnknownSnapshotException.class); // then do the lookup for the snapshot that it is done builder.setSnapshot(desc); IsSnapshotDoneResponse response = master.getMasterRpcServices().isSnapshotDone(null, builder.build()); assertTrue("Snapshot didn't complete when it should have.", response.getDone()); // now try the case where we are looking for a snapshot we didn't take builder.setSnapshot(SnapshotDescription.newBuilder().setName("Not A Snapshot").build()); SnapshotTestingUtils.expectSnapshotDoneException(master, builder.build(), 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); builder.setSnapshot(desc); response = master.getMasterRpcServices().isSnapshotDone(null, builder.build()); assertTrue("Completed, on-disk snapshot not found", response.getDone()); }