Skip to content
This repository has been archived by the owner on Aug 11, 2020. It is now read-only.

Commit

Permalink
using new restlet local release (logging fix), and merged in a couple…
Browse files Browse the repository at this point in the history
… fixes from trunk

git-svn-id: file:///opt/svn/repositories/sonatype.org/nexus/branches/nexus-1.6.0@6294 2aa8b3fc-8ebb-4439-a84f-95066eaea8ab
  • Loading branch information
dbradicich committed Apr 8, 2010
1 parent eae5495 commit c6497fa
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 32 deletions.
Expand Up @@ -25,6 +25,7 @@
import java.util.concurrent.Executors;

import org.apache.commons.lang.time.DurationFormatUtils;
import org.codehaus.plexus.util.ExceptionUtils;
import org.codehaus.plexus.util.StringUtils;
import org.sonatype.configuration.ConfigurationException;
import org.sonatype.nexus.configuration.model.CRemoteStorage;
Expand Down Expand Up @@ -713,13 +714,6 @@ public AbstractStorageItem doCacheItem( AbstractStorageItem item )
return result;
}

protected RepositoryItemUid getDownloadItemUid( ResourceStoreRequest request )
{
RepositoryItemUid uid = createUid( request.getRequestPath() + "?download=true" );

return uid;
}

@Override
protected StorageItem doRetrieveItem( ResourceStoreRequest request )
throws IllegalOperationException, ItemNotFoundException, StorageException
Expand All @@ -739,6 +733,19 @@ protected StorageItem doRetrieveItem( ResourceStoreRequest request )
getLogger().debug( db.toString() );
}

// we have to re-set locking here explicitly, since we are going to
// make a "salto-mortale" here, see below
// we start with "usual" read lock, we still don't know is this hosted or proxy repo
// if proxy, we still don't know do we have to go remote (local copy is old) or not
// if proxy and need to go remote, we want to _protect_ ourselves from
// serving up partial downloads...

RepositoryItemUid itemUid = createUid( request.getRequestPath() );

itemUid.lock( Action.read );

try
{
if ( !getRepositoryKind().isFacetAvailable( ProxyRepository.class ) )
{
// we have no proxy facet, just get 'em!
Expand All @@ -750,19 +757,37 @@ protected StorageItem doRetrieveItem( ResourceStoreRequest request )
// Reason: a previous thread may still _downloading_ the stuff we want to
// serve to another client, so we have to _wait_ for download, but for download
// only.
// From now on, the retrieve operation becomes WRITE operation,
// since this is proxy repository, and it _might_ have "fetch" as side-effect, or should wait for another
// thread
// to finish the fetch side effect.
// So, for _download_ UIDs we start serialize the request processing.
RepositoryItemUid downloadUid = getDownloadItemUid( request );
AbstractStorageItem localItem = null;

downloadUid.lock( Action.create );
if ( !request.isRequestRemoteOnly() )
{
try
{
localItem = (AbstractStorageItem) super.doRetrieveItem( request );

if ( localItem != null && !isOld( localItem ) )
{
// local copy is just fine, so, we are proxy but we have valid local copy in cache
return localItem;
}
}
catch ( ItemNotFoundException e )
{
localItem = null;
}
}

// we are a proxy, and we either don't have local copy or is stale, we need to
// go remote and potentially check for new version of file, but we still don't know
// will we actually fetch it (since aging != remote file changed!)
// BUT, from this point on, we want to _serialize_ access, so upgrade to CREATE lock

itemUid.lock( Action.create );

try
{
AbstractStorageItem localItem = null;

// check local copy again, we were maybe blocked for a download, and we need to
// recheck local copy after we acquired exclusive lock
if ( !request.isRequestRemoteOnly() )
{
try
Expand All @@ -771,6 +796,8 @@ protected StorageItem doRetrieveItem( ResourceStoreRequest request )

if ( localItem != null && !isOld( localItem ) )
{
// local copy is just fine (downloaded by a thread holding us blocked on acquiring
// exclusive lock)
return localItem;
}
}
Expand All @@ -780,13 +807,20 @@ protected StorageItem doRetrieveItem( ResourceStoreRequest request )
}
}

// this whole method happens with exclusive lock on UID
return doRetrieveItem0( request, localItem );
}
finally
{
downloadUid.unlock();
itemUid.unlock();
}
}
}
finally
{
itemUid.unlock();
}

}

protected StorageItem doRetrieveItem0( ResourceStoreRequest request, AbstractStorageItem localItem )
Expand Down Expand Up @@ -1093,11 +1127,10 @@ protected boolean doCheckRemoteItemExistence( StorageItem localItem, ResourceSto
protected AbstractStorageItem doRetrieveRemoteItem( ResourceStoreRequest request )
throws ItemNotFoundException, RemoteAccessException, StorageException
{
// this whole method _locks_ the downloadUid.
// See doRetrieveItem() method above
RepositoryItemUid downloadUid = getDownloadItemUid( request );
RepositoryItemUid itemUid = createUid( request.getRequestPath() );

downloadUid.lock( Action.create );
// all this remote download happens in exclusive lock
itemUid.lock( Action.create );

try
{
Expand Down Expand Up @@ -1191,12 +1224,28 @@ protected AbstractStorageItem doRetrieveRemoteItem( ResourceStoreRequest request
}
catch ( StorageException e )
{
getLogger().error(
"Got Storage Exception while storing remote artifact, will attempt next mirror", e );
lastException = e;

selector.feedbackFailure( mirror );
// debug, print all
if ( getLogger().isDebugEnabled() )
{
logFailedMirror( mirror, e );
}
// not debug, only print the message
else
{
Throwable t = ExceptionUtils.getRootCause( e );

if ( t == null )
{
t = e;
}

getLogger().error(
"Got Storage Exception while storing remote artifact, will attempt next mirror, cause: "
+ t.getClass().getName() + ": " + t.getMessage() );
}
}
catch ( RuntimeException e )
{
Expand Down Expand Up @@ -1248,7 +1297,7 @@ else if ( lastException instanceof ItemNotFoundException )
}
finally
{
downloadUid.unlock();
itemUid.unlock();
}
}

Expand Down
Expand Up @@ -692,7 +692,7 @@ public StorageItem retrieveItem( boolean fromTask, ResourceStoreRequest request
{
if ( getLogger().isDebugEnabled() )
{
getLogger().debug( "retrieveItem() :: " + request.toString() );
getLogger().debug( getId() + ".retrieveItem() :: " + request.toString() );
}

if ( !getLocalStatus().shouldServiceRequest() )
Expand Down Expand Up @@ -789,7 +789,7 @@ public void copyItem( boolean fromTask, ResourceStoreRequest from, ResourceStore
{
if ( getLogger().isDebugEnabled() )
{
getLogger().debug( "copyItem() :: " + from.toString() + " --> " + to.toString() );
getLogger().debug( getId() + ".copyItem() :: " + from.toString() + " --> " + to.toString() );
}

if ( !getLocalStatus().shouldServiceRequest() )
Expand Down Expand Up @@ -845,7 +845,7 @@ public void moveItem( boolean fromTask, ResourceStoreRequest from, ResourceStore
{
if ( getLogger().isDebugEnabled() )
{
getLogger().debug( "moveItem() :: " + from.toString() + " --> " + to.toString() );
getLogger().debug( getId() + ".moveItem() :: " + from.toString() + " --> " + to.toString() );
}

if ( !getLocalStatus().shouldServiceRequest() )
Expand All @@ -863,7 +863,7 @@ public void deleteItem( boolean fromTask, ResourceStoreRequest request )
{
if ( getLogger().isDebugEnabled() )
{
getLogger().debug( "deleteItem() :: " + request.toString() );
getLogger().debug( getId() + ".deleteItem() :: " + request.toString() );
}

if ( !getLocalStatus().shouldServiceRequest() )
Expand Down Expand Up @@ -928,7 +928,7 @@ public void storeItem( boolean fromTask, StorageItem item )
{
if ( getLogger().isDebugEnabled() )
{
getLogger().debug( "storeItem() :: " + item.getRepositoryItemUid().toString() );
getLogger().debug( getId() + ".storeItem() :: " + item.getRepositoryItemUid().toString() );
}

if ( !getLocalStatus().shouldServiceRequest() )
Expand Down Expand Up @@ -964,7 +964,7 @@ public Collection<StorageItem> list( boolean fromTask, ResourceStoreRequest requ
{
if ( getLogger().isDebugEnabled() )
{
getLogger().debug( "list() :: " + request.toString() );
getLogger().debug( getId() + ".list() :: " + request.toString() );
}

if ( !getLocalStatus().shouldServiceRequest() )
Expand All @@ -991,7 +991,7 @@ public Collection<StorageItem> list( boolean fromTask, StorageCollectionItem col
{
if ( getLogger().isDebugEnabled() )
{
getLogger().debug( "list() :: " + coll.getRepositoryItemUid().toString() );
getLogger().debug( getId() + ".list() :: " + coll.getRepositoryItemUid().toString() );
}

if ( !getLocalStatus().shouldServiceRequest() )
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -148,7 +148,7 @@
<plexus.restlet.bridge.version>1.14</plexus.restlet.bridge.version>
<micromailer.version>1.1.0</micromailer.version>
<mercury.version>1.0-alpha-6</mercury.version>
<restlet.version>1.1.6-SONATYPE-5348-V3</restlet.version>
<restlet.version>1.1.6-SONATYPE-5348-V4</restlet.version>
<plexus-jetty6.version>1.7</plexus-jetty6.version>
<plexus-task-scheduler.version>1.3</plexus-task-scheduler.version>
<plexus-digest.version>1.1</plexus-digest.version>
Expand Down

0 comments on commit c6497fa

Please sign in to comment.