!fs.rename(workingDir, snapshotDir)) && !FileUtil.copy(workingDirFs, workingDir, fs, snapshotDir, true, true, this.conf)) { throw new SnapshotCreationException("Failed to copy working directory(" + workingDir + ") to completed directory(" + snapshotDir + ").");
@Test public void testSnapshotFailsOnNonExistantTable() throws Exception { // make sure we don't fail on listing snapshots SnapshotTestingUtils.assertNoSnapshots(admin); TableName tableName = TableName.valueOf("_not_a_table"); // make sure the table doesn't exist boolean fail = false; do { try { admin.getTableDescriptor(tableName); fail = true; LOG.error("Table:" + tableName + " already exists, checking a new name"); tableName = TableName.valueOf(tableName+"!"); } catch (TableNotFoundException e) { fail = false; } } while (fail); // snapshot the non-existant table try { admin.snapshot("fail", tableName, SnapshotType.FLUSH); fail("Snapshot succeeded even though there is not table."); } catch (SnapshotCreationException e) { LOG.info("Correctly failed to snapshot a non-existant table:" + e.getMessage()); } }
/** * Move the finished snapshot to its final, publicly visible directory - this marks the snapshot * as 'complete'. * @param snapshot description of the snapshot being tabken * @param rootdir root directory of the hbase installation * @param workingDir directory where the in progress snapshot was built * @param fs {@link FileSystem} where the snapshot was built * @throws org.apache.hadoop.hbase.snapshot.SnapshotCreationException if the * snapshot could not be moved * @throws IOException the filesystem could not be reached */ public static void completeSnapshot(SnapshotDescription snapshot, Path rootdir, Path workingDir, FileSystem fs) throws SnapshotCreationException, IOException { Path finishedDir = getCompletedSnapshotDir(snapshot, rootdir); LOG.debug("Snapshot is done, just moving the snapshot from " + workingDir + " to " + finishedDir); if (!fs.rename(workingDir, finishedDir)) { throw new SnapshotCreationException( "Failed to move working directory(" + workingDir + ") to completed directory(" + finishedDir + ").", ProtobufUtil.createSnapshotDesc(snapshot)); } }
@Test public void testSnapshotFailsOnNonExistantTable() throws Exception { Admin admin = UTIL.getAdmin(); // make sure we don't fail on listing snapshots SnapshotTestingUtils.assertNoSnapshots(admin); String tableName = "_not_a_table"; // make sure the table doesn't exist boolean fail = false; do { try { admin.getTableDescriptor(TableName.valueOf(tableName)); fail = true; LOG.error("Table:" + tableName + " already exists, checking a new name"); tableName = tableName+"!"; } catch (TableNotFoundException e) { fail = false; } } while (fail); // snapshot the non-existant table try { admin.snapshot("fail", TableName.valueOf(tableName)); fail("Snapshot succeeded even though there is not table."); } catch (SnapshotCreationException e) { LOG.info("Correctly failed to snapshot a non-existant table:" + e.getMessage()); } }
throw new SnapshotCreationException("Rejected taking " + ClientSnapshotDescriptionUtils.toString(snapshot) + " because we are already running another snapshot " throw new SnapshotCreationException("Rejected taking " + ClientSnapshotDescriptionUtils.toString(snapshot) + " because we are already have a restore in progress on the same snapshot."); throw new SnapshotCreationException("Couldn't create working directory (" + workingDir + ") for snapshot" , ProtobufUtil.createSnapshotDesc(snapshot)); throw e; } catch (IOException e) { throw new SnapshotCreationException( "Exception while checking to see if snapshot could be started.", e, ProtobufUtil.createSnapshotDesc(snapshot));
@Test public void testSnapshotFailsOnNonExistantTable() throws Exception { // make sure we don't fail on listing snapshots SnapshotTestingUtils.assertNoSnapshots(admin); TableName tableName = TableName.valueOf("_not_a_table"); // make sure the table doesn't exist boolean fail = false; do { try { admin.getTableDescriptor(tableName); fail = true; LOG.error("Table:" + tableName + " already exists, checking a new name"); tableName = TableName.valueOf(tableName+"!"); } catch (TableNotFoundException e) { fail = false; } } while (fail); // snapshot the non-existant table try { admin.snapshot("fail", tableName, SnapshotType.FLUSH); fail("Snapshot succeeded even though there is not table."); } catch (SnapshotCreationException e) { LOG.info("Correctly failed to snapshot a non-existant table:" + e.getMessage()); } }
throw new SnapshotCreationException("Could not build snapshot handler", e, ProtobufUtil.createSnapshotDesc(snapshot));
@Test public void testSnapshotFailsOnNonExistantTable() throws Exception { Admin admin = UTIL.getAdmin(); // make sure we don't fail on listing snapshots SnapshotTestingUtils.assertNoSnapshots(admin); String tableName = "_not_a_table"; // make sure the table doesn't exist boolean fail = false; do { try { admin.getTableDescriptor(TableName.valueOf(tableName)); fail = true; LOG.error("Table:" + tableName + " already exists, checking a new name"); tableName = tableName+"!"; } catch (TableNotFoundException e) { fail = false; } } while (fail); // snapshot the non-existant table try { admin.snapshot("fail", TableName.valueOf(tableName)); fail("Snapshot succeeded even though there is not table."); } catch (SnapshotCreationException e) { LOG.info("Correctly failed to snapshot a non-existant table:" + e.getMessage()); } }
throw new SnapshotCreationException("Snapshot '" + snapshot.getName() + "' wasn't completed in expectedTime:" + max + " ms", snapshotDesc);
String msg = "Table:" + snapshot.getTable() + " info doesn't exist!"; LOG.error(msg); throw new SnapshotCreationException(msg, e, ProtobufUtil.createSnapshotDesc(snapshot)); } catch (IOException e) { throw new SnapshotCreationException( "Error while geting table description for table " + snapshot.getTable(), e, ProtobufUtil.createSnapshotDesc(snapshot)); throw new SnapshotCreationException( "Table '" + snapshot.getTable() + "' doesn't exist, can't take snapshot.", ProtobufUtil.createSnapshotDesc(snapshot)); TablePartiallyOpenException tpoe = new TablePartiallyOpenException(snapshot.getTable() + " isn't fully open."); throw new SnapshotCreationException("Table is not entirely open or closed", tpoe, ProtobufUtil.createSnapshotDesc(snapshot));
throw new SnapshotCreationException("Snapshot '" + snapshot.getName() + "' wasn't completed in expectedTime:" + max + " ms", snapshotDesc);
/** * Reset the manager to allow another snapshot to proceed * * @param snapshotDir final path of the snapshot * @param workingDir directory where the in progress snapshot was built * @param fs {@link FileSystem} where the snapshot was built * @throws SnapshotCreationException if the snapshot could not be moved * @throws IOException the filesystem could not be reached */ public void completeSnapshot(Path snapshotDir, Path workingDir, FileSystem fs) throws SnapshotCreationException, IOException { LOG.debug("Sentinel is done, just moving the snapshot from " + workingDir + " to " + snapshotDir); if (!fs.rename(workingDir, snapshotDir)) { throw new SnapshotCreationException("Failed to move working directory(" + workingDir + ") to completed directory(" + snapshotDir + ")."); } finished = true; }
/** * Reset the manager to allow another snapshot to proceed * * @param snapshotDir final path of the snapshot * @param workingDir directory where the in progress snapshot was built * @param fs {@link FileSystem} where the snapshot was built * @throws SnapshotCreationException if the snapshot could not be moved * @throws IOException the filesystem could not be reached */ public void completeSnapshot(Path snapshotDir, Path workingDir, FileSystem fs) throws SnapshotCreationException, IOException { LOG.debug("Sentinel is done, just moving the snapshot from " + workingDir + " to " + snapshotDir); if (!fs.rename(workingDir, snapshotDir)) { throw new SnapshotCreationException("Failed to move working directory(" + workingDir + ") to completed directory(" + snapshotDir + ")."); } finished = true; }
/** * Move the finished snapshot to its final, publicly visible directory - this marks the snapshot * as 'complete'. * @param snapshot description of the snapshot being tabken * @param rootdir root directory of the hbase installation * @param workingDir directory where the in progress snapshot was built * @param fs {@link FileSystem} where the snapshot was built * @throws SnapshotCreationException if the snapshot could not be moved * @throws IOException the filesystem could not be reached */ public static void completeSnapshot(SnapshotDescription snapshot, Path rootdir, Path workingDir, FileSystem fs) throws SnapshotCreationException, IOException { Path finishedDir = getCompletedSnapshotDir(snapshot, rootdir); LOG.debug("Snapshot is done, just moving the snapshot from " + workingDir + " to " + finishedDir); if (!fs.rename(workingDir, finishedDir)) { throw new SnapshotCreationException("Failed to move working directory(" + workingDir + ") to completed directory(" + finishedDir + ").", snapshot); } }
/** * Move the finished snapshot to its final, publicly visible directory - this marks the snapshot * as 'complete'. * @param snapshot description of the snapshot being tabken * @param rootdir root directory of the hbase installation * @param workingDir directory where the in progress snapshot was built * @param fs {@link FileSystem} where the snapshot was built * @throws org.apache.hadoop.hbase.snapshot.SnapshotCreationException if the * snapshot could not be moved * @throws IOException the filesystem could not be reached */ public static void completeSnapshot(SnapshotDescription snapshot, Path rootdir, Path workingDir, FileSystem fs) throws SnapshotCreationException, IOException { Path finishedDir = getCompletedSnapshotDir(snapshot, rootdir); LOG.debug("Snapshot is done, just moving the snapshot from " + workingDir + " to " + finishedDir); if (!fs.rename(workingDir, finishedDir)) { throw new SnapshotCreationException("Failed to move working directory(" + workingDir + ") to completed directory(" + finishedDir + ").", snapshot); } }
throw new SnapshotCreationException("Rejected taking " + ClientSnapshotDescriptionUtils.toString(snapshot) + " because we are already running another snapshot " throw new SnapshotCreationException("Rejected taking " + ClientSnapshotDescriptionUtils.toString(snapshot) + " because we are already have a restore in progress on the same snapshot " throw new SnapshotCreationException("Couldn't create working directory (" + workingDir + ") for snapshot" , snapshot); throw e; } catch (IOException e) { throw new SnapshotCreationException( "Exception while checking to see if snapshot could be started.", e, snapshot);
throw new SnapshotCreationException("Rejected taking " + SnapshotDescriptionUtils.toString(snapshot) + " because we are already running another snapshot " throw new SnapshotCreationException("Rejected taking " + SnapshotDescriptionUtils.toString(snapshot) + " because we are already have a restore in progress on the same snapshot " throw new SnapshotCreationException("Couldn't create working directory (" + workingDir + ") for snapshot" , snapshot); throw e; } catch (IOException e) { throw new SnapshotCreationException( "Exception while checking to see if snapshot could be started.", e, snapshot);
throw new SnapshotCreationException("Could not build snapshot handler", e, snapshot);
throw new SnapshotCreationException("Snapshot '" + snapshot.getName() + "' wasn't completed in expectedTime:" + max + " ms", snapshot);
/** * 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); } }