com.orientechnologies.common.concur.ONeedRetryException Java Examples

The following examples show how to use com.orientechnologies.common.concur.ONeedRetryException. 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: JobStoreImpl.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public List<OperableTrigger> acquireNextTriggers(final long noLaterThan,
                                                 final int maxCount,
                                                 final long timeWindow)
    throws JobPersistenceException
{
  storeLock.writeLock().lock();
  try {
    return inTx(databaseInstance)
        .retryOn(ONeedRetryException.class, ORecordNotFoundException.class)
        .call(db -> doAcquireNextTriggers(db, noLaterThan, maxCount, timeWindow));
  }
  catch (RuntimeException e) {
    acquireNextTriggersSummarizer.log("Problem acquiring next triggers", e);
    try {
      Thread.sleep(10); // introduce small delay, otherwise quartz will immediately try again
    }
    catch (InterruptedException ignore) { // NOSONAR
      // ignored
    }
    throw new JobPersistenceException(e.toString(), e);
  }
  finally {
    storeLock.writeLock().unlock();
  }
}
 
Example #2
Source File: AptSnapshotFacetSupport.java    From nexus-repository-apt with Eclipse Public License 1.0 6 votes vote down vote up
@Transactional(retryOn = { ONeedRetryException.class })
@Override
public void createSnapshot(String id, SnapshotComponentSelector selector) throws IOException {
  StorageTx tx = UnitOfWork.currentTx();
  StorageFacet storageFacet = facet(StorageFacet.class);
  Bucket bucket = tx.findBucket(getRepository());
  Component component = tx.createComponent(bucket, getRepository().getFormat()).name(id);
  tx.saveComponent(component);
  for (SnapshotItem item : collectSnapshotItems(selector)) {
    String assetName = createAssetPath(id, item.specifier.path);
    Asset asset = tx.createAsset(bucket, component).name(assetName);
    try (final TempBlob streamSupplier = storageFacet.createTempBlob(item.content.openInputStream(), FacetHelper.hashAlgorithms)) {
      AssetBlob blob = tx.createBlob(item.specifier.path, streamSupplier, FacetHelper.hashAlgorithms, null,
          FacetHelper.determineContentType(item), true);
      tx.attachBlob(asset, blob);
    }
    finally {
      item.content.close();
    }
    tx.saveAsset(asset);
  }
}
 
Example #3
Source File: AptSnapshotFacetSupport.java    From nexus-repository-apt with Eclipse Public License 1.0 6 votes vote down vote up
@Transactional(retryOn = { ONeedRetryException.class })
@Override
public Content getSnapshotFile(String id, String path) throws IOException {
  StorageTx tx = UnitOfWork.currentTx();
  Bucket bucket = tx.findBucket(getRepository());
  Component component = tx.findComponentWithProperty(P_NAME, id, bucket);
  if (component == null) {
    return null;
  }

  final Asset asset = tx.findAssetWithProperty(P_NAME, createAssetPath(id, path), component);
  if (asset == null) {
    return null;
  }

  final Blob blob = tx.requireBlob(asset.requireBlobRef());
  return FacetHelper.toContent(asset, blob);
}
 
Example #4
Source File: JobStoreImpl.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Execute write operation within transaction and propagate/translate exceptions.
 */
private <T> T executeWrite(final Operation<T> operation) throws JobPersistenceException {
  storeLock.writeLock().lock();
  try {
    return inTx(databaseInstance)
        .retryOn(ONeedRetryException.class, ORecordNotFoundException.class)
        .throwing(JobPersistenceException.class)
        .call(operation::execute);
  }
  catch (Exception e) {
    log.warn("Execution failed", e);
    Throwables.propagateIfPossible(e, JobPersistenceException.class);
    throw new JobPersistenceException(e.toString(), e);
  }
  finally {
    storeLock.writeLock().unlock();
  }
}
 
Example #5
Source File: CondaComponentMaintenanceFacet.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Transactional(retryOn = ONeedRetryException.class)
@Override
protected Set<String> deleteAssetTx(final EntityId assetId, final boolean deleteBlobs) {
  StorageTx tx = UnitOfWork.currentTx();
  Bucket bucket = tx.findBucket(getRepository());
  Asset asset = tx.findAsset(assetId, bucket);

  if (asset == null) {
    return emptySet();
  }

  tx.deleteAsset(asset, deleteBlobs);

  if (asset.componentId() != null) {
    Component component = tx.findComponentInBucket(asset.componentId(), bucket);

    if (!tx.browseAssets(component).iterator().hasNext()) {
      log.debug("Deleting component: {}", component);
      tx.deleteComponent(component, deleteBlobs);
    }
  }
  return Collections.singleton(asset.name());
}
 
Example #6
Source File: JobStoreImpl.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Execute read operation within transaction and propagate/translate exceptions.
 */
private <T> T executeRead(final Operation<T> operation) throws JobPersistenceException {
  storeLock.readLock().lock();
  try {
    return inTx(databaseInstance)
        .retryOn(ONeedRetryException.class, ORecordNotFoundException.class)
        .throwing(JobPersistenceException.class)
        .call(operation::execute);
  }
  catch (Exception e) {
    log.warn("Execution failed", e);
    Throwables.propagateIfPossible(e, JobPersistenceException.class);
    throw new JobPersistenceException(e.toString(), e);
  }
  finally {
    storeLock.readLock().unlock();
  }
}
 
Example #7
Source File: HelmComponentMaintenanceFacet.java    From nexus-repository-helm with Eclipse Public License 1.0 6 votes vote down vote up
@Transactional(retryOn = ONeedRetryException.class)
@Override
protected Set<String> deleteAssetTx(final EntityId assetId, final boolean deleteBlobs) {
  StorageTx tx = UnitOfWork.currentTx();
  Bucket bucket = tx.findBucket(getRepository());
  Asset asset = tx.findAsset(assetId, bucket);

  if (asset == null) {
    return Collections.emptySet();
  }

  tx.deleteAsset(asset, deleteBlobs);

  if (asset.componentId() != null) {
    Component component = tx.findComponentInBucket(asset.componentId(), bucket);

    if (!tx.browseAssets(component).iterator().hasNext()) {
      log.debug("Deleting component: {}", component);
      tx.deleteComponent(component, deleteBlobs);
    }
  }
  return Collections.singleton(asset.name());
}
 
Example #8
Source File: AptSnapshotFacetSupport.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Transactional(retryOn = {ONeedRetryException.class})
protected void createSnapshot(final String id, final Iterable<SnapshotItem> snapshots) throws IOException {
  StorageTx tx = UnitOfWork.currentTx();
  StorageFacet storageFacet = facet(StorageFacet.class);
  Bucket bucket = tx.findBucket(getRepository());
  for (SnapshotItem item : snapshots) {
    String assetName = createAssetPath(id, item.specifier.path);
    Asset asset = tx.createAsset(bucket, getRepository().getFormat()).name(assetName);
    try (final TempBlob streamSupplier = storageFacet
        .createTempBlob(item.content.openInputStream(), FacetHelper.hashAlgorithms)) {
      AssetBlob blob = tx.createBlob(item.specifier.path, streamSupplier, FacetHelper.hashAlgorithms, null,
          item.specifier.role.getMimeType(), true);
      tx.attachBlob(asset, blob);
    }
    finally {
      item.content.close();
    }
    tx.saveAsset(asset);
  }
}
 
Example #9
Source File: AptProxyFacet.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Transactional(retryOn = {ONeedRetryException.class})
protected void doIndicateVerified(final Content content, final CacheInfo cacheInfo, final String assetPath) {
  StorageTx tx = UnitOfWork.currentTx();
  Bucket bucket = tx.findBucket(getRepository());

  Asset asset = Content.findAsset(tx, bucket, content);
  if (asset == null) {
    asset = tx.findAssetWithProperty(P_NAME, assetPath, bucket);
  }
  if (asset == null) {
    return;
  }
  CacheInfo.applyToAsset(asset, cacheInfo);
  tx.saveAsset(asset);
}
 
Example #10
Source File: RetryMethodInterceptor.java    From guice-persist-orient with MIT License 5 votes vote down vote up
/**
 * Searching for {@link com.orientechnologies.common.concur.ONeedRetryException} in exception hierarchy.
 *
 * @param th thrown exception
 * @return true if retry could be performed
 */
private boolean isRetryException(final Throwable th) {
    Throwable current = th;
    boolean res = false;
    while (current != null) {
        if (current instanceof ONeedRetryException) {
            res = true;
            break;
        }
        current = current.getCause();
    }
    return res;
}
 
Example #11
Source File: LastDownloadedHandler.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Transactional(swallow = {
    // silently skip if the record has been deleted, someone else updated it, or the system is in read-only mode
    ORecordNotFoundException.class, ONeedRetryException.class, OModificationOperationProhibitedException.class })
@VisibleForTesting
protected void tryPersistLastDownloadedTime(final Asset asset) {
  StorageTx tx = UnitOfWork.currentTx();
  // reload asset in case it's changed since it was stored in the response
  Asset latestAsset = tx.findAsset(EntityHelper.id(asset));
  if (latestAsset != null && assetManager.maybeUpdateLastDownloaded(latestAsset)) {
    tx.saveAsset(latestAsset);
  }
}
 
Example #12
Source File: OrientBrowseNodeStoreImpl.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Override
@Guarded(by = STARTED)
public void createAssetNode(final String repositoryName,
                            final String format,
                            final List<BrowsePath> paths,
                            final Asset asset)
{
  inTxRetry(databaseInstance)
      // handle case where an asset and its component try to create the exact same path at once
      .retryOn(ONeedRetryException.class, ORecordDuplicatedException.class)
      .run(db -> entityAdapter.createAssetNode(db, repositoryName, format, paths, asset));
}
 
Example #13
Source File: OrientBrowseNodeStoreImpl.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Override
@Guarded(by = STARTED)
public void createComponentNode(final String repositoryName,
                                final String format,
                                final List<BrowsePath> paths,
                                final Component component)
{
  inTxRetry(databaseInstance)
      // handle case where assets try to create the exact same component-level path at once
      .retryOn(ONeedRetryException.class, ORecordDuplicatedException.class)
      .run(db -> entityAdapter.createComponentNode(db, repositoryName, format, paths, component));
}
 
Example #14
Source File: AptSnapshotFacetSupport.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Transactional(retryOn = {ONeedRetryException.class})
@Override
public void deleteSnapshot(final String id) throws IOException {
  String path = createAssetPath(id, "");

  StorageTx tx = UnitOfWork.currentTx();
  Query query = builder()
      .where(P_NAME).like(path + "%")
      .build();

  tx.findAssets(query, singletonList(getRepository()))
      .spliterator()
      .forEachRemaining(tx::deleteAsset);
}
 
Example #15
Source File: AptSnapshotFacetSupport.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Transactional(retryOn = {ONeedRetryException.class})
@Override
@Nullable
public Content getSnapshotFile(final String id, final String path) throws IOException {
  StorageTx tx = UnitOfWork.currentTx();
  Bucket bucket = tx.findBucket(getRepository());
  final Asset asset = tx.findAssetWithProperty(P_NAME, createAssetPath(id, path), bucket);
  if (asset == null) {
    return null;
  }

  final Blob blob = tx.requireBlob(asset.requireBlobRef());
  return FacetHelper.toContent(asset, blob);
}
 
Example #16
Source File: AptHostedComponentMaintenanceFacet.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Transactional(retryOn = ONeedRetryException.class)
@Override
protected Set<String> deleteAssetTx(final EntityId assetId, final boolean deleteBlobs) {
  StorageTx tx = UnitOfWork.currentTx();
  Bucket bucket = tx.findBucket(getRepository());
  Asset asset = tx.findAsset(assetId, bucket);

  if (asset == null) {
    return Collections.emptySet();
  }

  String assetKind = asset.formatAttributes().get(P_ASSET_KIND, String.class);
  Set<String> result = super.deleteAssetTx(assetId, deleteBlobs);
  if ("DEB".equals(assetKind)) {
    try {
      getRepository().facet(AptHostedFacet.class)
          .rebuildIndexes(Collections.singletonList(new AptHostedFacet.AssetChange(AssetAction.REMOVED, asset)));
    }
    catch (IOException e) {
      throw new UncheckedIOException(e);
    }
  }

  if (asset.componentId() != null) {
    Component component = tx.findComponentInBucket(asset.componentId(), bucket);

    if (!tx.browseAssets(component).iterator().hasNext()) {
      log.debug("Deleting component: {}", component);
      tx.deleteComponent(component, deleteBlobs);
    }
  }

  return result;
}
 
Example #17
Source File: OrientMavenGroupFacet.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Tries to invalidate the current main cached asset for the given {@link MavenPath}.
 */
@Transactional(retryOn = ONeedRetryException.class, swallow = ORecordNotFoundException.class)
protected void doInvalidate(final MavenPath mavenPath) {
  StorageTx tx = UnitOfWork.currentTx();
  final Asset asset = findAsset(tx, tx.findBucket(getRepository()), mavenPath.main());
  if (asset != null && CacheInfo.invalidateAsset(asset)) {
    tx.saveAsset(asset);
  }
}
 
Example #18
Source File: OrientPyPiGroupFacet.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Transactional(retryOn = ONeedRetryException.class, swallow = ORecordNotFoundException.class)
protected void doInvalidateCache(final String name) {
  StorageTx tx = UnitOfWork.currentTx();
  Asset asset = tx.findAssetWithProperty(P_NAME, name, tx.findBucket(getRepository()));
  if (asset != null && invalidateAsset(asset)) {
    log.info("Invalidating cached content {} from {}", name, getRepository().getName());
    tx.saveAsset(asset);
  }
}
 
Example #19
Source File: OrientNpmGroupFacet.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Nullable
@Transactional(retryOn = ONeedRetryException.class, swallow = ORecordNotFoundException.class)
protected void doInvalidate(final NpmPackageId packageId) {
  StorageTx tx = UnitOfWork.currentTx();
  Bucket bucket = tx.findBucket(getRepository());

  Asset asset = findPackageRootAsset(tx, bucket, packageId);
  if (nonNull(asset) && invalidateAsset(asset)) {
    tx.saveAsset(asset);
  }
}
 
Example #20
Source File: AptSnapshotFacetSupport.java    From nexus-repository-apt with Eclipse Public License 1.0 5 votes vote down vote up
@Transactional(retryOn = { ONeedRetryException.class })
@Override
public void deleteSnapshot(String id) throws IOException {
  StorageTx tx = UnitOfWork.currentTx();
  Bucket bucket = tx.findBucket(getRepository());
  Component component = tx.findComponentWithProperty(P_NAME, id, bucket);
  if (component == null) {
    return;
  }
  tx.deleteComponent(component);
}
 
Example #21
Source File: AptProxyFacet.java    From nexus-repository-apt with Eclipse Public License 1.0 5 votes vote down vote up
@Transactional(retryOn = { ONeedRetryException.class })
protected void doIndicateVerified(Content content, CacheInfo cacheInfo, String assetPath) {
  StorageTx tx = UnitOfWork.currentTx();
  Bucket bucket = tx.findBucket(getRepository());

  Asset asset = Content.findAsset(tx, bucket, content);
  if (asset == null) {
    asset = tx.findAssetWithProperty(P_NAME, assetPath, bucket);
  }
  if (asset == null) {
    return;
  }
  CacheInfo.applyToAsset(asset, cacheInfo);
  tx.saveAsset(asset);
}
 
Example #22
Source File: AptProxyFacet.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
@Transactional(retryOn = {ONeedRetryException.class})
@Override
protected void indicateVerified(final Context context, final Content content, final CacheInfo cacheInfo) throws IOException {
  doIndicateVerified(content, cacheInfo, assetPath(context));
}
 
Example #23
Source File: AptProxyFacet.java    From nexus-repository-apt with Eclipse Public License 1.0 4 votes vote down vote up
@Transactional(retryOn = { ONeedRetryException.class })
@Override
protected void indicateVerified(Context context, Content content, CacheInfo cacheInfo) throws IOException {
  doIndicateVerified(content, cacheInfo, assetPath(context));
}