Search in sources :

Example 1 with RemoteObjectReference

use of com.instaclustr.esop.impl.RemoteObjectReference in project esop by instaclustr.

the class LocalFileRestorer method delete.

@Override
public void delete(Path objectKey, boolean nodeAware) throws Exception {
    Path fileToDelete;
    if (nodeAware) {
        RemoteObjectReference remoteObjectReference = objectKeyToNodeAwareRemoteReference(objectKey);
        fileToDelete = request.storageLocation.fileBackupDirectory.resolve(request.storageLocation.bucket).resolve(remoteObjectReference.canonicalPath);
    } else {
        fileToDelete = request.storageLocation.fileBackupDirectory.resolve(request.storageLocation.bucket).resolve(objectKey);
    }
    Files.deleteIfExists(fileToDelete);
}
Also used : Path(java.nio.file.Path) RemoteObjectReference(com.instaclustr.esop.impl.RemoteObjectReference)

Example 2 with RemoteObjectReference

use of com.instaclustr.esop.impl.RemoteObjectReference in project esop by instaclustr.

the class BaseS3Restorer method delete.

@Override
public void delete(final Path objectKey, boolean nodeAware) throws Exception {
    RemoteObjectReference remoteObjectReference;
    if (nodeAware) {
        remoteObjectReference = objectKeyToNodeAwareRemoteReference(objectKey);
    } else {
        remoteObjectReference = objectKeyToRemoteReference(objectKey);
    }
    final Path fileToDelete = Paths.get(request.storageLocation.bucket, remoteObjectReference.canonicalPath);
    logger.info("Non dry: " + fileToDelete);
    amazonS3.deleteObject(new DeleteObjectRequest(request.storageLocation.bucket, remoteObjectReference.canonicalPath));
}
Also used : Path(java.nio.file.Path) DeleteObjectRequest(com.amazonaws.services.s3.model.DeleteObjectRequest) RemoteObjectReference(com.instaclustr.esop.impl.RemoteObjectReference)

Example 3 with RemoteObjectReference

use of com.instaclustr.esop.impl.RemoteObjectReference in project esop by instaclustr.

the class RestoreCommitLogsOperation method downloadCommitLogs.

private void downloadCommitLogs(final Restorer restorer) throws Exception {
    final RemoteObjectReference remoteObjectReference = restorer.objectKeyToNodeAwareRemoteReference(Paths.get("commitlog"));
    final Pattern commitlogPattern = Pattern.compile(".*(CommitLog-\\d+-\\d+\\.log)\\.(\\d+)");
    final Set<ManifestEntry> parsedCommitlogList = new HashSet<>();
    logger.info("Commencing processing of commit log listing");
    final AtomicReference<ManifestEntry> overhangingManifestEntry = new AtomicReference<>();
    final AtomicLong overhangingTimestamp = new AtomicLong(Long.MAX_VALUE);
    restorer.consumeFiles(remoteObjectReference, commitlogFile -> {
        final Matcher matcherCommitlog = commitlogPattern.matcher(commitlogFile.getObjectKey().toString());
        if (matcherCommitlog.matches()) {
            final long commitlogTimestamp = Long.parseLong(matcherCommitlog.group(2));
            if (commitlogTimestamp >= request.timestampStart && commitlogTimestamp <= request.timestampEnd) {
                parsedCommitlogList.add(new ManifestEntry(commitlogFile.getObjectKey(), request.commitlogDownloadDir.resolve(matcherCommitlog.group(1)), COMMIT_LOG, 0, null, null));
            } else if (commitlogTimestamp > request.timestampEnd && commitlogTimestamp < overhangingTimestamp.get()) {
                // Make sure we also catch the first commitlog that goes past the end of the timestamp
                overhangingTimestamp.set(commitlogTimestamp);
                overhangingManifestEntry.set(new ManifestEntry(commitlogFile.getObjectKey(), request.commitlogDownloadDir.resolve(matcherCommitlog.group(1)), COMMIT_LOG, 0, null, null));
            }
        }
    });
    if (overhangingManifestEntry.get() != null) {
        parsedCommitlogList.add(overhangingManifestEntry.get());
    }
    logger.info("Found {} commit logs to download", parsedCommitlogList.size());
    if (parsedCommitlogList.size() == 0) {
        return;
    }
    Session<DownloadUnit> downloadSession = null;
    try {
        downloadSession = downloadTracker.submit(restorer, this, parsedCommitlogList, null, this.request.concurrentConnections);
        downloadSession.waitUntilConsideredFinished();
        downloadTracker.cancelIfNecessary(downloadSession);
    } finally {
        downloadTracker.removeSession(downloadSession);
    }
}
Also used : Pattern(java.util.regex.Pattern) AtomicLong(java.util.concurrent.atomic.AtomicLong) RemoteObjectReference(com.instaclustr.esop.impl.RemoteObjectReference) ManifestEntry(com.instaclustr.esop.impl.ManifestEntry) Matcher(java.util.regex.Matcher) AtomicReference(java.util.concurrent.atomic.AtomicReference) DownloadUnit(com.instaclustr.esop.impl.restore.DownloadTracker.DownloadUnit) HashSet(java.util.HashSet)

Example 4 with RemoteObjectReference

use of com.instaclustr.esop.impl.RemoteObjectReference in project esop by instaclustr.

the class GCPRestorer method delete.

@Override
public void delete(Path objectKey, boolean nodeAware) throws Exception {
    RemoteObjectReference remoteObjectReference;
    if (nodeAware) {
        remoteObjectReference = objectKeyToNodeAwareRemoteReference(objectKey);
    } else {
        remoteObjectReference = objectKeyToRemoteReference(objectKey);
    }
    logger.info("Non dry: " + Paths.get(request.storageLocation.bucket, remoteObjectReference.canonicalPath));
    storage.delete(((GCPRemoteObjectReference) remoteObjectReference).blobId);
}
Also used : RemoteObjectReference(com.instaclustr.esop.impl.RemoteObjectReference)

Example 5 with RemoteObjectReference

use of com.instaclustr.esop.impl.RemoteObjectReference in project esop by instaclustr.

the class BaseS3Restorer method consumeFiles.

@Override
public void consumeFiles(final RemoteObjectReference prefix, final Consumer<RemoteObjectReference> consumer) {
    final Path bucketPath = Paths.get(request.storageLocation.clusterId).resolve(request.storageLocation.datacenterId).resolve(request.storageLocation.nodeId);
    ObjectListing objectListing = amazonS3.listObjects(request.storageLocation.bucket, prefix.canonicalPath);
    boolean hasMoreContent = true;
    while (hasMoreContent) {
        objectListing.getObjectSummaries().stream().filter(objectSummary -> !objectSummary.getKey().endsWith("/")).forEach(objectSummary -> consumer.accept(objectKeyToNodeAwareRemoteReference(bucketPath.relativize(Paths.get(objectSummary.getKey())))));
        if (objectListing.isTruncated()) {
            objectListing = amazonS3.listNextBatchOfObjects(objectListing);
        } else {
            hasMoreContent = false;
        }
    }
}
Also used : Path(java.nio.file.Path) TransferManager(com.amazonaws.services.s3.transfer.TransferManager) ListOperationRequest(com.instaclustr.esop.impl.list.ListOperationRequest) LoggerFactory(org.slf4j.LoggerFactory) ListOperationRequest.getForLocalListing(com.instaclustr.esop.impl.list.ListOperationRequest.getForLocalListing) GetObjectRequest(com.amazonaws.services.s3.model.GetObjectRequest) ObjectListing(com.amazonaws.services.s3.model.ObjectListing) ProgressEvent(com.amazonaws.event.ProgressEvent) DeleteObjectRequest(com.amazonaws.services.s3.model.DeleteObjectRequest) ArrayList(java.util.ArrayList) Collectors.toCollection(java.util.stream.Collectors.toCollection) RemoveBackupRequest(com.instaclustr.esop.impl.remove.RemoveBackupRequest) S3ProgressListener(com.amazonaws.services.s3.transfer.internal.S3ProgressListener) LocalFileRestorer(com.instaclustr.esop.local.LocalFileRestorer) S3Object(com.amazonaws.services.s3.model.S3Object) CharStreams(com.google.common.io.CharStreams) DeleteObjectsRequest(com.amazonaws.services.s3.model.DeleteObjectsRequest) RemoteObjectReference(com.instaclustr.esop.impl.RemoteObjectReference) AmazonS3(com.amazonaws.services.s3.AmazonS3) ProgressEventType(com.amazonaws.event.ProgressEventType) S3ObjectSummary(com.amazonaws.services.s3.model.S3ObjectSummary) Path(java.nio.file.Path) FileUtils(com.instaclustr.io.FileUtils) RestoreCommitLogsOperationRequest(com.instaclustr.esop.impl.restore.RestoreCommitLogsOperationRequest) Logger(org.slf4j.Logger) AmazonServiceException(com.amazonaws.AmazonServiceException) PersistableTransfer(com.amazonaws.services.s3.transfer.PersistableTransfer) StorageLocation(com.instaclustr.esop.impl.StorageLocation) Restorer(com.instaclustr.esop.impl.restore.Restorer) Files(java.nio.file.Files) Predicate(java.util.function.Predicate) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) RetriableException(com.instaclustr.esop.impl.retry.Retrier.RetriableException) IOException(java.io.IOException) Manifest(com.instaclustr.esop.impl.Manifest) InputStreamReader(java.io.InputStreamReader) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) RetrierFactory(com.instaclustr.esop.impl.retry.RetrierFactory) Consumer(java.util.function.Consumer) List(java.util.List) Paths(java.nio.file.Paths) RestoreOperationRequest(com.instaclustr.esop.impl.restore.RestoreOperationRequest) AmazonClientException(com.amazonaws.AmazonClientException) InputStream(java.io.InputStream) ObjectListing(com.amazonaws.services.s3.model.ObjectListing)

Aggregations

RemoteObjectReference (com.instaclustr.esop.impl.RemoteObjectReference)6 Path (java.nio.file.Path)3 DeleteObjectRequest (com.amazonaws.services.s3.model.DeleteObjectRequest)2 AmazonClientException (com.amazonaws.AmazonClientException)1 AmazonServiceException (com.amazonaws.AmazonServiceException)1 ProgressEvent (com.amazonaws.event.ProgressEvent)1 ProgressEventType (com.amazonaws.event.ProgressEventType)1 AmazonS3 (com.amazonaws.services.s3.AmazonS3)1 DeleteObjectsRequest (com.amazonaws.services.s3.model.DeleteObjectsRequest)1 GetObjectRequest (com.amazonaws.services.s3.model.GetObjectRequest)1 ObjectListing (com.amazonaws.services.s3.model.ObjectListing)1 S3Object (com.amazonaws.services.s3.model.S3Object)1 S3ObjectSummary (com.amazonaws.services.s3.model.S3ObjectSummary)1 PersistableTransfer (com.amazonaws.services.s3.transfer.PersistableTransfer)1 TransferManager (com.amazonaws.services.s3.transfer.TransferManager)1 S3ProgressListener (com.amazonaws.services.s3.transfer.internal.S3ProgressListener)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 CharStreams (com.google.common.io.CharStreams)1 Manifest (com.instaclustr.esop.impl.Manifest)1 ManifestEntry (com.instaclustr.esop.impl.ManifestEntry)1