You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by ja...@apache.org on 2017/04/12 18:43:09 UTC
geode git commit: GEODE-2768: Lucene Queries executed before index is
fully created should be retried
Repository: geode
Updated Branches:
refs/heads/feature/GEODE-2768 [created] 60f5f06f1
GEODE-2768: Lucene Queries executed before index is fully created should be retried
* Added a sleep to prevent rapid retries which lead to stack overflow
* Sleep can be removed when Function Execution retry does not add to stack
Project: http://git-wip-us.apache.org/repos/asf/geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/60f5f06f
Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/60f5f06f
Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/60f5f06f
Branch: refs/heads/feature/GEODE-2768
Commit: 60f5f06f18f8ea6c1d176a43a25bfbb4086e2f21
Parents: 344f93d
Author: Jason Huynh <hu...@gmail.com>
Authored: Wed Apr 12 11:39:28 2017 -0700
Committer: Jason Huynh <hu...@gmail.com>
Committed: Wed Apr 12 11:39:28 2017 -0700
----------------------------------------------------------------------
.../distributed/LuceneQueryFunction.java | 20 ++++++++++++++++++++
.../LuceneQueryFunctionJUnitTest.java | 18 ++++++++++++++++++
2 files changed, 38 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/geode/blob/60f5f06f/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 0bd9046..c2dcf02 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
@@ -25,6 +25,7 @@ import org.apache.geode.cache.lucene.LuceneIndexDestroyedException;
import org.apache.geode.cache.lucene.LuceneIndexNotFoundException;
import org.apache.geode.cache.lucene.internal.LuceneIndexImpl;
import org.apache.geode.cache.lucene.internal.LuceneIndexStats;
+import org.apache.geode.cache.lucene.internal.LuceneServiceImpl;
import org.apache.geode.internal.cache.PrimaryBucketException;
import org.apache.geode.internal.cache.execute.InternalFunctionInvocationTargetException;
import org.apache.logging.log4j.Logger;
@@ -132,6 +133,25 @@ 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
+ try {
+ Thread.sleep(100);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ }
+ throw new InternalFunctionInvocationTargetException(
+ "Defined Lucene Index has not been created");
+ }
+ }
} catch (CacheClosedException e) {
throw new InternalFunctionInvocationTargetException(
"Cache is closed when attempting to retrieve index:" + region.getFullPath(), e);
http://git-wip-us.apache.org/repos/asf/geode/blob/60f5f06f/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 0283ffa..5313ced 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
@@ -33,8 +33,10 @@ import org.apache.geode.cache.lucene.LuceneQueryException;
import org.apache.geode.cache.lucene.LuceneQueryFactory;
import org.apache.geode.cache.lucene.LuceneQueryProvider;
import org.apache.geode.cache.lucene.internal.InternalLuceneService;
+import org.apache.geode.cache.lucene.internal.LuceneIndexCreationProfile;
import org.apache.geode.cache.lucene.internal.LuceneIndexImpl;
import org.apache.geode.cache.lucene.internal.LuceneIndexStats;
+import org.apache.geode.cache.lucene.internal.LuceneServiceImpl;
import org.apache.geode.cache.lucene.internal.StringQueryProvider;
import org.apache.geode.cache.lucene.internal.repository.IndexRepository;
import org.apache.geode.cache.lucene.internal.repository.IndexResultCollector;
@@ -223,6 +225,22 @@ public class LuceneQueryFunctionJUnitTest {
}
@Test(expected = InternalFunctionInvocationTargetException.class)
+ public void whenServiceReturnsNullIndexButHasDefinedLuceneIndexDuringQueryExecutionInternalFunctionExceptionShouldBeThrown()
+ 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(mockContext.getDataSet()).thenReturn(mockRegion);
+ when(mockContext.getArguments()).thenReturn(searchArgs);
+
+ LuceneQueryFunction function = new LuceneQueryFunction();
+ when(mockService.getIndex(eq("indexName"), eq(regionPath))).thenReturn(null);
+ function.execute(mockContext);
+ }
+
+ @Test(expected = InternalFunctionInvocationTargetException.class)
public void whenServiceThrowsCacheClosedDuringQueryExecutionFunctionExceptionShouldBeThrown()
throws Exception {
when(mockContext.getDataSet()).thenReturn(mockRegion);