Search in sources :

Example 1 with SnapshotDescription

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;
}
Also used : Connection(org.apache.hadoop.hbase.client.Connection) SnapshotDescription(org.apache.hadoop.hbase.client.SnapshotDescription) Admin(org.apache.hadoop.hbase.client.Admin)

Example 2 with SnapshotDescription

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;
}
Also used : Path(org.apache.hadoop.fs.Path) SnapshotDescription(org.apache.hadoop.hbase.client.SnapshotDescription) URI(java.net.URI) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 3 with SnapshotDescription

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;
}
Also used : Path(org.apache.hadoop.fs.Path) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ExecutorService(java.util.concurrent.ExecutorService) SnapshotDescription(org.apache.hadoop.hbase.client.SnapshotDescription) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 4 with SnapshotDescription

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;
}
Also used : Path(org.apache.hadoop.fs.Path) FileStatus(org.apache.hadoop.fs.FileStatus) FileSystem(org.apache.hadoop.fs.FileSystem) ArrayList(java.util.ArrayList) SnapshotDescription(org.apache.hadoop.hbase.client.SnapshotDescription) HBaseProtos(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos)

Example 5 with SnapshotDescription

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;
}
Also used : ArrayList(java.util.ArrayList) SnapshotDescription(org.apache.hadoop.hbase.client.SnapshotDescription)

Aggregations

SnapshotDescription (org.apache.hadoop.hbase.client.SnapshotDescription)11 Path (org.apache.hadoop.fs.Path)3 Admin (org.apache.hadoop.hbase.client.Admin)3 HBaseProtos (org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos)3 Test (org.junit.Test)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 TableName (org.apache.hadoop.hbase.TableName)2 URI (java.net.URI)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutorService (java.util.concurrent.ExecutorService)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 FileStatus (org.apache.hadoop.fs.FileStatus)1 FileSystem (org.apache.hadoop.fs.FileSystem)1 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)1 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)1 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)1