geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject geode git commit: GEODE-2619: Lucene APIs unwrap function exception and throw the cause.
Date Wed, 29 Mar 2017 21:04:49 GMT
Repository: geode
Updated Branches:
  refs/heads/develop 0302d9c41 -> f3a2ef4c8


GEODE-2619: Lucene APIs unwrap function exception and throw the cause.

	* This is done so that users do not encounter Function Exceptions while executing Lucene
APIs.

	This closes #434


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

Branch: refs/heads/develop
Commit: f3a2ef4c85adc5dcfbdfc9ea5906f1bfefa6011a
Parents: 0302d9c
Author: nabarun <nnag@pivotal.io>
Authored: Tue Mar 28 00:16:44 2017 -0700
Committer: nabarun <nnag@pivotal.io>
Committed: Wed Mar 29 14:03:52 2017 -0700

----------------------------------------------------------------------
 .../cache/lucene/internal/LuceneQueryImpl.java  |  6 ++--
 .../PageableLuceneQueryResultsImpl.java         | 34 ++++++++++++--------
 .../internal/results/LuceneGetPageFunction.java | 28 +++++++++-------
 3 files changed, 41 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/f3a2ef4c/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 1ece774..9bdc935 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
@@ -117,10 +117,10 @@ public class LuceneQueryImpl<K, V> implements LuceneQuery<K,
V> {
     } catch (FunctionException e) {
       if (e.getCause() instanceof LuceneQueryException) {
         throw new LuceneQueryException(e);
-      } else {
-        e.printStackTrace();
-        throw e;
+      } else if (e.getCause() instanceof RuntimeException) {
+        throw (RuntimeException) e.getCause();
       }
+      throw e;
 
     }
     return entries;

http://git-wip-us.apache.org/repos/asf/geode/blob/f3a2ef4c/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/PageableLuceneQueryResultsImpl.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/PageableLuceneQueryResultsImpl.java
b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/PageableLuceneQueryResultsImpl.java
index 8db98a5..8e2b47c 100644
--- a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/PageableLuceneQueryResultsImpl.java
+++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/PageableLuceneQueryResultsImpl.java
@@ -16,7 +16,6 @@
 package org.apache.geode.cache.lucene.internal;
 
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
@@ -25,6 +24,7 @@ import java.util.Set;
 
 import org.apache.geode.cache.Region;
 import org.apache.geode.cache.execute.Execution;
+import org.apache.geode.cache.execute.FunctionException;
 import org.apache.geode.cache.execute.FunctionService;
 import org.apache.geode.cache.execute.ResultCollector;
 import org.apache.geode.cache.lucene.PageableLuceneQueryResults;
@@ -80,20 +80,28 @@ public class PageableLuceneQueryResultsImpl<K, V> implements PageableLuceneQuery
 
 
   public List<LuceneResultStruct<K, V>> getHitEntries(int fromIndex, int toIndex)
{
-    List<EntryScore<K>> scores = hits.subList(fromIndex, toIndex);
-    Set<K> keys = new HashSet<K>(scores.size());
-    for (EntryScore<K> score : scores) {
-      keys.add(score.getKey());
-    }
+    ArrayList<LuceneResultStruct<K, V>> results = null;
+    try {
+      List<EntryScore<K>> scores = hits.subList(fromIndex, toIndex);
+      Set<K> keys = new HashSet<K>(scores.size());
+      for (EntryScore<K> score : scores) {
+        keys.add(score.getKey());
+      }
+
+      Map<K, V> values = getValues(keys);
 
-    Map<K, V> values = getValues(keys);
 
-    ArrayList<LuceneResultStruct<K, V>> results =
-        new ArrayList<LuceneResultStruct<K, V>>(values.size());
-    for (EntryScore<K> score : scores) {
-      V value = values.get(score.getKey());
-      if (value != null)
-        results.add(new LuceneResultStructImpl(score.getKey(), value, score.getScore()));
+      results = new ArrayList<LuceneResultStruct<K, V>>(values.size());
+      for (EntryScore<K> score : scores) {
+        V value = values.get(score.getKey());
+        if (value != null)
+          results.add(new LuceneResultStructImpl(score.getKey(), value, score.getScore()));
+      }
+    } catch (FunctionException functionException) {
+      if (functionException.getCause() instanceof RuntimeException) {
+        throw (RuntimeException) functionException.getCause();
+      }
+      throw functionException;
     }
     return results;
   }

http://git-wip-us.apache.org/repos/asf/geode/blob/f3a2ef4c/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/results/LuceneGetPageFunction.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/results/LuceneGetPageFunction.java
b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/results/LuceneGetPageFunction.java
index 0addf48..e8a75ab 100644
--- a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/results/LuceneGetPageFunction.java
+++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/results/LuceneGetPageFunction.java
@@ -15,6 +15,7 @@
 
 package org.apache.geode.cache.lucene.internal.results;
 
+import org.apache.geode.cache.CacheClosedException;
 import org.apache.geode.cache.Region;
 import org.apache.geode.cache.execute.Function;
 import org.apache.geode.cache.execute.FunctionContext;
@@ -22,7 +23,9 @@ import org.apache.geode.cache.execute.RegionFunctionContext;
 import org.apache.geode.cache.partition.PartitionRegionHelper;
 import org.apache.geode.internal.InternalEntity;
 import org.apache.geode.internal.cache.EntrySnapshot;
+import org.apache.geode.internal.cache.PrimaryBucketException;
 import org.apache.geode.internal.cache.Token;
+import org.apache.geode.internal.cache.execute.InternalFunctionInvocationTargetException;
 import org.apache.geode.internal.logging.LogService;
 import org.apache.logging.log4j.Logger;
 
@@ -41,19 +44,22 @@ public class LuceneGetPageFunction implements Function, InternalEntity
{
 
   @Override
   public void execute(FunctionContext context) {
-    RegionFunctionContext ctx = (RegionFunctionContext) context;
-    Region region = PartitionRegionHelper.getLocalDataForContext(ctx);
-    Set<?> keys = ctx.getFilter();
-
-    List<PageEntry> results = new PageResults(keys.size());
-
-    for (Object key : keys) {
-      PageEntry entry = getEntry(region, key);
-      if (entry != null) {
-        results.add(entry);
+    try {
+      RegionFunctionContext ctx = (RegionFunctionContext) context;
+      Region region = PartitionRegionHelper.getLocalDataForContext(ctx);
+      Set<?> keys = ctx.getFilter();
+      List<PageEntry> results = new PageResults(keys.size());
+      for (Object key : keys) {
+        PageEntry entry = getEntry(region, key);
+        if (entry != null) {
+          results.add(entry);
+        }
       }
+      ctx.getResultSender().lastResult(results);
+    } catch (CacheClosedException | PrimaryBucketException e) {
+      logger.debug("Exception during lucene query function", e);
+      throw new InternalFunctionInvocationTargetException(e);
     }
-    ctx.getResultSender().lastResult(results);
   }
 
   protected PageEntry getEntry(final Region region, final Object key) {


Mime
View raw message