You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by ud...@apache.org on 2018/03/20 18:52:52 UTC

[geode] branch feature/GEODE-3926_2 updated: more WIP

This is an automated email from the ASF dual-hosted git repository.

udo pushed a commit to branch feature/GEODE-3926_2
in repository https://gitbox.apache.org/repos/asf/geode.git


The following commit(s) were added to refs/heads/feature/GEODE-3926_2 by this push:
     new 5b96909  more WIP
5b96909 is described below

commit 5b9690968e2fd19423e83345eceb4981b5af8b34
Author: Udo <uk...@pivotal.io>
AuthorDate: Tue Mar 20 11:52:43 2018 -0700

    more WIP
---
 .../lucene/internal/IndexRepositoryFactory.java    |  1 -
 .../internal/LuceneIndexForPartitionedRegion.java  | 61 ++++++---------
 .../cache/lucene/internal/LuceneIndexImpl.java     | 15 +++-
 .../cache/lucene/internal/LuceneRawIndex.java      | 10 +--
 .../lucene/internal/LuceneRawIndexFactory.java     | 11 ++-
 .../lucene/internal/LuceneRegionListener.java      |  3 +-
 .../cache/lucene/internal/LuceneServiceImpl.java   | 20 ++---
 .../internal/PartitionedRepositoryManager.java     |  6 +-
 .../lucene/internal/LuceneIndexFactorySpy.java     | 23 +++---
 .../LuceneIndexForPartitionedRegionTest.java       | 85 +++++++++------------
 .../PartitionedRepositoryManagerJUnitTest.java     | 87 ++++++++++++++++++----
 .../RawLuceneRepositoryManagerJUnitTest.java       |  2 +-
 12 files changed, 172 insertions(+), 152 deletions(-)

diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/IndexRepositoryFactory.java b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/IndexRepositoryFactory.java
index b3aeeee..fcb1620 100644
--- a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/IndexRepositoryFactory.java
+++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/IndexRepositoryFactory.java
@@ -50,7 +50,6 @@ public class IndexRepositoryFactory {
   public IndexRepository computeIndexRepository(final Integer bucketId, LuceneSerializer serializer,
       InternalLuceneIndex index, PartitionedRegion userRegion, final IndexRepository oldRepository)
       throws IOException {
-    System.out.println(this+".computeIndexRepository bucketId: "+bucketId);
     return ((LuceneIndexForPartitionedRegion) index).computeIndexRepository(bucketId, serializer,
         userRegion, oldRepository);
   }
diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneIndexForPartitionedRegion.java b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneIndexForPartitionedRegion.java
index 58e270b..1199e4c 100644
--- a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneIndexForPartitionedRegion.java
+++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneIndexForPartitionedRegion.java
@@ -67,23 +67,27 @@ import org.apache.geode.internal.cache.PartitionedRegionHelper;
 import org.apache.geode.internal.logging.LogService;
 
 public class LuceneIndexForPartitionedRegion extends LuceneIndexImpl {
-  protected Region fileAndChunkRegion;
-  protected final FileSystemStats fileSystemStats;
+  private Region fileAndChunkRegion;
+  private final FileSystemStats fileSystemStats;
 
   public static final String FILES_REGION_SUFFIX = ".files";
   private static final Logger logger = LogService.getLogger();
-  public static final String FILE_REGION_LOCK_FOR_BUCKET_ID = "FileRegionLockForBucketId:";
+  private static final String FILE_REGION_LOCK_FOR_BUCKET_ID = "FileRegionLockForBucketId:";
 
   private ExecutorService waitingThreadPool;
 
+  // For Mocking only
+  LuceneIndexForPartitionedRegion() {
+    this.fileSystemStats = null;
+  }
+
   public LuceneIndexForPartitionedRegion(String indexName, String regionPath, InternalCache cache,
-                                         Analyzer analyzer, Map<String, Analyzer> fieldAnalyzers,
-                                         LuceneSerializer serializer,
-                                         RegionAttributes attributes, String aeqId, String[] fields,
-                                         ExecutorService waitingThreadPool) {
+      Analyzer analyzer, Map<String, Analyzer> fieldAnalyzers, LuceneSerializer serializer,
+      RegionAttributes attributes, String aeqId, String[] fields,
+      ExecutorService waitingThreadPool) {
     super(indexName, regionPath, cache, serializer, fieldAnalyzers);
     final String statsName = indexName + "-" + regionPath;
-    this.fileSystemStats = new FileSystemStats(cache.getDistributedSystem(), statsName);
+    this.fileSystemStats = new FileSystemStats(getCache().getDistributedSystem(), statsName);
     this.waitingThreadPool = waitingThreadPool;
     this.setSearchableFields(fields);
     this.setAnalyzer(analyzer);
@@ -99,15 +103,12 @@ public class LuceneIndexForPartitionedRegion extends LuceneIndexImpl {
     if (mapper == null) {
       mapper = new HeterogeneousLuceneSerializer();
     }
-    PartitionedRepositoryManager partitionedRepositoryManager =
-        new PartitionedRepositoryManager(this, mapper, waitingThreadPool);
-    return partitionedRepositoryManager;
+    return new PartitionedRepositoryManager(this, mapper, waitingThreadPool);
   }
 
   protected void createLuceneListenersAndFileChunkRegions(
       PartitionedRepositoryManager partitionedRepositoryManager) {
-    partitionedRepositoryManager
-        .setUserRegionForRepositoryManager((PartitionedRegion) dataRegion);
+    partitionedRepositoryManager.setUserRegionForRepositoryManager((PartitionedRegion) dataRegion);
     RegionShortcut regionShortCut;
     final boolean withPersistence = withPersistence();
     RegionAttributes regionAttributes = dataRegion.getAttributes();
@@ -136,9 +137,6 @@ public class LuceneIndexForPartitionedRegion extends LuceneIndexImpl {
     if (!fileRegionExists(fileRegionName)) {
       fileAndChunkRegion = createRegion(fileRegionName, regionShortCut, this.regionPath,
           partitionAttributes, regionAttributes, lucenePrimaryBucketListener);
-      System.err
-          .println(this + ".createLuceneListenersAndFileChunkRegions   fileAndChunkRegion: "
-              + fileAndChunkRegion);
     } else {
       fileAndChunkRegion = this.cache.getRegion(fileRegionName);
     }
@@ -184,11 +182,9 @@ public class LuceneIndexForPartitionedRegion extends LuceneIndexImpl {
   }
 
   protected <K, V> Region<K, V> createRegion(final String regionName,
-                                             final RegionShortcut regionShortCut,
-                                             final String colocatedWithRegionName,
-                                             final PartitionAttributes partitionAttributes,
-                                             final RegionAttributes regionAttributes,
-                                             PartitionListener lucenePrimaryBucketListener) {
+      final RegionShortcut regionShortCut, final String colocatedWithRegionName,
+      final PartitionAttributes partitionAttributes, final RegionAttributes regionAttributes,
+      PartitionListener lucenePrimaryBucketListener) {
     PartitionAttributesFactory partitionAttributesFactory = new PartitionAttributesFactory();
     if (lucenePrimaryBucketListener != null) {
       partitionAttributesFactory.addPartitionListener(lucenePrimaryBucketListener);
@@ -208,13 +204,12 @@ public class LuceneIndexForPartitionedRegion extends LuceneIndexImpl {
     return createRegion(regionName, attributes);
   }
 
-  public void close() {
-  }
+  public void close() {}
 
   @Override
   public void dumpFiles(final String directory) {
     ResultCollector results = FunctionService.onRegion(getDataRegion())
-        .setArguments(new String[]{directory, indexName}).execute(DumpDirectoryFiles.ID);
+        .setArguments(new String[] {directory, indexName}).execute(DumpDirectoryFiles.ID);
     results.getResult();
   }
 
@@ -253,8 +248,7 @@ public class LuceneIndexForPartitionedRegion extends LuceneIndexImpl {
   public boolean isIndexAvailable(int id) {
     PartitionedRegion fileAndChunkRegion = getFileAndChunkRegion();
     if (fileAndChunkRegion != null) {
-      return fileAndChunkRegion.get(IndexRepositoryFactory.APACHE_GEODE_INDEX_COMPLETE, id)
-          != null;
+      return fileAndChunkRegion.get(IndexRepositoryFactory.APACHE_GEODE_INDEX_COMPLETE, id) != null;
     }
     return false;
   }
@@ -288,11 +282,8 @@ public class LuceneIndexForPartitionedRegion extends LuceneIndexImpl {
     }
   }
 
-  public IndexRepository computeIndexRepository(final Integer bucketId, LuceneSerializer
-      serializer,
-                                                PartitionedRegion userRegion,
-                                                final IndexRepository oldRepository)
-      throws IOException {
+  public IndexRepository computeIndexRepository(final Integer bucketId, LuceneSerializer serializer,
+      PartitionedRegion userRegion, final IndexRepository oldRepository) throws IOException {
     final PartitionedRegion fileRegion = getFileAndChunkRegion();
     BucketRegion fileAndChunkBucket = getFileBucketRegion(bucketId, fileRegion);
 
@@ -304,11 +295,9 @@ public class LuceneIndexForPartitionedRegion extends LuceneIndexImpl {
       }
       return null;
     }
-
     if (oldRepository != null && !oldRepository.isClosed()) {
       return oldRepository;
     }
-
     if (oldRepository != null) {
       oldRepository.cleanup();
     }
@@ -319,7 +308,6 @@ public class LuceneIndexForPartitionedRegion extends LuceneIndexImpl {
         return null;
       }
     }
-
     InternalCache cache = (InternalCache) userRegion.getRegionService();
     boolean initialPdxReadSerializedFlag = cache.getPdxReadSerializedOverride();
     cache.setPdxReadSerializedOverride(true);
@@ -360,8 +348,6 @@ public class LuceneIndexForPartitionedRegion extends LuceneIndexImpl {
 
   private BucketRegion getFileBucketRegion(Integer bucketId, PartitionedRegion fileRegion) {
     // We need to ensure that all members have created the fileAndChunk region before continuing
-    System.err.println(
-        this + ".getFileBucketRegion for bucket: " + bucketId + "  fileRegion:" + fileRegion);
     Region prRoot = PartitionedRegionHelper.getPRRoot(fileRegion.getCache());
     PartitionRegionConfig prConfig =
         (PartitionRegionConfig) prRoot.get(fileRegion.getRegionIdentifier());
@@ -373,8 +359,7 @@ public class LuceneIndexForPartitionedRegion extends LuceneIndexImpl {
   }
 
   private boolean reindexUserDataRegion(Integer bucketId, PartitionedRegion userRegion,
-                                        PartitionedRegion fileRegion, BucketRegion dataBucket,
-                                        IndexRepository repo)
+      PartitionedRegion fileRegion, BucketRegion dataBucket, IndexRepository repo)
       throws IOException {
     Set<IndexRepository> affectedRepos = new HashSet<IndexRepository>();
 
diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneIndexImpl.java b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneIndexImpl.java
index d6b608d..7d3aa5d 100644
--- a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneIndexImpl.java
+++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneIndexImpl.java
@@ -14,7 +14,6 @@
  */
 package org.apache.geode.cache.lucene.internal;
 
-import java.util.Collections;
 import java.util.Map;
 
 import org.apache.logging.log4j.Logger;
@@ -55,14 +54,22 @@ public abstract class LuceneIndexImpl implements InternalLuceneIndex {
   protected LuceneSerializer luceneSerializer;
   protected LocalRegion dataRegion;
 
+  LuceneIndexImpl() {
+    this(null, null, null, null, null);
+  }
+
   protected LuceneIndexImpl(String indexName, String regionPath, InternalCache cache,
-                            LuceneSerializer serializer, Map<String, Analyzer> fieldAnalyzers) {
+      LuceneSerializer serializer, Map<String, Analyzer> fieldAnalyzers) {
     this.indexName = indexName;
     this.regionPath = regionPath;
     this.cache = cache;
 
     final String statsName = indexName + "-" + regionPath;
-    this.indexStats = new LuceneIndexStats(cache.getDistributedSystem(), statsName);
+    if (getCache() != null) {
+      this.indexStats = new LuceneIndexStats(getCache().getDistributedSystem(), statsName);
+    } else {
+      this.indexStats = null;
+    }
     luceneSerializer = serializer;
     repositoryManager = createRepositoryManager(luceneSerializer);
     this.fieldAnalyzers = fieldAnalyzers;
@@ -248,7 +255,7 @@ public abstract class LuceneIndexImpl implements InternalLuceneIndex {
   }
 
   protected <K, V> Region<K, V> createRegion(final String regionName,
-                                             final RegionAttributes<K, V> attributes) {
+      final RegionAttributes<K, V> attributes) {
     // Create InternalRegionArguments to set isUsedForMetaRegion true to suppress xml generation
     // (among other things)
     InternalRegionArguments ira =
diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneRawIndex.java b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneRawIndex.java
index a074bd6..eb41eeb 100755
--- a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneRawIndex.java
+++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneRawIndex.java
@@ -28,10 +28,9 @@ import org.apache.geode.internal.cache.PartitionedRegion;
 
 public class LuceneRawIndex extends LuceneIndexImpl {
   public LuceneRawIndex(String indexName, String regionPath, InternalCache cache, Analyzer analyzer,
-                        Map<String, Analyzer> fieldAnalyzers,
-                        LuceneSerializer serializer, RegionAttributes attributes, String aeqId,
-                        String[] fields,
-                        ExecutorService waitingThreadPool) {
+      Map<String, Analyzer> fieldAnalyzers, LuceneSerializer serializer,
+      RegionAttributes attributes, String aeqId, String[] fields,
+      ExecutorService waitingThreadPool) {
     super(indexName, regionPath, cache, serializer, fieldAnalyzers);
     this.setSearchableFields(fields);
     this.setAnalyzer(analyzer);
@@ -61,8 +60,7 @@ public class LuceneRawIndex extends LuceneIndexImpl {
   }
 
   @Override
-  public void destroy(boolean initiator) {
-  }
+  public void destroy(boolean initiator) {}
 
   @Override
   public boolean isIndexAvailable(int id) {
diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneRawIndexFactory.java b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneRawIndexFactory.java
index a84b846..0e290b6 100755
--- a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneRawIndexFactory.java
+++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneRawIndexFactory.java
@@ -25,11 +25,10 @@ import org.apache.geode.internal.cache.InternalCache;
 
 public class LuceneRawIndexFactory extends LuceneIndexImplFactory {
   public LuceneIndexImpl create(String indexName, String regionPath, InternalCache cache,
-                                Analyzer analyzer, Map<String, Analyzer> fieldAnalyzers,
-                                LuceneSerializer serializer,
-                                RegionAttributes attributes, String aeqId, String[] fields,
-                                ExecutorService waitingThreadPool) {
-    return new LuceneRawIndex(indexName, regionPath, cache, analyzer,
-        fieldAnalyzers, serializer, attributes, aeqId, fields, waitingThreadPool);
+      Analyzer analyzer, Map<String, Analyzer> fieldAnalyzers, LuceneSerializer serializer,
+      RegionAttributes attributes, String aeqId, String[] fields,
+      ExecutorService waitingThreadPool) {
+    return new LuceneRawIndex(indexName, regionPath, cache, analyzer, fieldAnalyzers, serializer,
+        attributes, aeqId, fields, waitingThreadPool);
   }
 }
diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneRegionListener.java b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneRegionListener.java
index 9a9ce7c..06371c6 100644
--- a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneRegionListener.java
+++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneRegionListener.java
@@ -107,7 +107,8 @@ public class LuceneRegionListener implements RegionListener {
   public void afterCreate(Region region) {
     if (region.getFullPath().equals(this.regionPath)
         && this.afterCreateInvoked.compareAndSet(false, true)) {
-      System.err.println(this+".afterCreate Service: "+service+"   LuceneIndex: "+luceneIndex);
+      System.err
+          .println(this + ".afterCreate Service: " + service + "   LuceneIndex: " + luceneIndex);
       this.service.afterDataRegionCreated(this.luceneIndex);
     }
   }
diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneServiceImpl.java b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneServiceImpl.java
index 5451b5f..8617256 100644
--- a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneServiceImpl.java
+++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneServiceImpl.java
@@ -231,7 +231,7 @@ public class LuceneServiceImpl implements InternalLuceneService {
     LuceneIndexImpl luceneIndex = beforeDataRegionCreated(indexName, regionPath,
         region.getAttributes(), analyzer, fieldAnalyzers, aeqId, serializer, fields);
 
-    System.out.println(this+".createIndexOnExistingRegion  index: "+luceneIndex);
+    System.out.println(this + ".createIndexOnExistingRegion  index: " + luceneIndex);
     afterDataRegionCreated(luceneIndex);
 
     region.addAsyncEventQueueId(aeqId, true);
@@ -324,23 +324,19 @@ public class LuceneServiceImpl implements InternalLuceneService {
       RegionAttributes attributes, final Analyzer analyzer,
       final Map<String, Analyzer> fieldAnalyzers, String aeqId, final LuceneSerializer serializer,
       final String... fields) {
-    LuceneIndexImpl
-        index =
-        createIndexObject(indexName, regionPath, fields, analyzer, fieldAnalyzers, serializer,
-            attributes, aeqId);
-    System.err.println(this+".beforeDataRegionCreated Index: "+index);
+    LuceneIndexImpl index = createIndexObject(indexName, regionPath, fields, analyzer,
+        fieldAnalyzers, serializer, attributes, aeqId);
+    System.err.println(this + ".beforeDataRegionCreated Index: " + index);
     return index;
   }
 
   private LuceneIndexImpl createIndexObject(String indexName, String regionPath, String[] fields,
       Analyzer analyzer, Map<String, Analyzer> fieldAnalyzers, LuceneSerializer serializer,
       RegionAttributes attributes, String aeqId) {
-    System.err.println(this+".createIndexObject LuceneIndexFactory: "+luceneIndexFactory);
-    LuceneIndexImpl
-        index =
-        luceneIndexFactory.create(indexName, regionPath, cache, analyzer, fieldAnalyzers,
-            serializer, attributes, aeqId, fields, dm.getWaitingThreadPool());
-    System.err.println(this+".createIndexObject Index: "+index);
+    System.err.println(this + ".createIndexObject LuceneIndexFactory: " + luceneIndexFactory);
+    LuceneIndexImpl index = luceneIndexFactory.create(indexName, regionPath, cache, analyzer,
+        fieldAnalyzers, serializer, attributes, aeqId, fields, dm.getWaitingThreadPool());
+    System.err.println(this + ".createIndexObject Index: " + index);
     return index;
   }
 
diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/PartitionedRepositoryManager.java b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/PartitionedRepositoryManager.java
index 658182b..90828d2 100755
--- a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/PartitionedRepositoryManager.java
+++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/PartitionedRepositoryManager.java
@@ -77,7 +77,7 @@ public class PartitionedRepositoryManager implements RepositoryManager {
 
   @Override
   public Collection<IndexRepository> getRepositories(RegionFunctionContext ctx)
-      throws BucketNotFoundException {
+      throws BucketNotFoundException, LuceneIndexCreationInProgressException {
     Region<Object, Object> region = ctx.getDataSet();
     Set<Integer> buckets = ((InternalRegionFunctionContext) ctx).getLocalBucketSet(region);
     ArrayList<IndexRepository> repos = new ArrayList<IndexRepository>(buckets.size());
@@ -92,7 +92,8 @@ public class PartitionedRepositoryManager implements RepositoryManager {
         } else {
           waitingThreadPoolFromDM.execute(() -> {
             try {
-              repos.add(getRepository(userBucket.getId()));
+              IndexRepository repository = getRepository(userBucket.getId());
+              repos.add(repository);
             } catch (BucketNotFoundException e) {
               logger.debug(
                   "Lucene Index creation still in progress. Catching BucketNotFoundException");
@@ -140,7 +141,6 @@ public class PartitionedRepositoryManager implements RepositoryManager {
   protected IndexRepository computeRepository(Integer bucketId, LuceneSerializer serializer,
       InternalLuceneIndex index, PartitionedRegion userRegion, IndexRepository oldRepository)
       throws IOException {
-    System.err.println(this+".computeRepository23232 index: "+index);
     return indexRepositoryFactory.computeIndexRepository(bucketId, serializer, index, userRegion,
         oldRepository);
   }
diff --git a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/LuceneIndexFactorySpy.java b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/LuceneIndexFactorySpy.java
index 6625515..90d3b26 100644
--- a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/LuceneIndexFactorySpy.java
+++ b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/LuceneIndexFactorySpy.java
@@ -42,15 +42,14 @@ public class LuceneIndexFactorySpy extends LuceneIndexImplFactory {
 
   @Override
   public LuceneIndexImpl create(String indexName, String regionPath, InternalCache cache,
-                                Analyzer analyzer, Map<String, Analyzer> fieldAnalyzers,
-                                LuceneSerializer serializer,
-                                RegionAttributes attributes, String aeqId, String[] fields,
-                                ExecutorService waitingThreadPool) {
+      Analyzer analyzer, Map<String, Analyzer> fieldAnalyzers, LuceneSerializer serializer,
+      RegionAttributes attributes, String aeqId, String[] fields,
+      ExecutorService waitingThreadPool) {
 
     LuceneIndexForPartitionedRegion index =
-        Mockito.spy(new ExtendedLuceneIndexForPartitionedRegion(indexName, regionPath, cache, analyzer, fieldAnalyzers, serializer, attributes, aeqId,
-            fields, waitingThreadPool));
-    System.err.println(this+".create  "+index);
+        Mockito.spy(new ExtendedLuceneIndexForPartitionedRegion(indexName, regionPath, cache,
+            analyzer, fieldAnalyzers, serializer, attributes, aeqId, fields, waitingThreadPool));
+    System.err.println(this + ".create  " + index);
     return index;
   }
 
@@ -64,13 +63,9 @@ public class LuceneIndexFactorySpy extends LuceneIndexImplFactory {
 
 
     public ExtendedLuceneIndexForPartitionedRegion(String indexName, String regionPath,
-                                                   InternalCache cache,
-                                                   Analyzer analyzer,
-                                                   Map<String, Analyzer> fieldAnalyzers,
-                                                   LuceneSerializer serializer,
-                                                   RegionAttributes attributes, String aeqId,
-                                                   String[] fields,
-                                                   ExecutorService waitingThreadPool) {
+        InternalCache cache, Analyzer analyzer, Map<String, Analyzer> fieldAnalyzers,
+        LuceneSerializer serializer, RegionAttributes attributes, String aeqId, String[] fields,
+        ExecutorService waitingThreadPool) {
       super(indexName, regionPath, cache, analyzer, fieldAnalyzers, serializer, attributes, aeqId,
           fields, waitingThreadPool);
     }
diff --git a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/LuceneIndexForPartitionedRegionTest.java b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/LuceneIndexForPartitionedRegionTest.java
index ee25162..99b6064 100644
--- a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/LuceneIndexForPartitionedRegionTest.java
+++ b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/LuceneIndexForPartitionedRegionTest.java
@@ -79,9 +79,8 @@ public class LuceneIndexForPartitionedRegionTest {
     String name = "indexName";
     String regionPath = "regionName";
     InternalCache cache = Fakes.cache();
-    LuceneIndexForPartitionedRegion index =
-        new LuceneIndexForPartitionedRegion(name, regionPath, cache, null, null, null,
-            null, null, null, executorService);
+    LuceneIndexForPartitionedRegion index = new LuceneIndexForPartitionedRegion(name, regionPath,
+        cache, null, null, null, null, null, null, executorService);
     assertEquals(name, index.getName());
   }
 
@@ -90,9 +89,8 @@ public class LuceneIndexForPartitionedRegionTest {
     String name = "indexName";
     String regionPath = "regionName";
     InternalCache cache = Fakes.cache();
-    LuceneIndexForPartitionedRegion index =
-        new LuceneIndexForPartitionedRegion(name, regionPath, cache, null, null, null,
-            null, null, null, executorService);
+    LuceneIndexForPartitionedRegion index = new LuceneIndexForPartitionedRegion(name, regionPath,
+        cache, null, null, null, null, null, null, executorService);
     assertEquals(regionPath, index.getRegionPath());
   }
 
@@ -102,9 +100,8 @@ public class LuceneIndexForPartitionedRegionTest {
     String regionPath = "regionName";
     InternalCache cache = Fakes.cache();
     PartitionedRegion region = mock(PartitionedRegion.class);
-    LuceneIndexForPartitionedRegion index =
-        new LuceneIndexForPartitionedRegion(name, regionPath, cache, null, null, null,
-            region.getAttributes(), null, null, executorService);
+    LuceneIndexForPartitionedRegion index = new LuceneIndexForPartitionedRegion(name, regionPath,
+        cache, null, null, null, region.getAttributes(), null, null, executorService);
     String fileRegionName = index.createFileRegionName();
     when(cache.getRegion(fileRegionName)).thenReturn(region);
 
@@ -116,9 +113,8 @@ public class LuceneIndexForPartitionedRegionTest {
     String name = "indexName";
     String regionPath = "regionName";
     InternalCache cache = Fakes.cache();
-    LuceneIndexForPartitionedRegion index =
-        new LuceneIndexForPartitionedRegion(name, regionPath, cache, null, null, null,
-            null, null, null, executorService);
+    LuceneIndexForPartitionedRegion index = new LuceneIndexForPartitionedRegion(name, regionPath,
+        cache, null, null, null, null, null, null, executorService);
     String fileRegionName = index.createFileRegionName();
     when(cache.getRegion(fileRegionName)).thenReturn(null);
 
@@ -137,9 +133,8 @@ public class LuceneIndexForPartitionedRegionTest {
     AsyncEventQueueFactoryImpl aeqFactory = mock(AsyncEventQueueFactoryImpl.class);
     when(cache.createAsyncEventQueueFactory()).thenReturn(aeqFactory);
 
-    LuceneIndexForPartitionedRegion index =
-        new LuceneIndexForPartitionedRegion(name, regionPath, cache, null, null, null,
-            region.getAttributes(), null, null, executorService);
+    LuceneIndexForPartitionedRegion index = new LuceneIndexForPartitionedRegion(name, regionPath,
+        cache, null, null, null, region.getAttributes(), null, null, executorService);
 
     verify(aeqFactory).setPersistent(eq(true));
     verify(aeqFactory).create(any(), any());
@@ -152,9 +147,8 @@ public class LuceneIndexForPartitionedRegionTest {
     String regionPath = "regionName";
     InternalCache cache = Fakes.cache();
     LuceneSerializer serializer = mock(LuceneSerializer.class);
-    LuceneIndexForPartitionedRegion index =
-        spy(new LuceneIndexForPartitionedRegion(name, regionPath, cache, null, null, serializer,
-            null, null, null, executorService));
+    LuceneIndexForPartitionedRegion index = spy(new LuceneIndexForPartitionedRegion(name,
+        regionPath, cache, null, null, serializer, null, null, null, executorService));
     verify(index).createRepositoryManager(eq(serializer));
   }
 
@@ -167,9 +161,8 @@ public class LuceneIndexForPartitionedRegionTest {
     InternalCache cache = Fakes.cache();
     ArgumentCaptor<LuceneSerializer> serializerCaptor =
         ArgumentCaptor.forClass(LuceneSerializer.class);
-    LuceneIndexForPartitionedRegion index =
-        new LuceneIndexForPartitionedRegion(name, regionPath, cache, null, null, null,
-            null, null, fields, executorService);
+    LuceneIndexForPartitionedRegion index = new LuceneIndexForPartitionedRegion(name, regionPath,
+        cache, null, null, null, null, null, fields, executorService);
     index = spy(index);
     verify(index).createRepositoryManager(serializerCaptor.capture());
     LuceneSerializer serializer = serializerCaptor.getValue();
@@ -186,22 +179,21 @@ public class LuceneIndexForPartitionedRegionTest {
     AsyncEventQueueFactoryImpl aeqFactory = mock(AsyncEventQueueFactoryImpl.class);
     when(cache.createAsyncEventQueueFactory()).thenReturn(aeqFactory);
 
-    LuceneIndexForPartitionedRegion index =
-        new LuceneIndexForPartitionedRegion(name, regionPath, cache, null, null, null,
-            region.getAttributes(), null, null, executorService);
+    LuceneIndexForPartitionedRegion index = new LuceneIndexForPartitionedRegion(name, regionPath,
+        cache, null, null, null, region.getAttributes(), null, null, executorService);
 
     verify(aeqFactory, never()).setPersistent(eq(true));
     verify(aeqFactory).create(any(), any());
   }
 
   private Region initializeScenario(final boolean withPersistence, final String regionPath,
-                                    final Cache cache) {
+      final Cache cache) {
     int defaultLocalMemory = 100;
     return initializeScenario(withPersistence, regionPath, cache, defaultLocalMemory);
   }
 
   private RegionAttributes createRegionAttributes(final boolean withPersistence,
-                                                  PartitionAttributes partitionAttributes) {
+      PartitionAttributes partitionAttributes) {
     AttributesFactory factory = new AttributesFactory();
     if (withPersistence) {
       factory.setDataPolicy(DataPolicy.PERSISTENT_PARTITION);
@@ -214,7 +206,7 @@ public class LuceneIndexForPartitionedRegionTest {
   }
 
   private Region initializeScenario(final boolean withPersistence, final String regionPath,
-                                    final Cache cache, int localMaxMemory) {
+      final Cache cache, int localMaxMemory) {
     PartitionedRegion region = mock(PartitionedRegion.class);
     PartitionAttributes partitionAttributes = new PartitionAttributesFactory()
         .setLocalMaxMemory(localMaxMemory).setTotalNumBuckets(103).create();
@@ -254,9 +246,8 @@ public class LuceneIndexForPartitionedRegionTest {
     Region region = initializeScenario(withPersistence, regionPath, cache, 0);
 
     RegionAttributes regionAttributes = region.getAttributes();
-    LuceneIndexForPartitionedRegion index =
-        new LuceneIndexForPartitionedRegion(name, regionPath, cache, null, null, null,
-            regionAttributes, "aeq", null, executorService);
+    LuceneIndexForPartitionedRegion index = new LuceneIndexForPartitionedRegion(name, regionPath,
+        cache, null, null, null, regionAttributes, "aeq", null, executorService);
     LuceneIndexForPartitionedRegion spy = setupSpy(region, index, "aeq");
     spy.initialize();
   }
@@ -271,15 +262,13 @@ public class LuceneIndexForPartitionedRegionTest {
     Region region = initializeScenario(withPersistence, regionPath, cache);
 
     RegionAttributes regionAttributes = region.getAttributes();
-    LuceneIndexForPartitionedRegion index =
-        new LuceneIndexForPartitionedRegion(name, regionPath, cache, null, null, null,
-            regionAttributes, "aeq", null, executorService);
+    LuceneIndexForPartitionedRegion index = new LuceneIndexForPartitionedRegion(name, regionPath,
+        cache, null, null, null, regionAttributes, "aeq", null, executorService);
   }
 
   protected LuceneIndexForPartitionedRegion setupSpy(final Region region,
-                                                     final LuceneIndexForPartitionedRegion index,
-                                                     final String aeq) {
-    index.setSearchableFields(new String[]{"field"});
+      final LuceneIndexForPartitionedRegion index, final String aeq) {
+    index.setSearchableFields(new String[] {"field"});
     LuceneIndexForPartitionedRegion spy = spy(index);
     doReturn(null).when(spy).createRegion(any(), any(), any(), any(), any(), any());
     doReturn(null).when(spy).createAEQ(any(), any());
@@ -296,9 +285,8 @@ public class LuceneIndexForPartitionedRegionTest {
     Region region = initializeScenario(withPersistence, regionPath, cache);
     AsyncEventQueueFactoryImpl aeqFactory = mock(AsyncEventQueueFactoryImpl.class);
     when(cache.createAsyncEventQueueFactory()).thenReturn(aeqFactory);
-    LuceneIndexForPartitionedRegion index =
-        new LuceneIndexForPartitionedRegion(name, regionPath, cache, null, null, null,
-            region.getAttributes(), "aeq", null, executorService);
+    LuceneIndexForPartitionedRegion index = new LuceneIndexForPartitionedRegion(name, regionPath,
+        cache, null, null, null, region.getAttributes(), "aeq", null, executorService);
     LuceneIndexForPartitionedRegion spy = setupSpy(region, index, "aeq");
 
     verify(spy).createRegion(eq(index.createFileRegionName()), eq(RegionShortcut.PARTITION), any(),
@@ -314,9 +302,8 @@ public class LuceneIndexForPartitionedRegionTest {
     RegionAttributes regionAttributes = mock(RegionAttributes.class);
     when(regionAttributes.getDataPolicy()).thenReturn(DataPolicy.PARTITION);
     PartitionAttributes partitionAttributes = initializeAttributes(cache);
-    LuceneIndexForPartitionedRegion index =
-        new LuceneIndexForPartitionedRegion(name, regionPath, cache, null, null, null,
-            regionAttributes, null, null, executorService);
+    LuceneIndexForPartitionedRegion index = new LuceneIndexForPartitionedRegion(name, regionPath,
+        cache, null, null, null, regionAttributes, null, null, executorService);
     LuceneIndexForPartitionedRegion indexSpy = spy(index);
     indexSpy.createRegion(index.createFileRegionName(), RegionShortcut.PARTITION, regionPath,
         partitionAttributes, regionAttributes, null);
@@ -334,10 +321,9 @@ public class LuceneIndexForPartitionedRegionTest {
     InternalCache cache = Fakes.cache();
     initializeScenario(withPersistence, regionPath, cache);
 
-    LuceneIndexForPartitionedRegion index =
-        new LuceneIndexForPartitionedRegion(name, regionPath, cache, null, null, null,
-            null, null, null, executorService);
-    index.setSearchableFields(new String[]{"field"});
+    LuceneIndexForPartitionedRegion index = new LuceneIndexForPartitionedRegion(name, regionPath,
+        cache, null, null, null, null, null, null, executorService);
+    index.setSearchableFields(new String[] {"field"});
     LuceneIndexForPartitionedRegion spy = spy(index);
     doReturn(null).when(spy).createRegion(any(), any(), any(), any(), any(), any());
     doReturn(null).when(spy).createAEQ((RegionAttributes) any(), any());
@@ -353,16 +339,15 @@ public class LuceneIndexForPartitionedRegionTest {
     boolean withPersistence = false;
     String name = "indexName";
     String regionPath = "regionName";
-    String[] fields = new String[]{"field1", "field2"};
+    String[] fields = new String[] {"field1", "field2"};
     InternalCache cache = Fakes.cache();
     initializeScenario(withPersistence, regionPath, cache);
 
     AsyncEventQueue aeq = mock(AsyncEventQueue.class);
     DumpDirectoryFiles function = new DumpDirectoryFiles();
     FunctionService.registerFunction(function);
-    LuceneIndexForPartitionedRegion index =
-        new LuceneIndexForPartitionedRegion(name, regionPath, cache, null, null, null,
-            null, null, null, executorService);
+    LuceneIndexForPartitionedRegion index = new LuceneIndexForPartitionedRegion(name, regionPath,
+        cache, null, null, null, null, null, null, executorService);
     index = spy(index);
     when(index.getFieldNames()).thenReturn(fields);
     doReturn(aeq).when(index).createAEQ(any(), any());
diff --git a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/PartitionedRepositoryManagerJUnitTest.java b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/PartitionedRepositoryManagerJUnitTest.java
index 9fdc10b..ed7305d 100644
--- a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/PartitionedRepositoryManagerJUnitTest.java
+++ b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/PartitionedRepositoryManagerJUnitTest.java
@@ -26,17 +26,23 @@ import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
 import java.io.IOException;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.LinkedHashSet;
 import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.LongAdder;
 
+import org.apache.commons.collections.map.HashedMap;
 import org.apache.lucene.analysis.standard.StandardAnalyzer;
 import org.apache.lucene.index.IndexWriter;
+import org.awaitility.Awaitility;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -84,7 +90,6 @@ public class PartitionedRepositoryManagerJUnitTest {
   protected LuceneSerializer serializer;
   protected PartitionedRegionDataStore userDataStore;
   protected PartitionedRegionDataStore fileDataStore;
-  protected PartitionedRegionHelper prHelper;
   protected PartitionRegionConfig prConfig;
   protected LocalRegion prRoot;
 
@@ -95,6 +100,8 @@ public class PartitionedRepositoryManagerJUnitTest {
   protected LuceneIndexImpl indexForPR;
   protected PartitionedRepositoryManager repoManager;
   protected GemFireCacheImpl cache;
+  private final Map<Integer, Boolean> isIndexAvailableMap = new HashedMap();
+
 
   @Before
   public void setUp() {
@@ -128,7 +135,7 @@ public class PartitionedRepositoryManagerJUnitTest {
     when(fileAndChunkRegion.getRegionIdentifier()).thenReturn("rid");
     indexStats = Mockito.mock(LuceneIndexStats.class);
     fileSystemStats = Mockito.mock(FileSystemStats.class);
-    indexForPR = Mockito.mock(LuceneIndexForPartitionedRegion.class);
+    indexForPR = Mockito.spy(LuceneIndexForPartitionedRegion.class);
     when(((LuceneIndexForPartitionedRegion) indexForPR).getFileAndChunkRegion())
         .thenReturn(fileAndChunkRegion);
     when(((LuceneIndexForPartitionedRegion) indexForPR).getFileSystemStats())
@@ -215,30 +222,50 @@ public class PartitionedRepositoryManagerJUnitTest {
 
     when(fileDataStore.getLocalBucketById(eq(0))).thenReturn(null);
 
-    when(fileAndChunkRegion.getOrCreateNodeForBucketWrite(eq(0), (RetryTimeKeeper) any()))
-        .then(new Answer() {
-          @Override
-          public Object answer(InvocationOnMock invocation) throws Throwable {
-            when(fileDataStore.getLocalBucketById(eq(0))).thenReturn(fileAndChunkBuckets.get(0));
-            return null;
-          }
+    when(fileAndChunkRegion.getOrCreateNodeForBucketWrite(eq(0), any()))
+        .then((Answer) invocation -> {
+          when(fileDataStore.getLocalBucketById(eq(0))).thenReturn(fileAndChunkBuckets.get(0));
+          return null;
         });
 
     assertNotNull(repoManager.getRepository(userRegion, 0, null));
   }
 
+  @Test(expected = LuceneIndexCreationInProgressException.class)
+  public void queryByRegionFailingWithInProgressException()
+      throws LuceneIndexCreationInProgressException, BucketNotFoundException {
+    setUpMockBucket(0);
+    setUpMockBucket(1);
+
+    Set<Integer> buckets = new LinkedHashSet<>(Arrays.asList(0, 1));
+    InternalRegionFunctionContext ctx = Mockito.mock(InternalRegionFunctionContext.class);
+    when(ctx.getLocalBucketSet((any()))).thenReturn(buckets);
+    repoManager.getRepositories(ctx);
+  }
+
   @Test
-  public void getByRegion() throws BucketNotFoundException {
+  public void queryByRegionWaitingForRepoToBeCreated()
+      throws LuceneIndexCreationInProgressException {
     setUpMockBucket(0);
     setUpMockBucket(1);
 
+    setupIsIndexAvailable();
+
     Set<Integer> buckets = new LinkedHashSet<Integer>(Arrays.asList(0, 1));
     InternalRegionFunctionContext ctx = Mockito.mock(InternalRegionFunctionContext.class);
     when(ctx.getLocalBucketSet((any()))).thenReturn(buckets);
-    Collection<IndexRepository> repos = repoManager.getRepositories(ctx);
-    assertEquals(2, repos.size());
+    final Collection<IndexRepository> repositories = new HashSet<>();
 
-    Iterator<IndexRepository> itr = repos.iterator();
+    Awaitility.await().pollDelay(1, TimeUnit.SECONDS).pollInterval(1, TimeUnit.SECONDS)
+        .atMost(500, TimeUnit.SECONDS).until(() -> {
+          try {
+            repositories.addAll(repoManager.getRepositories(ctx));
+          } catch (BucketNotFoundException | LuceneIndexCreationInProgressException e) {
+          }
+          return repositories.size() == 2;
+        });
+
+    Iterator<IndexRepository> itr = repositories.iterator();
     IndexRepositoryImpl repo0 = (IndexRepositoryImpl) itr.next();
     IndexRepositoryImpl repo1 = (IndexRepositoryImpl) itr.next();
 
@@ -248,13 +275,40 @@ public class PartitionedRepositoryManagerJUnitTest {
 
     checkRepository(repo0, 0);
     checkRepository(repo1, 1);
+
+  }
+
+  private void setupIsIndexAvailable() {
+    when(indexForPR.isIndexAvailable(1)).then((Answer) invocation -> {
+      boolean result;
+      Boolean isAvailable = isIndexAvailableMap.get(1);
+      if (isAvailable == null || !isAvailable) {
+        isIndexAvailableMap.put(1, true);
+        result = false;
+      } else {
+        result = true;
+      }
+      return result;
+    });
+    when(indexForPR.isIndexAvailable(0)).then((Answer) invocation -> {
+      boolean result;
+      Boolean isAvailable = isIndexAvailableMap.get(0);
+      if (isAvailable == null || !isAvailable) {
+        isIndexAvailableMap.put(0, true);
+        result = false;
+      } else {
+        result = true;
+      }
+      return result;
+    });
   }
 
   /**
    * Test that we get the expected exception when a user bucket is missing
    */
-  @Test(expected = BucketNotFoundException.class)
-  public void getMissingBucketByRegion() throws BucketNotFoundException {
+  @Test(expected = LuceneIndexCreationInProgressException.class)
+  public void getMissingBucketByRegion()
+      throws LuceneIndexCreationInProgressException, BucketNotFoundException {
     setUpMockBucket(0);
 
     Set<Integer> buckets = new LinkedHashSet<Integer>(Arrays.asList(0, 1));
@@ -272,7 +326,7 @@ public class PartitionedRepositoryManagerJUnitTest {
     assertEquals(serializer, repo0.getSerializer());
   }
 
-  protected BucketRegion setUpMockBucket(int id) throws BucketNotFoundException {
+  protected BucketRegion setUpMockBucket(int id) {
     BucketRegion mockBucket = Mockito.mock(BucketRegion.class);
     BucketRegion fileAndChunkBucket = Mockito.mock(BucketRegion.class);
     // Allowing the fileAndChunkBucket to behave like a map so that the IndexWriter operations don't
@@ -292,6 +346,7 @@ public class PartitionedRepositoryManagerJUnitTest {
     BucketAdvisor mockBucketAdvisor = Mockito.mock(BucketAdvisor.class);
     when(fileAndChunkBucket.getBucketAdvisor()).thenReturn(mockBucketAdvisor);
     when(mockBucketAdvisor.isPrimary()).thenReturn(true);
+
     return mockBucket;
   }
 }
diff --git a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/RawLuceneRepositoryManagerJUnitTest.java b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/RawLuceneRepositoryManagerJUnitTest.java
index a000d2f..57ca3ce 100644
--- a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/RawLuceneRepositoryManagerJUnitTest.java
+++ b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/RawLuceneRepositoryManagerJUnitTest.java
@@ -85,7 +85,7 @@ public class RawLuceneRepositoryManagerJUnitTest extends PartitionedRepositoryMa
   }
 
   @Override
-  protected BucketRegion setUpMockBucket(int id) throws BucketNotFoundException {
+  protected BucketRegion setUpMockBucket(int id) {
     BucketRegion mockBucket = Mockito.mock(BucketRegion.class);
     when(mockBucket.getId()).thenReturn(id);
     when(userRegion.getBucketRegion(eq(id), eq(null))).thenReturn(mockBucket);

-- 
To stop receiving notification emails like this one, please contact
udo@apache.org.