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/03/02 18:23:02 UTC
geode git commit: GEODE-2571 CacheClosedException during
LuceneQueryFunction should be handled with a retry
Repository: geode
Updated Branches:
refs/heads/develop de0dab309 -> 6d263d57a
GEODE-2571 CacheClosedException during LuceneQueryFunction should be handled with a retry
Project: http://git-wip-us.apache.org/repos/asf/geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/6d263d57
Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/6d263d57
Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/6d263d57
Branch: refs/heads/develop
Commit: 6d263d57a26226b59ef0bfb1e01205889d3d1409
Parents: de0dab3
Author: Jason Huynh <hu...@gmail.com>
Authored: Thu Mar 2 09:54:12 2017 -0800
Committer: Jason Huynh <hu...@gmail.com>
Committed: Thu Mar 2 10:22:51 2017 -0800
----------------------------------------------------------------------
.../distributed/LuceneQueryFunction.java | 48 ++++++++++++++------
.../LuceneQueryFunctionJUnitTest.java | 27 ++++++++++-
2 files changed, 58 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/geode/blob/6d263d57/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 dd70480..e3b5297 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
@@ -19,6 +19,7 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
+import org.apache.geode.cache.CacheClosedException;
import org.apache.geode.cache.execute.Function;
import org.apache.geode.cache.lucene.internal.LuceneIndexImpl;
import org.apache.geode.cache.lucene.internal.LuceneIndexStats;
@@ -72,23 +73,11 @@ public class LuceneQueryFunction implements Function, InternalEntity {
throw new IllegalArgumentException("Missing query provider");
}
- LuceneService service = LuceneServiceProvider.get(region.getCache());
- LuceneIndexImpl index =
- (LuceneIndexImpl) service.getIndex(searchContext.getIndexName(), region.getFullPath());
- if (index == null) {
- throw new InternalFunctionInvocationTargetException(
- "Index for Region:" + region.getFullPath() + " was not found");
- }
+ LuceneIndexImpl index = getLuceneIndex(region, searchContext);
RepositoryManager repoManager = index.getRepositoryManager();
LuceneIndexStats stats = index.getIndexStats();
- Query query = null;
- try {
- query = queryProvider.getQuery(index);
- } catch (LuceneQueryException e) {
- logger.warn("", e);
- throw new FunctionException(e);
- }
+ Query query = getQuery(queryProvider, index);
if (logger.isDebugEnabled()) {
logger.debug("Executing lucene query: {}, on region {}", query, region.getFullPath());
@@ -123,12 +112,41 @@ public class LuceneQueryFunction implements Function, InternalEntity {
}
stats.incNumberOfQueryExecuted();
resultSender.lastResult(mergedResult);
- } catch (IOException | BucketNotFoundException e) {
+ } catch (IOException | BucketNotFoundException | CacheClosedException e) {
logger.debug("Exception during lucene query function", e);
throw new InternalFunctionInvocationTargetException(e);
}
}
+ private LuceneIndexImpl getLuceneIndex(final Region region,
+ final LuceneFunctionContext<IndexResultCollector> searchContext) {
+ LuceneService service = LuceneServiceProvider.get(region.getCache());
+ LuceneIndexImpl index = null;
+ try {
+ 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);
+ }
+ if (index == null) {
+ throw new InternalFunctionInvocationTargetException(
+ "Index for Region:" + region.getFullPath() + " was not found");
+ }
+ return index;
+ }
+
+ private Query getQuery(final LuceneQueryProvider queryProvider, final LuceneIndexImpl index) {
+ Query query = null;
+ try {
+ query = queryProvider.getQuery(index);
+ } catch (LuceneQueryException e) {
+ logger.warn("", e);
+ throw new FunctionException(e);
+ }
+ return query;
+ }
+
@Override
public String getId() {
http://git-wip-us.apache.org/repos/asf/geode/blob/6d263d57/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 6a9af9b..18621d5 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
@@ -24,6 +24,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
+import org.apache.geode.cache.CacheClosedException;
import org.apache.geode.cache.Region;
import org.apache.geode.cache.execute.FunctionException;
import org.apache.geode.cache.execute.ResultSender;
@@ -38,6 +39,7 @@ import org.apache.geode.cache.lucene.internal.repository.IndexRepository;
import org.apache.geode.cache.lucene.internal.repository.IndexResultCollector;
import org.apache.geode.cache.lucene.internal.repository.RepositoryManager;
import org.apache.geode.internal.cache.InternalCache;
+import org.apache.geode.internal.cache.execute.InternalFunctionInvocationTargetException;
import org.apache.geode.internal.cache.execute.InternalRegionFunctionContext;
import org.apache.geode.test.junit.categories.UnitTest;
@@ -208,15 +210,36 @@ public class LuceneQueryFunctionJUnitTest {
function.execute(mockContext);
}
- @Test(expected = FunctionException.class)
+ @Test(expected = InternalFunctionInvocationTargetException.class)
public void whenServiceReturnsNullIndexDuringQueryExecutionFunctionExceptionShouldBeThrown()
throws Exception {
when(mockContext.getDataSet()).thenReturn(mockRegion);
when(mockContext.getArguments()).thenReturn(searchArgs);
- LuceneQueryFunction function = new LuceneQueryFunction();
+ 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);
+ when(mockContext.getArguments()).thenReturn(searchArgs);
+ LuceneQueryFunction function = new LuceneQueryFunction();
+ when(mockService.getIndex(eq("indexName"), eq(regionPath)))
+ .thenThrow(new CacheClosedException());
+ function.execute(mockContext);
+ }
+
+ @Test(expected = InternalFunctionInvocationTargetException.class)
+ public void whenCacheIsClosedDuringLuceneQueryExecutionInternalFunctionShouldBeThrownToTriggerFunctionServiceRetry()
+ throws Exception {
+ when(mockContext.getDataSet()).thenReturn(mockRegion);
+ when(mockContext.getArguments()).thenReturn(searchArgs);
+ LuceneQueryFunction function = new LuceneQueryFunction();
+ when(mockRepoManager.getRepositories(eq(mockContext))).thenThrow(new CacheClosedException());
function.execute(mockContext);
}