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

Commit

Permalink
Get index update working with new update interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
scarlucci committed Apr 11, 2013
1 parent 398ebcd commit 73e71f5
Showing 1 changed file with 62 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1050,62 +1050,32 @@ private void reindexRepository( final Repository repository, final String fromPa
{
logger.debug( "Reindexing repository {} fromPath={} fullReindex={}", repository.getId(), fromPath,
fullReindex );

Runnable runnable = new Runnable()
{
@Override
public void run( final IndexingContext context )
throws IOException
{
if ( ISPROXY( repository ) )
{
updateRemoteIndex( repository.adaptToFacet( ProxyRepository.class ), context, fullReindex );
}

TaskUtil.checkInterruption();

// igorf, this needs be merged back to maven indexer, see MINDEXER-65
final IndexSearcher contextIndexSearcher = context.acquireIndexSearcher();
try
{
final NexusScanningListener scanListener =
new NexusScanningListener( context, contextIndexSearcher, fullReindex,
ISPROXY( repository ) );
scanner.scan( new ScanningRequest( context, scanListener, fromPath ) );
}
finally
{
context.releaseIndexSearcher( contextIndexSearcher );
}
}
};

if ( !fullReindex )
{
//Try incremental update first
try
{
Runnable runnable = new IndexUpdateRunnable(repository, fromPath, false);
sharedSingle( repository, runnable );
logger.debug( "Reindexed repository {}", repository.getId() );
return;
}
catch(IOException e)
catch(IncrementalIndexUpdateException e)
{
if(e instanceof IncrementalIndexUpdateException)
{
//This exception is an indication that an incremental
//update is not possible, and a full update is necessary
//Just log it and try full update
logger.info( "Unable to incrementally update index for repository {}", repository.getId() );
}
else
{
throw e;
}
//This exception is an indication that an incremental
//update is not possible, and a full update is necessary
//This exception has already been logged. Nothing to do here
//except let execution continue on below to perform a full update
}
}

//Perform full index update
Runnable runnable = new IndexUpdateRunnable(repository, fromPath, true);

// delete published stuff too, as we are breaking incremental downstream chain
deleteIndexItems( repository );

// creates a temp ctx and finally replaces the "real" with temp
temporary( repository, runnable );

Expand All @@ -1123,6 +1093,49 @@ public void run( final IndexingContext context )
repository.getId() );
}
}

/**
* Runnable implementation for updating an index
*/
private class IndexUpdateRunnable implements Runnable
{
Repository repository;
String fromPath;
boolean fullReindex;

IndexUpdateRunnable(Repository repository, String fromPath, boolean fullReindex)
{
this.repository = repository;
this.fromPath = fromPath;
this.fullReindex = fullReindex;
}

@Override
public void run( final IndexingContext context )
throws IOException
{
if ( ISPROXY( this.repository ) )
{
updateRemoteIndex( this.repository.adaptToFacet( ProxyRepository.class ), context, this.fullReindex );
}

TaskUtil.checkInterruption();

// igorf, this needs be merged back to maven indexer, see MINDEXER-65
final IndexSearcher contextIndexSearcher = context.acquireIndexSearcher();
try
{
final NexusScanningListener scanListener =
new NexusScanningListener( context, contextIndexSearcher, this.fullReindex,
ISPROXY( this.repository ) );
scanner.scan( new ScanningRequest( context, scanListener, this.fromPath ) );
}
finally
{
context.releaseIndexSearcher( contextIndexSearcher );
}
}
}

// ----------------------------------------------------------------------------
// Downloading remote indexes (will do remote-download, merge only)
Expand Down Expand Up @@ -1369,6 +1382,14 @@ public InputStream retrieve( String name )
logger.warn( RepositoryStringUtils.getFormattedMessage(
"Cannot fetch remote index for repository %s, task cancelled.", repository ) );
}
catch ( IncrementalIndexUpdateException e )
{
//This is an indication that an incremental index update is not possible, and a full index
//update must be performed.
//Just log this, and pass this exception upstream so that it can be handled appropriately
logger.info( "Cannot incrementally update index for repository {}", repository.getId() );
throw e;
}
catch ( IOException e )
{
logger.warn( RepositoryStringUtils.getFormattedMessage(
Expand Down

0 comments on commit 73e71f5

Please sign in to comment.