Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

SUPPORT-1796 consistent IndexingContext locking order

Signed-off-by: Igor Fedorenko <igor@ifedorenko.com>
  • Loading branch information...
commit 416b80fb613787d96c2876034c61f8563fecd0c7 1 parent 7eb3cbd
@ifedorenko ifedorenko authored
View
38 ...-plugins/nexus-indexer-lucene-plugin/src/main/java/org/sonatype/nexus/index/Contexts.java
@@ -0,0 +1,38 @@
+/**
+ * Sonatype Nexus (TM) Open Source Version
+ * Copyright (c) 2007-2012 Sonatype, Inc.
+ * All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
+ *
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
+ * which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
+ * of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
+ * Eclipse Foundation. All other trademarks are the property of their respective owners.
+ */
+package org.sonatype.nexus.index;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+import org.apache.maven.index.context.IndexingContext;
+
+public class Contexts
+{
+ public static List<IndexingContext> sort( Collection<IndexingContext> contexts )
+ {
+ ArrayList<IndexingContext> result = new ArrayList<IndexingContext>( contexts );
+ Collections.sort( result, new Comparator<IndexingContext>()
+ {
+ @Override
+ public int compare( IndexingContext c1, IndexingContext c2 )
+ {
+ return c1.getId().compareTo( c2.getId() );
+ }
+ } );
+ return Collections.unmodifiableList( result );
+ }
+}
View
138 ...s-indexer-lucene-plugin/src/main/java/org/sonatype/nexus/index/DefaultIndexerManager.java
@@ -55,7 +55,6 @@
import org.apache.maven.index.NexusIndexer;
import org.apache.maven.index.SearchType;
import org.apache.maven.index.artifact.VersionUtils;
-import org.apache.maven.index.context.ContextMemberProvider;
import org.apache.maven.index.context.DefaultIndexingContext;
import org.apache.maven.index.context.DocumentFilter;
import org.apache.maven.index.context.IndexCreator;
@@ -1470,13 +1469,6 @@ public FlatSearchResponse searchArtifactFlat( String term, String repositoryId,
Integer hitLimit )
throws NoSuchRepositoryException
{
- IndexingContext context = null;
-
- if ( repositoryId != null )
- {
- context = getRepositoryIndexContext( repositoryId );
- }
-
Query q1 = nexusIndexer.constructQuery( MAVEN.GROUP_ID, term, SearchType.SCORED );
Query q2 = nexusIndexer.constructQuery( MAVEN.ARTIFACT_ID, term, SearchType.SCORED );
@@ -1487,18 +1479,9 @@ public FlatSearchResponse searchArtifactFlat( String term, String repositoryId,
bq.add( q2, BooleanClause.Occur.SHOULD );
- FlatSearchRequest req = null;
+ FlatSearchRequest req = new FlatSearchRequest( bq, ArtifactInfo.REPOSITORY_VERSION_COMPARATOR );
- if ( repositoryId == null )
- {
- req = new FlatSearchRequest( bq, ArtifactInfo.REPOSITORY_VERSION_COMPARATOR );
- }
- else
- {
- req = new FlatSearchRequest( bq, ArtifactInfo.REPOSITORY_VERSION_COMPARATOR );
-
- req.getContexts().add( context );
- }
+ req.getContexts().addAll( getSearchTargetContexts( repositoryId ) );
// if ( from != null )
// {
@@ -1548,18 +1531,33 @@ public FlatSearchResponse searchArtifactFlat( String term, String repositoryId,
}
}
- @Deprecated
- public FlatSearchResponse searchArtifactClassFlat( String term, String repositoryId, Integer from, Integer count,
- Integer hitLimit )
+ private Collection<IndexingContext> getSearchTargetContexts( String repositoryId )
throws NoSuchRepositoryException
{
- IndexingContext context = null;
-
if ( repositoryId != null )
{
- context = getRepositoryIndexContext( repositoryId );
+ IndexingContext context = getRepositoryIndexContext( repositoryId );
+ if ( context != null )
+ {
+ return Collections.singletonList( context );
+ }
}
+ ArrayList<IndexingContext> result = new ArrayList<IndexingContext>();
+ for ( IndexingContext context : nexusIndexer.getIndexingContexts().values() )
+ {
+ if ( context.isSearchable() )
+ {
+ result.add( context );
+ }
+ }
+ return Contexts.sort( result );
+ }
+ @Deprecated
+ public FlatSearchResponse searchArtifactClassFlat( String term, String repositoryId, Integer from, Integer count,
+ Integer hitLimit )
+ throws NoSuchRepositoryException
+ {
if ( term.endsWith( ".class" ) )
{
term = term.substring( 0, term.length() - 6 );
@@ -1567,18 +1565,9 @@ public FlatSearchResponse searchArtifactClassFlat( String term, String repositor
Query q = nexusIndexer.constructQuery( MAVEN.CLASSNAMES, term, SearchType.SCORED );
- FlatSearchRequest req = null;
+ FlatSearchRequest req = new FlatSearchRequest( q, ArtifactInfo.REPOSITORY_VERSION_COMPARATOR );
- if ( repositoryId == null )
- {
- req = new FlatSearchRequest( q, ArtifactInfo.REPOSITORY_VERSION_COMPARATOR );
- }
- else
- {
- req = new FlatSearchRequest( q, ArtifactInfo.REPOSITORY_VERSION_COMPARATOR );
-
- req.getContexts().add( context );
- }
+ req.getContexts().addAll( getSearchTargetContexts( repositoryId ) );
// if ( from != null )
// {
@@ -1638,12 +1627,6 @@ public FlatSearchResponse searchArtifactFlat( String gTerm, String aTerm, String
return new FlatSearchResponse( null, -1, new HashSet<ArtifactInfo>() );
}
- IndexingContext context = null;
-
- if ( repositoryId != null )
- {
- context = getRepositoryIndexContext( repositoryId );
- }
BooleanQuery bq = new BooleanQuery();
if ( gTerm != null )
@@ -1671,18 +1654,9 @@ public FlatSearchResponse searchArtifactFlat( String gTerm, String aTerm, String
bq.add( constructQuery( MAVEN.CLASSIFIER, cTerm, SearchType.SCORED ), BooleanClause.Occur.MUST );
}
- FlatSearchRequest req = null;
+ FlatSearchRequest req = new FlatSearchRequest( bq, ArtifactInfo.REPOSITORY_VERSION_COMPARATOR );
- if ( repositoryId == null )
- {
- req = new FlatSearchRequest( bq, ArtifactInfo.REPOSITORY_VERSION_COMPARATOR );
- }
- else
- {
- req = new FlatSearchRequest( bq, ArtifactInfo.REPOSITORY_VERSION_COMPARATOR );
-
- req.getContexts().add( context );
- }
+ req.getContexts().addAll( getSearchTargetContexts( repositoryId ) );
// if ( from != null )
// {
@@ -1859,15 +1833,7 @@ public IteratorSearchResponse searchQueryIterator( Query query, String repositor
{
IteratorSearchRequest req = createRequest( query, from, count, hitLimit, uniqueRGA, filters );
- if ( repositoryId != null )
- {
- IndexingContext context = getRepositoryIndexContext( repositoryId );
-
- if ( context != null )
- {
- req.getContexts().add( context );
- }
- }
+ req.getContexts().addAll( getSearchTargetContexts( repositoryId ) );
try
{
@@ -1898,13 +1864,6 @@ public IteratorSearchResponse searchArtifactIterator( String term, String reposi
SearchType searchType, List<ArtifactInfoFilter> filters )
throws NoSuchRepositoryException
{
- IndexingContext context = null;
-
- if ( repositoryId != null )
- {
- context = getRepositoryIndexContext( repositoryId );
- }
-
Query q1 = constructQuery( MAVEN.GROUP_ID, term, searchType );
q1.setBoost( 2.0f );
@@ -1944,10 +1903,7 @@ public IteratorSearchResponse searchArtifactIterator( String term, String reposi
req.getMatchHighlightRequests().add( new MatchHighlightRequest( MAVEN.GROUP_ID, q1, MatchHighlightMode.HTML ) );
req.getMatchHighlightRequests().add( new MatchHighlightRequest( MAVEN.ARTIFACT_ID, q2, MatchHighlightMode.HTML ) );
- if ( repositoryId != null )
- {
- req.getContexts().add( context );
- }
+ req.getContexts().addAll( getSearchTargetContexts( repositoryId ) );
try
{
@@ -1978,13 +1934,6 @@ public IteratorSearchResponse searchArtifactClassIterator( String term, String r
List<ArtifactInfoFilter> filters )
throws NoSuchRepositoryException
{
- IndexingContext context = null;
-
- if ( repositoryId != null )
- {
- context = getRepositoryIndexContext( repositoryId );
- }
-
if ( term.endsWith( ".class" ) )
{
term = term.substring( 0, term.length() - 6 );
@@ -1996,10 +1945,7 @@ public IteratorSearchResponse searchArtifactClassIterator( String term, String r
req.getMatchHighlightRequests().add( new MatchHighlightRequest( MAVEN.CLASSNAMES, q, MatchHighlightMode.HTML ) );
- if ( repositoryId != null )
- {
- req.getContexts().add( context );
- }
+ req.getContexts().addAll( getSearchTargetContexts( repositoryId ) );
try
{
@@ -2036,13 +1982,6 @@ public IteratorSearchResponse searchArtifactIterator( String gTerm, String aTerm
return IteratorSearchResponse.TOO_MANY_HITS_ITERATOR_SEARCH_RESPONSE;
}
- IndexingContext context = null;
-
- if ( repositoryId != null )
- {
- context = getRepositoryIndexContext( repositoryId );
- }
-
BooleanQuery bq = new BooleanQuery();
if ( gTerm != null )
@@ -2090,10 +2029,7 @@ public boolean accepts( IndexingContext ctx, ArtifactInfo ai )
IteratorSearchRequest req = createRequest( bq, from, count, hitLimit, uniqueRGA, filters );
- if ( repositoryId != null )
- {
- req.getContexts().add( context );
- }
+ req.getContexts().addAll( getSearchTargetContexts( repositoryId ) );
try
{
@@ -2129,13 +2065,6 @@ public IteratorSearchResponse searchArtifactSha1ChecksumIterator( String sha1Che
return IteratorSearchResponse.TOO_MANY_HITS_ITERATOR_SEARCH_RESPONSE;
}
- IndexingContext context = null;
-
- if ( repositoryId != null )
- {
- context = getRepositoryIndexContext( repositoryId );
- }
-
SearchType searchType = sha1Checksum.length() == 40 ? SearchType.EXACT : SearchType.SCORED;
BooleanQuery bq = new BooleanQuery();
@@ -2147,10 +2076,7 @@ public IteratorSearchResponse searchArtifactSha1ChecksumIterator( String sha1Che
IteratorSearchRequest req = createRequest( bq, from, count, hitLimit, false, filters );
- if ( repositoryId != null )
- {
- req.getContexts().add( context );
- }
+ req.getContexts().addAll( getSearchTargetContexts( repositoryId ) );
try
{
View
1  ...dexer-lucene-plugin/src/main/java/org/sonatype/nexus/index/LazyContextMemberProvider.java
@@ -89,6 +89,7 @@ public LazyContextMemberProvider( final DefaultIndexerManager indexerManager, fi
logger.debug( "Lazy context provider unable to lookup member by ID!", e );
}
}
+ contexts = Contexts.sort( contexts );
}
return contexts;
}
Please sign in to comment.
Something went wrong with that request. Please try again.