Skip to content

Commit

Permalink
Retry if fail with ARTIFACT_EXISTS error code
Browse files Browse the repository at this point in the history
With the new parallel product assembly it seem to happen that a download
is performed when another thread has already added it.

In such case, instead of fail the makeLocallyAvailable method with an
error that the artifact is already there just sleep a little bit and
then retry the attempt.
  • Loading branch information
laeubi committed Jan 28, 2024
1 parent 502a622 commit dc94fbf
Showing 1 changed file with 21 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.Map;
import java.util.Objects;
import java.util.TreeSet;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;

import org.apache.commons.codec.digest.DigestUtils;
Expand Down Expand Up @@ -88,14 +89,13 @@ public class MirroringArtifactProvider implements IRawArtifactFileProvider {
* Creates a new {@link MirroringArtifactProvider} instance.
*
* @param localArtifactRepository
* The local Maven repository
* The local Maven repository
* @param remoteProviders
* The provider that will be queried by this instance when it is
* asked for an artifact which is not (yet) available in the
* local Maven repository. Typically this provider is backed by
* remote p2 repositories.
* The provider that will be queried by this instance when it is asked for an
* artifact which is not (yet) available in the local Maven repository. Typically
* this provider is backed by remote p2 repositories.
* @param logger
* a logger for progress output
* a logger for progress output
*/
public static MirroringArtifactProvider createInstance(LocalArtifactRepository localArtifactRepository,
IRawArtifactProvider remoteProviders, MavenContext context) {
Expand Down Expand Up @@ -199,24 +199,32 @@ public final boolean contains(IArtifactDescriptor descriptor) throws MirroringFa
* @return <code>false</code> if the artifact is neither already cached locally nor available
* remotely.
* @throws MirroringFailedException
* if a fatal error occurred while downloading the artifact.
* if a fatal error occurred while downloading the artifact.
*/
private boolean makeLocallyAvailable(IArtifactKey key) throws MirroringFailedException {
// TODO 397355 cache artifactDescriptors for the key so that only one synchronization is necessary to figure out if a download is needed
try {
boolean isAvailable = makeOneFormatLocallyAvailable(key);

if (isAvailable) {
/*
* Always execute this step so that a local repository that only contains the packed format of an
* artifact is automatically corrected. We need the canonical format in the local repository so that
* {@link IArtifactFileProvider#getArtifactFile(IArtifactKey)} does not return null.
* Always execute this step so that a local repository that only contains the packed
* format of an artifact is automatically corrected. We need the canonical format in
* the local repository so that {@link
* IArtifactFileProvider#getArtifactFile(IArtifactKey)} does not return null.
*/
ensureArtifactIsPresentInCanonicalFormat(key);
}
return isAvailable;

} catch (ProvisionException e) {
if (ProvisionException.ARTIFACT_EXISTS == e.getStatus().getCode()) {
//there is some race condition here so we need to start over again
try {
TimeUnit.MILLISECONDS.sleep(100);
} catch (InterruptedException e1) {
}
return makeLocallyAvailable(key);
}
throw new MirroringFailedException(
"Error while mirroring artifact " + key + " to the local Maven repository" + e.getMessage(), e);
} catch (ArtifactSinkException e) {
Expand Down Expand Up @@ -370,8 +378,8 @@ private static IStatus artifactNotFoundStatus(IArtifactKey key) {
}

/**
* Returns an {@link IProgressMonitor} which translates p2's status updates into a reasonable log
* output.
* Returns an {@link IProgressMonitor} which translates p2's status updates into a reasonable
* log output.
*/
final IProgressMonitor monitorForDownload() {
// create a new instance for each call - DuplicateFilteringLoggingProgressMonitor is not thread-safe
Expand Down

0 comments on commit dc94fbf

Please sign in to comment.