geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jasonhu...@apache.org
Subject geode git commit: GEODE-2825: Lucene query function will wait until index is returned if an index is defined
Date Tue, 02 May 2017 23:32:39 GMT
Repository: geode
Updated Branches:
  refs/heads/develop b81ebcb19 -> ecbf55769


GEODE-2825: Lucene query function will wait until index is returned if an index is defined

  * If an index is in a defined state but not yet created, the query will now wait
    until the index is created or no longer defined.  Instead of throwing an
    exception and possibly getting a stack overflow


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

Branch: refs/heads/develop
Commit: ecbf55769c1aa04b173e39f719565e03820ac8f2
Parents: b81ebcb
Author: Jason Huynh <huynhja@gmail.com>
Authored: Tue May 2 16:31:59 2017 -0700
Committer: Jason Huynh <huynhja@gmail.com>
Committed: Tue May 2 16:31:59 2017 -0700

----------------------------------------------------------------------
 .../distributed/LuceneQueryFunction.java        | 24 +++++-------
 .../LuceneQueryFunctionJUnitTest.java           | 41 ++++++++++++++++----
 2 files changed, 44 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/ecbf5576/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/distributed/LuceneQueryFunction.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/distributed/LuceneQueryFunction.java
b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/distributed/LuceneQueryFunction.java
index 9ad69ac..b60652f 100644
--- a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/distributed/LuceneQueryFunction.java
+++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/distributed/LuceneQueryFunction.java
@@ -133,29 +133,24 @@ public class LuceneQueryFunction implements Function, InternalEntity
{
     try {
       index =
           (LuceneIndexImpl) service.getIndex(searchContext.getIndexName(), region.getFullPath());
-      if (index == null && service instanceof LuceneServiceImpl) {
-        if (((LuceneServiceImpl) service).getDefinedIndex(searchContext.getIndexName(),
-            region.getFullPath()) != null) {
-          // The node may be in the process of recovering, where we have the index defined
but yet
-          // to be recovered
-          // If we retry fast enough, we could get a stack overflow based on the way function
-          // execution is currently written
-          // Instead we will add an artificial sleep to slow down the retry at this point
-          // Hopefully in the future, the function execution would retry without adding to
the stack
-          // and this can be removed
+      if (index == null) {
+        while (service instanceof LuceneServiceImpl && (((LuceneServiceImpl) service)
+            .getDefinedIndex(searchContext.getIndexName(), region.getFullPath()) != null))
{
           try {
-            Thread.sleep(1000);
+            Thread.sleep(10);
           } catch (InterruptedException e) {
-            Thread.currentThread().interrupt();
+            return null;
           }
-          throw new InternalFunctionInvocationTargetException(
-              "Defined Lucene Index has not been created");
+          region.getCache().getCancelCriterion().checkCancelInProgress(null);
         }
+        index =
+            (LuceneIndexImpl) service.getIndex(searchContext.getIndexName(), region.getFullPath());
       }
     } catch (CacheClosedException e) {
       throw new InternalFunctionInvocationTargetException(
           "Cache is closed when attempting to retrieve index:" + region.getFullPath(), e);
     }
+
     return index;
   }
 
@@ -181,3 +176,4 @@ public class LuceneQueryFunction implements Function, InternalEntity {
     return true;
   }
 }
+

http://git-wip-us.apache.org/repos/asf/geode/blob/ecbf5576/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/distributed/LuceneQueryFunctionJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/distributed/LuceneQueryFunctionJUnitTest.java
b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/distributed/LuceneQueryFunctionJUnitTest.java
index 6690850..737805b 100644
--- a/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/distributed/LuceneQueryFunctionJUnitTest.java
+++ b/geode-lucene/src/test/java/org/apache/geode/cache/lucene/internal/distributed/LuceneQueryFunctionJUnitTest.java
@@ -23,6 +23,7 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
 
+import org.apache.geode.CancelCriterion;
 import org.apache.geode.cache.CacheClosedException;
 import org.apache.geode.cache.Region;
 import org.apache.geode.cache.execute.FunctionException;
@@ -54,6 +55,8 @@ import org.junit.Test;
 import org.junit.experimental.categories.Category;
 import org.mockito.ArgumentCaptor;
 import org.mockito.Mockito;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
 
 @Category(UnitTest.class)
 public class LuceneQueryFunctionJUnitTest {
@@ -224,19 +227,42 @@ public class LuceneQueryFunctionJUnitTest {
     function.execute(mockContext);
   }
 
-  @Test(expected = InternalFunctionInvocationTargetException.class)
-  public void whenServiceReturnsNullIndexButHasDefinedLuceneIndexDuringQueryExecutionInternalFunctionExceptionShouldBeThrown()
+  @Test
+  public void whenServiceReturnsNullIndexButHasDefinedLuceneIndexDuringQueryExecutionShouldBlockUntilAvailable()
       throws Exception {
     LuceneServiceImpl mockServiceImpl = mock(LuceneServiceImpl.class);
     when(mockCache.getService(any())).thenReturn(mockServiceImpl);
-    when(mockServiceImpl.getIndex(eq("indexName"), eq(regionPath))).thenReturn(null);
-    when(mockServiceImpl.getDefinedIndex(eq("indexName"), eq(regionPath)))
-        .thenReturn(mock(LuceneIndexCreationProfile.class));
+    when(mockServiceImpl.getIndex(eq("indexName"), eq(regionPath))).thenAnswer(new Answer()
{
+      private boolean calledFirstTime = false;
+
+      @Override
+      public Object answer(final InvocationOnMock invocation) throws Throwable {
+        if (calledFirstTime == false) {
+          calledFirstTime = true;
+          return null;
+        } else {
+          return mockIndex;
+        }
+      }
+    });
+    when(mockServiceImpl.getDefinedIndex(eq("indexName"), eq(regionPath))).thenAnswer(new
Answer() {
+      private int count = 10;
+
+      @Override
+      public Object answer(final InvocationOnMock invocation) throws Throwable {
+        if (count-- > 0) {
+          return mock(LuceneIndexCreationProfile.class);
+        }
+        return null;
+      }
+    });
     when(mockContext.getDataSet()).thenReturn(mockRegion);
     when(mockContext.getArguments()).thenReturn(searchArgs);
-
+    when(mockContext.<TopEntriesCollector>getResultSender()).thenReturn(mockResultSender);
+    CancelCriterion mockCancelCriterion = mock(CancelCriterion.class);
+    when(mockCache.getCancelCriterion()).thenReturn(mockCancelCriterion);
+    when(mockCancelCriterion.isCancelInProgress()).thenReturn(false);
     LuceneQueryFunction function = new LuceneQueryFunction();
-    when(mockService.getIndex(eq("indexName"), eq(regionPath))).thenReturn(null);
     function.execute(mockContext);
   }
 
@@ -336,3 +362,4 @@ public class LuceneQueryFunctionJUnitTest {
     query = queryProvider.getQuery(mockIndex);
   }
 }
+


Mime
View raw message