Java源码示例:org.sonatype.nexus.blobstore.api.BlobStoreUsageChecker

示例1
@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();
}
 
示例2
@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);
}
 
示例3
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();
}
 
示例4
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);
  }
}
 
示例5
@Inject
public CompactBlobStoreTask(final BlobStoreManager blobStoreManager,
                            final BlobStoreUsageChecker blobStoreUsageChecker)
{
  this.blobStoreManager = checkNotNull(blobStoreManager);
  this.blobStoreUsageChecker = checkNotNull(blobStoreUsageChecker);
}
 
示例6
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;
}
 
示例7
@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;
}
 
示例8
@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);
  }
}
 
示例9
@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);
}
 
示例10
@Override
@Guarded(by = STARTED)
public synchronized void compact(@Nullable final BlobStoreUsageChecker inUseChecker) {
    // no-op
}
 
示例11
protected void doCompact(@Nullable final BlobStoreUsageChecker inUseChecker) {
  // no-op
}
 
示例12
@Override
@Guarded(by = STARTED)
public synchronized void compact(@Nullable final BlobStoreUsageChecker inUseChecker) {
  members.get().stream().forEach((BlobStore member) -> member.compact(inUseChecker));
}