geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kl...@apache.org
Subject [21/32] geode git commit: GEODE-2410: Lucene afterPrimary and afterSecondary calls pass through the same crit section.
Date Fri, 03 Feb 2017 18:35:50 GMT
GEODE-2410: Lucene afterPrimary and afterSecondary calls pass through the same crit section.

	* afterPrimary and afterSecondary calls are passed through the same critical section.
	* If the caller is primary bucket, it will try to acquire a Dlock on the bucket and create
the index repo.
	* If it is secondary it will clean up the repo - close the writer and release the locks.
	* If the primary changes to secondary while waiting for indexes to be created, it will exit
from the critical section without acquiring the lock.


Project: http://git-wip-us.apache.org/repos/asf/geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/d2a626e9
Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/d2a626e9
Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/d2a626e9

Branch: refs/heads/feature/GEODE-1930-2
Commit: d2a626e9cecb4d9a1b3599201a379eefe0dc8556
Parents: 868fcc8
Author: nabarun <nnag@pivotal.io>
Authored: Thu Feb 2 15:06:38 2017 -0800
Committer: nabarun <nnag@pivotal.io>
Committed: Thu Feb 2 15:06:38 2017 -0800

----------------------------------------------------------------------
 .../AbstractPartitionedRepositoryManager.java   | 32 +++++---------
 .../lucene/internal/IndexRepositoryFactory.java | 46 ++++++++++++++------
 .../lucene/internal/LuceneBucketListener.java   |  6 +--
 .../cache/lucene/internal/LuceneQueryImpl.java  | 31 +++++--------
 .../internal/PartitionedRepositoryManager.java  |  8 ++--
 .../internal/RawIndexRepositoryFactory.java     | 10 +++--
 .../internal/RawLuceneRepositoryManager.java    | 11 ++---
 .../internal/directory/RegionDirectory.java     |  1 +
 .../internal/distributed/LuceneFunction.java    |  3 +-
 .../PartitionedRepositoryManagerJUnitTest.java  | 18 +++++---
 .../RawLuceneRepositoryManagerJUnitTest.java    | 41 ++++++++++++-----
 .../directory/RegionDirectoryJUnitTest.java     |  7 +++
 .../cache/lucene/test/IndexRepositorySpy.java   | 12 ++---
 13 files changed, 132 insertions(+), 94 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/d2a626e9/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/AbstractPartitionedRepositoryManager.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/AbstractPartitionedRepositoryManager.java
b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/AbstractPartitionedRepositoryManager.java
index 9e055f0..f64ca82 100755
--- a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/AbstractPartitionedRepositoryManager.java
+++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/AbstractPartitionedRepositoryManager.java
@@ -18,10 +18,7 @@ import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Set;
-import java.util.concurrent.Callable;
 import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.Future;
-import java.util.concurrent.FutureTask;
 
 import org.apache.geode.InternalGemFireError;
 import org.apache.geode.cache.Region;
@@ -90,21 +87,14 @@ public abstract class AbstractPartitionedRepositoryManager implements
Repository
     return repos;
   }
 
-  public abstract IndexRepository createOneIndexRepository(final Integer bucketId,
-      LuceneSerializer serializer, LuceneIndexImpl index, PartitionedRegion userRegion)
-      throws IOException;
+  public abstract IndexRepository computeRepository(final Integer bucketId,
+      LuceneSerializer serializer, LuceneIndexImpl index, PartitionedRegion userRegion,
+      IndexRepository oldRepository) throws IOException;
 
-  protected IndexRepository createRepository(Integer bucketId) throws BucketNotFoundException
{
+  protected IndexRepository computeRepository(Integer bucketId) throws BucketNotFoundException
{
     IndexRepository repo = indexRepositories.compute(bucketId, (key, oldRepository) ->
{
-      if (oldRepository != null && !oldRepository.isClosed()) {
-        return oldRepository;
-      }
-      if (oldRepository != null) {
-        oldRepository.cleanup();
-      }
-
       try {
-        return createOneIndexRepository(bucketId, serializer, index, userRegion);
+        return computeRepository(bucketId, serializer, index, userRegion, oldRepository);
       } catch (IOException e) {
         throw new InternalGemFireError("Unable to create index repository", e);
       }
@@ -122,14 +112,12 @@ public abstract class AbstractPartitionedRepositoryManager implements
Repository
       return repo;
     }
 
-    throw new BucketNotFoundException(
-        "Colocated index buckets not found for bucket id " + bucketId);
-  }
+    repo = computeRepository(bucketId);
 
-  protected void cleanRepository(Integer bucketId) throws BucketNotFoundException {
-    IndexRepository repo = indexRepositories.remove(bucketId);
-    if (repo != null) {
-      repo.cleanup();
+    if (repo == null) {
+      throw new BucketNotFoundException(
+          "Unable to create lucene index because no longer primary for bucket " + bucketId);
     }
+    return repo;
   }
 }

http://git-wip-us.apache.org/repos/asf/geode/blob/d2a626e9/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/IndexRepositoryFactory.java
----------------------------------------------------------------------
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 5be17e3..2b244e7 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
@@ -40,27 +40,40 @@ public class IndexRepositoryFactory {
 
   public IndexRepositoryFactory() {}
 
-  public IndexRepository createIndexRepository(final Integer bucketId, LuceneSerializer serializer,
-      LuceneIndexImpl index, PartitionedRegion userRegion) throws IOException {
-    final IndexRepository repo;
+  public IndexRepository computeIndexRepository(final Integer bucketId, LuceneSerializer
serializer,
+      LuceneIndexImpl index, PartitionedRegion userRegion, final IndexRepository oldRepository)
+      throws IOException {
     LuceneIndexForPartitionedRegion indexForPR = (LuceneIndexForPartitionedRegion) index;
     BucketRegion fileBucket = getMatchingBucket(indexForPR.getFileRegion(), bucketId);
     BucketRegion chunkBucket = getMatchingBucket(indexForPR.getChunkRegion(), bucketId);
     BucketRegion dataBucket = getMatchingBucket(userRegion, bucketId);
     boolean success = false;
     if (fileBucket == null || chunkBucket == null) {
+      oldRepository.cleanup();
       return null;
     }
     if (!fileBucket.getBucketAdvisor().isPrimary()) {
-      throw new IOException("Not creating the index because we are not the primary");
+      oldRepository.cleanup();
+      return null;
+    }
+
+    if (oldRepository != null && !oldRepository.isClosed()) {
+      return oldRepository;
     }
-    DistributedLockService lockService =
-        DistributedLockService.getServiceNamed(PartitionedRegionHelper.PARTITION_LOCK_SERVICE_NAME);
-    String lockName = FILE_REGION_LOCK_FOR_BUCKET_ID + fileBucket.getFullPath() + bucketId;
-    if (lockService != null) {
-      // lockService will be null for testing at this point
-      lockService.lock(lockName, -1, -1);
+
+    if (oldRepository != null && oldRepository.isClosed()) {
+      oldRepository.cleanup();
+    }
+    DistributedLockService lockService = getLockService();
+    String lockName = getLockName(bucketId, fileBucket);
+    while (!lockService.lock(lockName, 100, -1)) {
+      if (!fileBucket.getBucketAdvisor().isPrimary()) {
+        return null;
+      }
     }
+
+
+    final IndexRepository repo;
     try {
       RegionDirectory dir =
           new RegionDirectory(fileBucket, chunkBucket, indexForPR.getFileSystemStats());
@@ -72,14 +85,21 @@ public class IndexRepositoryFactory {
       return repo;
     } finally {
       if (!success) {
-        if (lockService != null) {
-          lockService.unlock(lockName);
-        }
+        lockService.unlock(lockName);
       }
     }
 
   }
 
+  private String getLockName(final Integer bucketId, final BucketRegion fileBucket) {
+    return FILE_REGION_LOCK_FOR_BUCKET_ID + fileBucket.getFullPath() + bucketId;
+  }
+
+  private DistributedLockService getLockService() {
+    return DistributedLockService
+        .getServiceNamed(PartitionedRegionHelper.PARTITION_LOCK_SERVICE_NAME);
+  }
+
   /**
    * Find the bucket in region2 that matches the bucket id from region1.
    */

http://git-wip-us.apache.org/repos/asf/geode/blob/d2a626e9/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneBucketListener.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneBucketListener.java
b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneBucketListener.java
index da0c2c2..0af2719 100644
--- a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneBucketListener.java
+++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneBucketListener.java
@@ -14,8 +14,6 @@
  */
 package org.apache.geode.cache.lucene.internal;
 
-import org.apache.geode.GemFireException;
-import org.apache.geode.cache.execute.FunctionException;
 import org.apache.geode.cache.partition.PartitionListenerAdapter;
 import org.apache.geode.distributed.internal.DM;
 import org.apache.geode.internal.cache.BucketNotFoundException;
@@ -37,7 +35,7 @@ public class LuceneBucketListener extends PartitionListenerAdapter {
   public void afterPrimary(int bucketId) {
     dm.getWaitingThreadPool().execute(() -> {
       try {
-        lucenePartitionRepositoryManager.createRepository(bucketId);
+        lucenePartitionRepositoryManager.computeRepository(bucketId);
       } catch (BucketNotFoundException e) {
         logger.warn(
             "Index repository could not be created when index chunk region bucket became
primary. "
@@ -54,7 +52,7 @@ public class LuceneBucketListener extends PartitionListenerAdapter {
   public void afterSecondary(int bucketId) {
     dm.getWaitingThreadPool().execute(() -> {
       try {
-        lucenePartitionRepositoryManager.cleanRepository(bucketId);
+        lucenePartitionRepositoryManager.computeRepository(bucketId);
       } catch (Exception e) {
         logger.warn("Exception while cleaning up Lucene Index Repository", e);
       }

http://git-wip-us.apache.org/repos/asf/geode/blob/d2a626e9/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneQueryImpl.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneQueryImpl.java
b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneQueryImpl.java
index 0e8bb37..4ac987d 100644
--- a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneQueryImpl.java
+++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/LuceneQueryImpl.java
@@ -44,7 +44,6 @@ import org.apache.logging.log4j.Logger;
 
 public class LuceneQueryImpl<K, V> implements LuceneQuery<K, V> {
   Logger logger = LogService.getLogger();
-  private final static int MAX_TRIES = 500;
 
   private int limit = LuceneQueryFactory.DEFAULT_LIMIT;
   private int pageSize = LuceneQueryFactory.DEFAULT_PAGESIZE;
@@ -108,24 +107,18 @@ public class LuceneQueryImpl<K, V> implements LuceneQuery<K,
V> {
 
     // TODO provide a timeout to the user?
     TopEntries<K> entries = null;
-    int numTries = 0;
-    while (entries == null && numTries++ < MAX_TRIES) {
-      try {
-        TopEntriesFunctionCollector collector = new TopEntriesFunctionCollector(context);
-        ResultCollector<TopEntriesCollector, TopEntries<K>> rc =
-            (ResultCollector<TopEntriesCollector, TopEntries<K>>) onRegion().withArgs(context)
-                .withCollector(collector).execute(LuceneFunction.ID);
-        entries = rc.getResult();
-      } catch (FunctionException e) {
-        if (e.getCause() instanceof LuceneQueryException) {
-          throw new LuceneQueryException(e);
-        } else if (e.getCause() instanceof BucketNotFoundException) {
-          logger.debug("Retrying due to index on bucket not found:" + e);
-          // throw e;
-        } else {
-          e.printStackTrace();
-          throw e;
-        }
+    try {
+      TopEntriesFunctionCollector collector = new TopEntriesFunctionCollector(context);
+      ResultCollector<TopEntriesCollector, TopEntries<K>> rc =
+          (ResultCollector<TopEntriesCollector, TopEntries<K>>) onRegion().withArgs(context)
+              .withCollector(collector).execute(LuceneFunction.ID);
+      entries = rc.getResult();
+    } catch (FunctionException e) {
+      if (e.getCause() instanceof LuceneQueryException) {
+        throw new LuceneQueryException(e);
+      } else {
+        e.printStackTrace();
+        throw e;
       }
     }
     return entries;

http://git-wip-us.apache.org/repos/asf/geode/blob/d2a626e9/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/PartitionedRepositoryManager.java
----------------------------------------------------------------------
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 2f87218..7494e15 100644
--- 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
@@ -36,8 +36,10 @@ public class PartitionedRepositoryManager extends AbstractPartitionedRepositoryM
   }
 
   @Override
-  public IndexRepository createOneIndexRepository(Integer bucketId, LuceneSerializer serializer,
-      LuceneIndexImpl index, PartitionedRegion userRegion) throws IOException {
-    return indexRepositoryFactory.createIndexRepository(bucketId, serializer, index, userRegion);
+  public IndexRepository computeRepository(Integer bucketId, LuceneSerializer serializer,
+      LuceneIndexImpl index, PartitionedRegion userRegion, IndexRepository oldRepository)
+      throws IOException {
+    return indexRepositoryFactory.computeIndexRepository(bucketId, serializer, index, userRegion,
+        oldRepository);
   }
 }

http://git-wip-us.apache.org/repos/asf/geode/blob/d2a626e9/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/RawIndexRepositoryFactory.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/RawIndexRepositoryFactory.java
b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/RawIndexRepositoryFactory.java
index 2f61913..b960935 100755
--- a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/RawIndexRepositoryFactory.java
+++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/RawIndexRepositoryFactory.java
@@ -33,12 +33,16 @@ import org.apache.geode.internal.cache.PartitionedRegion;
 public class RawIndexRepositoryFactory extends IndexRepositoryFactory {
   public RawIndexRepositoryFactory() {}
 
-  public IndexRepository createIndexRepository(final Integer bucketId, LuceneSerializer serializer,
-      LuceneIndexImpl index, PartitionedRegion userRegion) throws IOException {
+  @Override
+  public IndexRepository computeIndexRepository(final Integer bucketId, LuceneSerializer
serializer,
+      LuceneIndexImpl index, PartitionedRegion userRegion, IndexRepository oldRepository)
+      throws IOException {
     final IndexRepository repo;
+    if (oldRepository != null) {
+      oldRepository.cleanup();
+    }
     LuceneRawIndex indexForRaw = (LuceneRawIndex) index;
     BucketRegion dataBucket = getMatchingBucket(userRegion, bucketId);
-
     Directory dir = null;
     if (indexForRaw.withPersistence()) {
       String bucketLocation = LuceneServiceImpl.getUniqueIndexName(index.getName(),

http://git-wip-us.apache.org/repos/asf/geode/blob/d2a626e9/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/RawLuceneRepositoryManager.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/RawLuceneRepositoryManager.java
b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/RawLuceneRepositoryManager.java
index b503692..c31f19c 100755
--- a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/RawLuceneRepositoryManager.java
+++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/RawLuceneRepositoryManager.java
@@ -16,7 +16,6 @@ package org.apache.geode.cache.lucene.internal;
 
 import java.io.IOException;
 
-import org.apache.geode.cache.Region;
 import org.apache.geode.cache.lucene.internal.repository.IndexRepository;
 import org.apache.geode.cache.lucene.internal.repository.serializer.LuceneSerializer;
 import org.apache.geode.internal.cache.BucketNotFoundException;
@@ -43,7 +42,7 @@ public class RawLuceneRepositoryManager extends AbstractPartitionedRepositoryMan
     }
 
     try {
-      repo = createOneIndexRepository(bucketId, this.serializer, this.index, this.userRegion);
+      repo = computeRepository(bucketId, this.serializer, this.index, this.userRegion, repo);
       return repo;
     } catch (IOException e) {
       e.printStackTrace();
@@ -54,8 +53,10 @@ public class RawLuceneRepositoryManager extends AbstractPartitionedRepositoryMan
   }
 
   @Override
-  public IndexRepository createOneIndexRepository(Integer bucketId, LuceneSerializer serializer,
-      LuceneIndexImpl index, PartitionedRegion userRegion) throws IOException {
-    return indexRepositoryFactory.createIndexRepository(bucketId, serializer, index, userRegion);
+  public IndexRepository computeRepository(Integer bucketId, LuceneSerializer serializer,
+      LuceneIndexImpl index, PartitionedRegion userRegion, IndexRepository oldRepository)
+      throws IOException {
+    return indexRepositoryFactory.computeIndexRepository(bucketId, serializer, index, userRegion,
+        oldRepository);
   }
 }

http://git-wip-us.apache.org/repos/asf/geode/blob/d2a626e9/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/directory/RegionDirectory.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/directory/RegionDirectory.java
b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/directory/RegionDirectory.java
index e43b60b..f1af7f3 100644
--- a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/directory/RegionDirectory.java
+++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/directory/RegionDirectory.java
@@ -15,6 +15,7 @@
 
 package org.apache.geode.cache.lucene.internal.directory;
 
+import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.util.Arrays;

http://git-wip-us.apache.org/repos/asf/geode/blob/d2a626e9/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/distributed/LuceneFunction.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/distributed/LuceneFunction.java
b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/distributed/LuceneFunction.java
index 5271a2f..fd908de 100644
--- a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/distributed/LuceneFunction.java
+++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/distributed/LuceneFunction.java
@@ -19,6 +19,7 @@ import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collection;
 
+import org.apache.geode.cache.execute.Function;
 import org.apache.geode.cache.lucene.internal.LuceneIndexImpl;
 import org.apache.geode.cache.lucene.internal.LuceneIndexStats;
 import org.apache.logging.log4j.Logger;
@@ -46,7 +47,7 @@ import org.apache.geode.internal.logging.LogService;
  * the coordinator and arguments like region and buckets. It invokes search on the local
index and
  * provides a result collector. The locally collected results are sent to the search coordinator.
  */
-public class LuceneFunction extends FunctionAdapter implements InternalEntity {
+public class LuceneFunction implements Function, InternalEntity {
   private static final long serialVersionUID = 1L;
   public static final String ID = LuceneFunction.class.getName();
 

http://git-wip-us.apache.org/repos/asf/geode/blob/d2a626e9/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/PartitionedRepositoryManagerJUnitTest.java
----------------------------------------------------------------------
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 1c47e89..7890903 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
@@ -16,6 +16,7 @@ package org.apache.geode.cache.lucene.internal;
 
 import static org.junit.Assert.*;
 import static org.mockito.Matchers.*;
+import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
 import java.io.IOException;
@@ -28,10 +29,12 @@ import java.util.Map;
 import java.util.Set;
 
 import org.apache.geode.distributed.DistributedLockService;
+import org.apache.geode.distributed.internal.locks.DLockService;
 import org.apache.geode.internal.cache.BucketAdvisor;
-import org.apache.geode.internal.cache.partitioned.Bucket;
+import org.apache.geode.internal.cache.PartitionedRegionHelper;
 import org.apache.lucene.analysis.standard.StandardAnalyzer;
 import org.apache.lucene.index.IndexWriter;
+import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
@@ -83,10 +86,18 @@ public class PartitionedRepositoryManagerJUnitTest {
     when(userRegion.getDataStore()).thenReturn(userDataStore);
     when(cache.getRegion("/testRegion")).thenReturn(userRegion);
     serializer = new HeterogeneousLuceneSerializer(new String[] {"a", "b"});
-
+    DLockService lockService = mock(DLockService.class);
+    when(lockService.lock(any(), anyLong(), anyLong())).thenReturn(true);
+    DLockService.addLockServiceForTests(PartitionedRegionHelper.PARTITION_LOCK_SERVICE_NAME,
+        lockService);
     createIndexAndRepoManager();
   }
 
+  @After
+  public void tearDown() {
+    DLockService.removeLockServiceForTests(PartitionedRegionHelper.PARTITION_LOCK_SERVICE_NAME);
+  }
+
   protected void createIndexAndRepoManager() {
     fileRegion = Mockito.mock(PartitionedRegion.class);
     fileDataStore = Mockito.mock(PartitionedRegionDataStore.class);
@@ -250,11 +261,8 @@ public class PartitionedRepositoryManagerJUnitTest {
     dataBuckets.put(id, mockBucket);
 
     BucketAdvisor mockBucketAdvisor = Mockito.mock(BucketAdvisor.class);
-    DistributedLockService lockService = Mockito.mock(DistributedLockService.class);
-    when(fileBucket.getLockService()).thenReturn(lockService);
     when(fileBucket.getBucketAdvisor()).thenReturn(mockBucketAdvisor);
     when(mockBucketAdvisor.isPrimary()).thenReturn(true);
-    repoManager.createRepository(mockBucket.getId());
     return mockBucket;
   }
 }

http://git-wip-us.apache.org/repos/asf/geode/blob/d2a626e9/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/RawLuceneRepositoryManagerJUnitTest.java
----------------------------------------------------------------------
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 a9fb52b..bca7085 100755
--- 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
@@ -15,34 +15,53 @@
 package org.apache.geode.cache.lucene.internal;
 
 import static org.junit.Assert.*;
+import static org.mockito.Matchers.anyLong;
+import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.eq;
 
-import org.apache.geode.distributed.DistributedLockService;
-import org.apache.geode.internal.cache.BucketAdvisor;
+import org.apache.geode.cache.lucene.internal.repository.serializer.HeterogeneousLuceneSerializer;
+import org.apache.geode.distributed.internal.locks.DLockService;
+import org.apache.geode.internal.cache.GemFireCacheImpl;
+import org.apache.geode.internal.cache.PartitionedRegion;
+import org.apache.geode.internal.cache.PartitionedRegionDataStore;
+import org.apache.geode.internal.cache.PartitionedRegionHelper;
+import org.apache.geode.test.fake.Fakes;
+import org.apache.geode.test.junit.rules.DiskDirRule;
 import org.apache.lucene.analysis.standard.StandardAnalyzer;
 import org.apache.lucene.index.IndexWriter;
 import org.apache.lucene.store.Directory;
 import org.apache.lucene.store.NIOFSDirectory;
-import org.apache.lucene.store.RAMDirectory;
 import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
 import org.mockito.Mockito;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
 
-import org.apache.geode.cache.lucene.internal.directory.RegionDirectory;
-import org.apache.geode.cache.lucene.internal.filesystem.FileSystemStats;
 import org.apache.geode.cache.lucene.internal.repository.IndexRepositoryImpl;
 import org.apache.geode.internal.cache.BucketNotFoundException;
 import org.apache.geode.internal.cache.BucketRegion;
-import org.apache.geode.internal.cache.PartitionedRegion;
-import org.apache.geode.internal.cache.PartitionedRegionDataStore;
-import org.apache.geode.internal.cache.PartitionedRegion.RetryTimeKeeper;
+
+import java.io.File;
 
 public class RawLuceneRepositoryManagerJUnitTest extends PartitionedRepositoryManagerJUnitTest
{
 
+  @Rule
+  public DiskDirRule diskDirRule = new DiskDirRule();
+
+  @Before
+  public void setUp() {
+    cache = Fakes.cache();
+
+    userRegion = Mockito.mock(PartitionedRegion.class);
+    userDataStore = Mockito.mock(PartitionedRegionDataStore.class);
+    when(userRegion.getDataStore()).thenReturn(userDataStore);
+    when(cache.getRegion("/testRegion")).thenReturn(userRegion);
+    serializer = new HeterogeneousLuceneSerializer(new String[] {"a", "b"});
+    createIndexAndRepoManager();
+  }
+
   @After
   public void tearDown() {
     ((RawLuceneRepositoryManager) repoManager).close();
@@ -84,7 +103,7 @@ public class RawLuceneRepositoryManagerJUnitTest extends PartitionedRepositoryMa
     when(userDataStore.getLocalBucketById(eq(id + 113))).thenReturn(mockBucket);
     dataBuckets.put(id, mockBucket);
 
-    repoManager.createRepository(mockBucket.getId());
+    repoManager.computeRepository(mockBucket.getId());
     return mockBucket;
   }
 

http://git-wip-us.apache.org/repos/asf/geode/blob/d2a626e9/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/directory/RegionDirectoryJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/directory/RegionDirectoryJUnitTest.java
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/directory/RegionDirectoryJUnitTest.java
index 4204204..32249e4 100644
--- a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/directory/RegionDirectoryJUnitTest.java
+++ b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/directory/RegionDirectoryJUnitTest.java
@@ -14,15 +14,22 @@
  */
 package org.apache.geode.cache.lucene.internal.directory;
 
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyLong;
 import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
 
 import java.io.IOException;
 import java.nio.file.Path;
 import java.util.concurrent.ConcurrentHashMap;
 
 import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule;
+import org.apache.geode.distributed.internal.locks.DLockService;
+import org.apache.geode.internal.cache.PartitionedRegionHelper;
 import org.apache.lucene.store.BaseDirectoryTestCase;
 import org.apache.lucene.store.Directory;
+import org.junit.After;
+import org.junit.Before;
 import org.junit.Rule;
 import org.junit.experimental.categories.Category;
 

http://git-wip-us.apache.org/repos/asf/geode/blob/d2a626e9/geode-lucene/src/test/java/org/apache/geode/cache/lucene/test/IndexRepositorySpy.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/test/IndexRepositorySpy.java
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/test/IndexRepositorySpy.java
index d3b1f2f..d363903 100644
--- a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/test/IndexRepositorySpy.java
+++ b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/test/IndexRepositorySpy.java
@@ -23,17 +23,12 @@ import java.util.function.Consumer;
 import org.apache.geode.cache.lucene.internal.IndexRepositoryFactory;
 import org.apache.geode.cache.lucene.internal.LuceneIndexForPartitionedRegion;
 import org.apache.geode.cache.lucene.internal.LuceneIndexImpl;
-import org.apache.geode.cache.lucene.internal.LuceneIndexStats;
 import org.apache.geode.cache.lucene.internal.PartitionedRepositoryManager;
-import org.apache.geode.cache.lucene.internal.filesystem.FileSystemStats;
 import org.apache.geode.cache.lucene.internal.repository.IndexRepository;
 import org.apache.geode.cache.lucene.internal.repository.serializer.LuceneSerializer;
-import org.apache.geode.internal.cache.BucketRegion;
 import org.apache.geode.internal.cache.PartitionedRegion;
 
-import org.apache.lucene.analysis.Analyzer;
 import org.mockito.Mockito;
-import org.mockito.invocation.InvocationOnMock;
 import org.mockito.stubbing.Answer;
 
 public class IndexRepositorySpy extends IndexRepositoryFactory {
@@ -54,11 +49,12 @@ public class IndexRepositorySpy extends IndexRepositoryFactory {
   private IndexRepositorySpy() {}
 
   @Override
-  public IndexRepository createIndexRepository(final Integer bucketId, LuceneSerializer serializer,
-      LuceneIndexImpl index, PartitionedRegion userRegion) throws IOException {
+  public IndexRepository computeIndexRepository(final Integer bucketId, LuceneSerializer
serializer,
+      LuceneIndexImpl index, PartitionedRegion userRegion, IndexRepository oldRepository)
+      throws IOException {
     LuceneIndexForPartitionedRegion indexForPR = (LuceneIndexForPartitionedRegion) index;
     final IndexRepository indexRepo =
-        super.createIndexRepository(bucketId, serializer, index, userRegion);
+        super.computeIndexRepository(bucketId, serializer, index, userRegion, oldRepository);
     final IndexRepository spy = Mockito.spy(indexRepo);
 
     Answer invokeBeforeWrite = invocation -> {


Mime
View raw message