org.sonatype.nexus.blobstore.api.BlobStoreUsageChecker Java Examples

The following examples show how to use org.sonatype.nexus.blobstore.api.BlobStoreUsageChecker. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GoogleCloudBlobStore.java    From nexus-blobstore-google-cloud with Eclipse Public License 1.0 6 votes vote down vote up
@Override
@Guarded(by = STARTED)
public void doCompact(@Nullable final BlobStoreUsageChecker blobStoreUsageChecker) {
  log.info("Begin deleted blobs processing");
  ProgressLogIntervalHelper progressLogger = new ProgressLogIntervalHelper(log, 60);
  final AtomicInteger counter = new AtomicInteger(0);
  deletedBlobIndex.getContents().forEach(blobId -> {
    CancelableHelper.checkCancellation();

    deleteHard(blobId);
    counter.incrementAndGet();

    progressLogger.info("Elapsed time: {}, processed: {}", progressLogger.getElapsed(),
        counter.get());
  });
  progressLogger.flush();
}
 
Example #2
Source File: RestoreMetadataTask.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Inject
public RestoreMetadataTask(final BlobStoreManager blobStoreManager,
                           final RepositoryManager repositoryManager,
                           final Map<String, RestoreBlobStrategy> restoreBlobStrategies,
                           final BlobStoreUsageChecker blobStoreUsageChecker,
                           final DryRunPrefix dryRunPrefix,
                           final Map<String, IntegrityCheckStrategy> integrityCheckStrategies,
                           final BucketStore bucketStore,
                           final MaintenanceService maintenanceService)
{
  this.blobStoreManager = checkNotNull(blobStoreManager);
  this.repositoryManager = checkNotNull(repositoryManager);
  this.restoreBlobStrategies = checkNotNull(restoreBlobStrategies);
  this.blobStoreUsageChecker = checkNotNull(blobStoreUsageChecker);
  this.dryRunPrefix = checkNotNull(dryRunPrefix);
  this.defaultIntegrityCheckStrategy = checkNotNull(integrityCheckStrategies.get(DEFAULT_NAME));
  this.integrityCheckStrategies = checkNotNull(integrityCheckStrategies);
  this.bucketStore = checkNotNull(bucketStore);
  this.maintenanceService = checkNotNull(maintenanceService);
}
 
Example #3
Source File: FileBlobStore.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
void doCompactWithDeletedBlobIndex(@Nullable final BlobStoreUsageChecker inUseChecker) throws IOException {
  log.info("Begin deleted blobs processing");
  // only process each blob once (in-use blobs may be re-added to the index)
  ProgressLogIntervalHelper progressLogger = new ProgressLogIntervalHelper(log, 60);
  for (int counter = 0, numBlobs = deletedBlobIndex.size(); counter < numBlobs; counter++) {
    checkCancellation();
    byte[] bytes = deletedBlobIndex.peek();
    if (bytes == null) {
      return;
    }
    BlobId blobId = new BlobId(new String(bytes, UTF_8));
    FileBlob blob = liveBlobs.getIfPresent(blobId);
    if (blob == null || blob.isStale()) {
      maybeCompactBlob(inUseChecker, blobId);
      deletedBlobIndex.remove();
    }
    else {
      // still in use, so move it to end of the queue
      deletedBlobIndex.remove();
      deletedBlobIndex.add(bytes);
    }
    progressLogger.info("Elapsed time: {}, processed: {}/{}", progressLogger.getElapsed(),
        counter + 1, numBlobs);
  }
  progressLogger.flush();
}
 
Example #4
Source File: FileBlobStore.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
private void compactByAttributes(
    final FileBlobAttributes attributes,
    final BlobStoreUsageChecker inUseChecker,
    final AtomicInteger count,
    final ProgressLogIntervalHelper progressLogger)
{
  String blobId = getBlobIdFromAttributeFilePath(new FileAttributesLocation(attributes.getPath()));
  FileBlob blob = liveBlobs.getIfPresent(blobId);
  try {
    if (blob == null || blob.isStale()) {
      if (!maybeCompactBlob(inUseChecker, new BlobId(blobId))) {
        deletedBlobIndex.add(blobId.getBytes(UTF_8));
      }
      else {
        progressLogger.info("Elapsed time: {}, processed: {}", progressLogger.getElapsed(),
            count.incrementAndGet());
      }
    }
    else {
      deletedBlobIndex.add(blobId.getBytes(UTF_8));
    }
  }
  catch (IOException e) {
    log.warn("Failed to add blobId to index from attribute file {}", blobId, e);
  }
}
 
Example #5
Source File: CompactBlobStoreTask.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Inject
public CompactBlobStoreTask(final BlobStoreManager blobStoreManager,
                            final BlobStoreUsageChecker blobStoreUsageChecker)
{
  this.blobStoreManager = checkNotNull(blobStoreManager);
  this.blobStoreUsageChecker = checkNotNull(blobStoreUsageChecker);
}
 
Example #6
Source File: FileBlobStore.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
private boolean maybeCompactBlob(@Nullable final BlobStoreUsageChecker inUseChecker, final BlobId blobId)
{
  Optional<FileBlobAttributes> attributesOption = ofNullable((FileBlobAttributes) getBlobAttributes(blobId));
  if (!attributesOption.isPresent() || !undelete(inUseChecker, blobId, attributesOption.get(), false)) {
    // attributes file is missing or blob id not in use, so it's safe to delete the file
    log.debug("Hard deleting blob id: {}, in blob store: {}", blobId, blobStoreConfiguration.getName());
    return deleteHard(blobId);
  }
  return false;
}
 
Example #7
Source File: BlobStoreSupport.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Override
@Guarded(by = STARTED)
public boolean undelete(@Nullable final BlobStoreUsageChecker inUseChecker, final BlobId blobId,
                        final BlobAttributes attributes,
                        final boolean isDryRun)
{
  checkNotNull(attributes);
  String logPrefix = isDryRun ? dryRunPrefix.get() : "";
  Optional<String> blobName = Optional.of(attributes)
      .map(BlobAttributes::getProperties)
      .map(p -> p.getProperty(HEADER_PREFIX + BLOB_NAME_HEADER));
  if (!blobName.isPresent()) {
    log.error("Property not present: {}, for blob id: {}, at path: {}", HEADER_PREFIX + BLOB_NAME_HEADER,
        blobId, attributePathString(blobId)); // NOSONAR
    return false;
  }
  if (attributes.isDeleted() && inUseChecker != null && inUseChecker.test(this, blobId, blobName.get())) {
    String deletedReason = attributes.getDeletedReason();
    if (!isDryRun) {
      attributes.setDeleted(false);
      attributes.setDeletedReason(null);
      try {
        doUndelete(blobId, attributes);
        attributes.store();
      }
      catch (IOException e) {
        log.error("Error while un-deleting blob id: {}, deleted reason: {}, blob store: {}, blob name: {}",
            blobId, deletedReason, blobStoreConfiguration.getName(), blobName.get(), e);
      }
    }
    log.warn(
        "{}Soft-deleted blob still in use, un-deleting blob id: {}, deleted reason: {}, blob store: {}, blob name: {}",
        logPrefix, blobId, deletedReason, blobStoreConfiguration.getName(), blobName.get());
    return true;
  }
  return false;
}
 
Example #8
Source File: BlobStoreSupport.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Override
@Guarded(by = STARTED)
public synchronized void compact(@Nullable final BlobStoreUsageChecker inUseChecker) {
  long start = System.nanoTime();
  try {
    doCompact(inUseChecker);
  }
  finally {
    updateTimer("compact", System.nanoTime() - start);
  }
}
 
Example #9
Source File: BlobStoreGroup.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean undelete(@Nullable final BlobStoreUsageChecker inUseChecker,
                        final BlobId blobId,
                        final BlobAttributes attributes,
                        final boolean isDryRun)
{
  return members.get().stream()
      .map((BlobStore member) -> member.undelete(inUseChecker, blobId, attributes, isDryRun))
      .anyMatch((Boolean deleted) -> deleted);
}
 
Example #10
Source File: S3BlobStore.java    From nexus-blobstore-s3 with Eclipse Public License 1.0 4 votes vote down vote up
@Override
@Guarded(by = STARTED)
public synchronized void compact(@Nullable final BlobStoreUsageChecker inUseChecker) {
    // no-op
}
 
Example #11
Source File: BlobStoreSupport.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
protected void doCompact(@Nullable final BlobStoreUsageChecker inUseChecker) {
  // no-op
}
 
Example #12
Source File: BlobStoreGroup.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
@Override
@Guarded(by = STARTED)
public synchronized void compact(@Nullable final BlobStoreUsageChecker inUseChecker) {
  members.get().stream().forEach((BlobStore member) -> member.compact(inUseChecker));
}