use of org.apache.hadoop.hbase.client.SnapshotDescription in project hbase by apache.
the class CreateSnapshot method doWork.
@Override
protected int doWork() throws Exception {
Connection connection = null;
Admin admin = null;
try {
connection = ConnectionFactory.createConnection(getConf());
admin = connection.getAdmin();
admin.snapshot(new SnapshotDescription(snapshotName, tableName, snapshotType));
} catch (Exception e) {
System.err.println("failed to take the snapshot: " + e.getMessage());
return -1;
} finally {
if (admin != null) {
admin.close();
}
if (connection != null) {
connection.close();
}
}
return 0;
}
use of org.apache.hadoop.hbase.client.SnapshotDescription in project hbase by apache.
the class SnapshotInfo method doWork.
@Override
public int doWork() throws IOException, InterruptedException {
if (remoteDir != null) {
URI defaultFs = remoteDir.getFileSystem(conf).getUri();
FSUtils.setFsDefault(conf, new Path(defaultFs));
FSUtils.setRootDir(conf, remoteDir);
}
// List Available Snapshots
if (listSnapshots) {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
System.out.printf("%-20s | %-20s | %s%n", "SNAPSHOT", "CREATION TIME", "TABLE NAME");
for (SnapshotDescription desc : getSnapshotList(conf)) {
System.out.printf("%-20s | %20s | %s%n", desc.getName(), df.format(new Date(desc.getCreationTime())), desc.getTableNameAsString());
}
return 0;
}
rootDir = FSUtils.getRootDir(conf);
fs = FileSystem.get(rootDir.toUri(), conf);
LOG.debug("fs=" + fs.getUri().toString() + " root=" + rootDir);
// Load snapshot information
if (!loadSnapshotInfo(snapshotName)) {
System.err.println("Snapshot '" + snapshotName + "' not found!");
return 1;
}
printInfo();
if (showSchema)
printSchema();
printFiles(showFiles, showStats);
return 0;
}
use of org.apache.hadoop.hbase.client.SnapshotDescription in project hbase by apache.
the class SnapshotInfo method getSnapshotsFilesMap.
/**
* Returns the map of store files based on path for all snapshots
* @param conf the {@link Configuration} to use
* @param uniqueHFilesArchiveSize pass out the size for store files in archive
* @param uniqueHFilesSize pass out the size for store files shared
* @param uniqueHFilesMobSize pass out the size for mob store files shared
* @return the map of store files
*/
public static Map<Path, Integer> getSnapshotsFilesMap(final Configuration conf, AtomicLong uniqueHFilesArchiveSize, AtomicLong uniqueHFilesSize, AtomicLong uniqueHFilesMobSize) throws IOException {
List<SnapshotDescription> snapshotList = getSnapshotList(conf);
if (snapshotList.isEmpty()) {
return Collections.emptyMap();
}
ConcurrentHashMap<Path, Integer> fileMap = new ConcurrentHashMap<>();
ExecutorService exec = SnapshotManifest.createExecutor(conf, "SnapshotsFilesMapping");
try {
for (final SnapshotDescription snapshot : snapshotList) {
getSnapshotFilesMap(conf, snapshot, exec, fileMap, uniqueHFilesArchiveSize, uniqueHFilesSize, uniqueHFilesMobSize);
}
} finally {
exec.shutdown();
}
return fileMap;
}
use of org.apache.hadoop.hbase.client.SnapshotDescription in project hbase by apache.
the class SnapshotInfo method getSnapshotList.
/**
* 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) {
HBaseProtos.SnapshotDescription snapshotDesc = SnapshotDescriptionUtils.readSnapshotInfo(fs, snapshotDirStat.getPath());
snapshotLists.add(ProtobufUtil.createSnapshotDesc(snapshotDesc));
}
return snapshotLists;
}
use of org.apache.hadoop.hbase.client.SnapshotDescription in project hbase by apache.
the class SnapshotTestingUtils method assertExistsMatchingSnapshot.
/**
* 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<>();
for (SnapshotDescription sd : snapshots) {
if (snapshotName.equals(sd.getName()) && tableName.equals(sd.getTableName())) {
returnedSnapshots.add(sd);
}
}
Assert.assertTrue("No matching snapshots found.", returnedSnapshots.size() > 0);
return returnedSnapshots;
}
Aggregations