Repository: maven-indexer
Updated Branches:
  refs/heads/master 7bcf5312e -> ac19770a3


Indexing a repository with the indexer-cli (using -i and -r parameters) creates 
an empty packed index.

Caused by the fact that the IndexSearcher obtained before indexer.scan() is 
called is the same one that is passed to the IndexPackingUpdate, however, once 
indexer.scan() is executed, the context's (directory) content is replaced with 
the temporay one (used for downloading) but the previously returned 
IndexSearcher is invalidated by the DefaultIndexingContext.openAndWarmup() 
method that is called for the new index directory. Any packing operation that 
is attempted from this point will produce an empty packed index instead of 
using the actual index content produced by the indexer.scan() method.

Fixed by acquireing the indexSearcher *after* the indexer.scan() method 
finishes, so that the pack operation works with the actual data and produces a 
proper packed index.


Project: http://git-wip-us.apache.org/repos/asf/maven-indexer/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-indexer/commit/3241c273
Tree: http://git-wip-us.apache.org/repos/asf/maven-indexer/tree/3241c273
Diff: http://git-wip-us.apache.org/repos/asf/maven-indexer/diff/3241c273

Branch: refs/heads/master
Commit: 3241c273d2d8acf4fb07899beffbfaf7fe083ebd
Parents: 1c2af7a
Author: Eduard Moraru <enygma2...@gmail.com>
Authored: Mon Jan 12 15:43:57 2015 +0200
Committer: Eduard Moraru <enygma2...@gmail.com>
Committed: Mon Jan 12 15:43:57 2015 +0200

----------------------------------------------------------------------
 .../apache/maven/index/cli/NexusIndexerCli.java | 28 +++++++++++++-------
 1 file changed, 18 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven-indexer/blob/3241c273/indexer-cli/src/main/java/org/apache/maven/index/cli/NexusIndexerCli.java
----------------------------------------------------------------------
diff --git 
a/indexer-cli/src/main/java/org/apache/maven/index/cli/NexusIndexerCli.java 
b/indexer-cli/src/main/java/org/apache/maven/index/cli/NexusIndexerCli.java
index dc4a8f7..c140ace 100644
--- a/indexer-cli/src/main/java/org/apache/maven/index/cli/NexusIndexerCli.java
+++ b/indexer-cli/src/main/java/org/apache/maven/index/cli/NexusIndexerCli.java
@@ -352,7 +352,6 @@ public class NexusIndexerCli
             null, // index update url
             indexers );
 
-        final IndexSearcher indexSearcher = context.acquireIndexSearcher();
         try
         {
             IndexPacker packer = plexus.lookup( IndexPacker.class );
@@ -361,21 +360,31 @@ public class NexusIndexerCli
 
             indexer.scan( context, listener, true );
 
-            IndexPackingRequest request = new IndexPackingRequest( context, 
indexSearcher.getIndexReader(), outputFolder );
+            IndexSearcher indexSearcher = context.acquireIndexSearcher();
 
-            request.setCreateChecksumFiles( createChecksums );
+            try
+            {
+                IndexPackingRequest request =
+                    new IndexPackingRequest(context, 
indexSearcher.getIndexReader(), outputFolder);
+
+                request.setCreateChecksumFiles(createChecksums);
 
-            request.setCreateIncrementalChunks( createIncrementalChunks );
+                request.setCreateIncrementalChunks(createIncrementalChunks);
 
-            request.setFormats( Arrays.asList( IndexFormat.FORMAT_V1 ) );
+                request.setFormats(Arrays.asList(IndexFormat.FORMAT_V1));
 
-            if ( chunkCount != null )
+                if (chunkCount != null)
+                {
+                    request.setMaxIndexChunks(chunkCount.intValue());
+                }
+
+                packIndex(packer, request, debug, quiet);
+            }
+            finally
             {
-                request.setMaxIndexChunks( chunkCount.intValue() );
+                context.releaseIndexSearcher(indexSearcher);
             }
 
-            packIndex( packer, request, debug, quiet );
-
             if ( !quiet )
             {
                 printStats( tstart );
@@ -383,7 +392,6 @@ public class NexusIndexerCli
         }
         finally
         {
-            context.releaseIndexSearcher( indexSearcher );
             indexer.removeIndexingContext( context, false );
         }
     }

Reply via email to