Search in sources :

Example 1 with SCMSnapshotDownloader

use of org.apache.hadoop.hdds.scm.ha.SCMSnapshotDownloader in project ozone by apache.

the class StorageContainerServiceProviderImpl method getSCMDBSnapshot.

public DBCheckpoint getSCMDBSnapshot() {
    String snapshotFileName = RECON_SCM_SNAPSHOT_DB + "_" + System.currentTimeMillis();
    File targetFile = new File(scmSnapshotDBParentDir, snapshotFileName + ".tar.gz");
    try {
        if (!SCMHAUtils.isSCMHAEnabled(configuration)) {
            SecurityUtil.doAsLoginUser(() -> {
                try (InputStream inputStream = reconUtils.makeHttpCall(connectionFactory, getScmDBSnapshotUrl(), isOmSpnegoEnabled()).getInputStream()) {
                    FileUtils.copyInputStreamToFile(inputStream, targetFile);
                }
                return null;
            });
            LOG.info("Downloaded SCM Snapshot from SCM");
        } else {
            List<String> ratisRoles = scmClient.getScmInfo().getRatisPeerRoles();
            for (String ratisRole : ratisRoles) {
                String[] role = ratisRole.split(":");
                if (role[2].equals(RaftProtos.RaftPeerRole.LEADER.toString())) {
                    String hostAddress = role[4].trim();
                    int grpcPort = configuration.getInt(ScmConfigKeys.OZONE_SCM_GRPC_PORT_KEY, ScmConfigKeys.OZONE_SCM_GRPC_PORT_DEFAULT);
                    try (SCMSnapshotDownloader downloadClient = new InterSCMGrpcClient(hostAddress, grpcPort, configuration, new ReconCertificateClient(new SecurityConfig(configuration), reconStorage.getReconCertSerialId()))) {
                        downloadClient.download(targetFile.toPath()).get();
                    } catch (ExecutionException | InterruptedException e) {
                        LOG.error("Rocks DB checkpoint downloading failed", e);
                        throw new IOException(e);
                    }
                    LOG.info("Downloaded SCM Snapshot from Leader SCM");
                    break;
                }
            }
        }
        Path untarredDbDir = Paths.get(scmSnapshotDBParentDir.getAbsolutePath(), snapshotFileName);
        reconUtils.untarCheckpointFile(targetFile, untarredDbDir);
        FileUtils.deleteQuietly(targetFile);
        return new RocksDBCheckpoint(untarredDbDir);
    } catch (IOException e) {
        LOG.error("Unable to obtain SCM DB Snapshot. ", e);
    }
    return null;
}
Also used : Path(java.nio.file.Path) RocksDBCheckpoint(org.apache.hadoop.hdds.utils.db.RocksDBCheckpoint) InputStream(java.io.InputStream) SCMSnapshotDownloader(org.apache.hadoop.hdds.scm.ha.SCMSnapshotDownloader) InterSCMGrpcClient(org.apache.hadoop.hdds.scm.ha.InterSCMGrpcClient) IOException(java.io.IOException) DBCheckpoint(org.apache.hadoop.hdds.utils.db.DBCheckpoint) RocksDBCheckpoint(org.apache.hadoop.hdds.utils.db.RocksDBCheckpoint) ReconCertificateClient(org.apache.hadoop.hdds.security.x509.certificate.client.ReconCertificateClient) SecurityConfig(org.apache.hadoop.hdds.security.x509.SecurityConfig) ExecutionException(java.util.concurrent.ExecutionException) File(java.io.File)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Path (java.nio.file.Path)1 ExecutionException (java.util.concurrent.ExecutionException)1 InterSCMGrpcClient (org.apache.hadoop.hdds.scm.ha.InterSCMGrpcClient)1 SCMSnapshotDownloader (org.apache.hadoop.hdds.scm.ha.SCMSnapshotDownloader)1 SecurityConfig (org.apache.hadoop.hdds.security.x509.SecurityConfig)1 ReconCertificateClient (org.apache.hadoop.hdds.security.x509.certificate.client.ReconCertificateClient)1 DBCheckpoint (org.apache.hadoop.hdds.utils.db.DBCheckpoint)1 RocksDBCheckpoint (org.apache.hadoop.hdds.utils.db.RocksDBCheckpoint)1