/** * Get the default working directory for snapshots - where they are built, where they are * temporarily copied on export, etc. * @param rootDir root directory of the HBase installation * @return Path to the default snapshot tmp directory, relative to the passed root directory */ private static Path getDefaultWorkingSnapshotDir(final Path rootDir) { return new Path(getSnapshotsDir(rootDir), SNAPSHOT_TMP_DIR_NAME); }
/** * Gets the list of all completed snapshots. * @return list of SnapshotDescriptions * @throws IOException File system exception */ public List<SnapshotDescription> getCompletedSnapshots() throws IOException { return getCompletedSnapshots(SnapshotDescriptionUtils.getSnapshotsDir(rootDir), true); }
/** * Get the directory for a completed snapshot. This directory is a sub-directory of snapshot root * directory and all the data files for a snapshot are kept under this directory. * @param snapshotName name of the snapshot being taken * @param rootDir hbase root directory * @return the final directory for the completed snapshot */ public static Path getCompletedSnapshotDir(final String snapshotName, final Path rootDir) { return getSpecifiedSnapshotDir(getSnapshotsDir(rootDir), snapshotName); }
/** * Create a snapshot file cache for all snapshots under the specified [root]/.snapshot on the * filesystem * @param fs {@link FileSystem} where the snapshots are stored * @param rootDir hbase root directory * @param cacheRefreshPeriod period (ms) with which the cache should be refreshed * @param cacheRefreshDelay amount of time to wait for the cache to be refreshed * @param refreshThreadName name of the cache refresh thread * @param inspectSnapshotFiles Filter to apply to each snapshot to extract the files. */ public SnapshotFileCache(FileSystem fs, Path rootDir, long cacheRefreshPeriod, long cacheRefreshDelay, String refreshThreadName, SnapshotFileInspector inspectSnapshotFiles) { this.fs = fs; this.fileInspector = inspectSnapshotFiles; this.snapshotDir = SnapshotDescriptionUtils.getSnapshotsDir(rootDir); // periodically refresh the file cache to make sure we aren't superfluously saving files. this.refreshTimer = new Timer(refreshThreadName, true); this.refreshTimer.scheduleAtFixedRate(new RefreshCacheTask(), cacheRefreshDelay, cacheRefreshPeriod); }
/** * Returns the list of available snapshots in the specified location * @param conf the {@link Configuration} to use * @return the list of snapshots */ public static List<SnapshotDescription> getSnapshotList(final Configuration conf) throws IOException { Path rootDir = FSUtils.getRootDir(conf); FileSystem fs = FileSystem.get(rootDir.toUri(), conf); Path snapshotDir = SnapshotDescriptionUtils.getSnapshotsDir(rootDir); FileStatus[] snapshots = fs.listStatus(snapshotDir, new SnapshotDescriptionUtils.CompletedSnaphotDirectoriesFilter(fs)); List<SnapshotDescription> snapshotLists = new ArrayList<>(snapshots.length); for (FileStatus snapshotDirStat: snapshots) { SnapshotProtos.SnapshotDescription snapshotDesc = SnapshotDescriptionUtils.readSnapshotInfo(fs, snapshotDirStat.getPath()); snapshotLists.add(ProtobufUtil.createSnapshotDesc(snapshotDesc)); } return snapshotLists; }
Path snapshotDir = SnapshotDescriptionUtils.getSnapshotsDir(mfs.getRootDir()); if (fs.exists(snapshotDir)) { FileStatus[] snapshots = FSUtils.listStatus(fs, snapshotDir,
@After public void cleanupFiles() throws Exception { // cleanup the snapshot directory Path snapshotDir = SnapshotDescriptionUtils.getSnapshotsDir(rootDir); fs.delete(snapshotDir, true); }
private static boolean isAnySnapshots(FileSystem fs) throws IOException { Path snapshotDir = SnapshotDescriptionUtils.getSnapshotsDir(FSUtils.getRootDir(CONF)); FileStatus[] snapFiles = fs.listStatus(snapshotDir); if (snapFiles.length == 0) { return false; } Path firstPath = snapFiles[0].getPath(); LOG.info("firstPath in isAnySnapshots: " + firstPath); if (snapFiles.length == 1 && firstPath.getName().equals(".tmp")) { FileStatus[] tmpSnapFiles = fs.listStatus(firstPath); return tmpSnapFiles != null && tmpSnapFiles.length > 0; } return true; }
if (snapshotDir == null) snapshotDir = SnapshotDescriptionUtils.getSnapshotsDir(rootDir);
/** * Get the general working directory for snapshots - where they are built, where they are * temporarily copied on export, etc. * @param rootDir root directory of the HBase installation * @return Path to the snapshot tmp directory, relative to the passed root directory */ public static Path getWorkingSnapshotDir(final Path rootDir) { return new Path(getSnapshotsDir(rootDir), SNAPSHOT_TMP_DIR_NAME); }
/** * Get the general working directory for snapshots - where they are built, where they are * temporarily copied on export, etc. * @param rootDir root directory of the HBase installation * @return Path to the snapshot tmp directory, relative to the passed root directory */ public static Path getWorkingSnapshotDir(final Path rootDir) { return new Path(getSnapshotsDir(rootDir), SNAPSHOT_TMP_DIR_NAME); }
/** * Get the directory for a completed snapshot. This directory is a sub-directory of snapshot root * directory and all the data files for a snapshot are kept under this directory. * @param snapshotName name of the snapshot being taken * @param rootDir hbase root directory * @return the final directory for the completed snapshot */ public static Path getCompletedSnapshotDir(final String snapshotName, final Path rootDir) { return getCompletedSnapshotDir(getSnapshotsDir(rootDir), snapshotName); }
/** * Get the directory for a completed snapshot. This directory is a sub-directory of snapshot root * directory and all the data files for a snapshot are kept under this directory. * @param snapshotName name of the snapshot being taken * @param rootDir hbase root directory * @return the final directory for the completed snapshot */ public static Path getCompletedSnapshotDir(final String snapshotName, final Path rootDir) { return getCompletedSnapshotDir(getSnapshotsDir(rootDir), snapshotName); }
/** * Gets the list of all completed snapshots. * @return list of SnapshotDescriptions * @throws IOException File system exception */ public List<SnapshotDescription> getCompletedSnapshots() throws IOException { return getCompletedSnapshots(SnapshotDescriptionUtils.getSnapshotsDir(rootDir)); }
/** * Create a snapshot file cache for all snapshots under the specified [root]/.snapshot on the * filesystem * @param fs {@link FileSystem} where the snapshots are stored * @param rootDir hbase root directory * @param cacheRefreshPeriod period (ms) with which the cache should be refreshed * @param cacheRefreshDelay amount of time to wait for the cache to be refreshed * @param refreshThreadName name of the cache refresh thread * @param inspectSnapshotFiles Filter to apply to each snapshot to extract the files. */ public SnapshotFileCache(FileSystem fs, Path rootDir, long cacheRefreshPeriod, long cacheRefreshDelay, String refreshThreadName, SnapshotFileInspector inspectSnapshotFiles) { this.fs = fs; this.fileInspector = inspectSnapshotFiles; this.snapshotDir = SnapshotDescriptionUtils.getSnapshotsDir(rootDir); // periodically refresh the file cache to make sure we aren't superfluously saving files. this.refreshTimer = new Timer(refreshThreadName, true); this.refreshTimer.scheduleAtFixedRate(new RefreshCacheTask(), cacheRefreshDelay, cacheRefreshPeriod); }
/** * Create a snapshot file cache for all snapshots under the specified [root]/.snapshot on the * filesystem * @param fs {@link FileSystem} where the snapshots are stored * @param rootDir hbase root directory * @param cacheRefreshPeriod period (ms) with which the cache should be refreshed * @param cacheRefreshDelay amount of time to wait for the cache to be refreshed * @param refreshThreadName name of the cache refresh thread * @param inspectSnapshotFiles Filter to apply to each snapshot to extract the files. */ public SnapshotFileCache(FileSystem fs, Path rootDir, long cacheRefreshPeriod, long cacheRefreshDelay, String refreshThreadName, SnapshotFileInspector inspectSnapshotFiles) { this.fs = fs; this.fileInspector = inspectSnapshotFiles; this.snapshotDir = SnapshotDescriptionUtils.getSnapshotsDir(rootDir); // periodically refresh the file cache to make sure we aren't superfluously saving files. this.refreshTimer = new Timer(refreshThreadName, true); this.refreshTimer.scheduleAtFixedRate(new RefreshCacheTask(), cacheRefreshDelay, cacheRefreshPeriod); }
/** * Returns the list of available snapshots in the specified location * @param conf the {@link Configuration} to use * @return the list of snapshots */ public static List<SnapshotDescription> getSnapshotList(final Configuration conf) throws IOException { Path rootDir = FSUtils.getRootDir(conf); FileSystem fs = FileSystem.get(rootDir.toUri(), conf); Path snapshotDir = SnapshotDescriptionUtils.getSnapshotsDir(rootDir); FileStatus[] snapshots = fs.listStatus(snapshotDir, new SnapshotDescriptionUtils.CompletedSnaphotDirectoriesFilter(fs)); List<SnapshotDescription> snapshotLists = new ArrayList<SnapshotDescription>(snapshots.length); for (FileStatus snapshotDirStat: snapshots) { snapshotLists.add(SnapshotDescriptionUtils.readSnapshotInfo(fs, snapshotDirStat.getPath())); } return snapshotLists; }
@After public void cleanupFiles() throws Exception { // cleanup the snapshot directory Path snapshotDir = SnapshotDescriptionUtils.getSnapshotsDir(rootDir); fs.delete(snapshotDir, true); }
private static boolean isAnySnapshots(FileSystem fs) throws IOException { Path snapshotDir = SnapshotDescriptionUtils.getSnapshotsDir(FSUtils.getRootDir(CONF)); FileStatus[] snapFiles = fs.listStatus(snapshotDir); if (snapFiles.length == 0) { return false; } Path firstPath = snapFiles[0].getPath(); LOG.info("firstPath in isAnySnapshots: " + firstPath); if (snapFiles.length == 1 && firstPath.getName().equals(".tmp")) { FileStatus[] tmpSnapFiles = fs.listStatus(firstPath); return tmpSnapFiles != null && tmpSnapFiles.length > 0; } return true; }
/** * Migrates all snapshots, user tables and system tables that require migration. * First migrates snapshots. * Then migrates each user table in order, * then attempts ROOT (should be gone) * Migrates hbase:meta last to indicate migration is complete. */ private static void migrateFsTableDescriptors(FileSystem fs, Path rootDir) throws IOException { // First migrate snapshots - will migrate any snapshot dir that contains a table info file Path snapshotsDir = SnapshotDescriptionUtils.getSnapshotsDir(rootDir); if (fs.exists(snapshotsDir)) { LOG.info("Migrating snapshots"); FileStatus[] snapshots = fs.listStatus(snapshotsDir, new SnapshotDescriptionUtils.CompletedSnaphotDirectoriesFilter(fs)); for (FileStatus snapshot : snapshots) { migrateTable(fs, snapshot.getPath()); } } LOG.info("Migrating user tables"); List<Path> userTableDirs = FSUtils.getTableDirs(fs, rootDir); for (Path userTableDir : userTableDirs) { migrateTable(fs, userTableDir); } LOG.info("Migrating system tables"); // migrate meta last because that's what we check to see if migration is complete migrateTableIfExists(fs, rootDir, TableName.META_TABLE_NAME); }