geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zho...@apache.org
Subject [geode] branch feature/GEODE-QueryProvider updated: use computeIfAbsent to calculate pointsConfigMap for PdxLuceneSerializer
Date Thu, 21 Jun 2018 18:49:09 GMT
This is an automated email from the ASF dual-hosted git repository.

zhouxj pushed a commit to branch feature/GEODE-QueryProvider
in repository https://gitbox.apache.org/repos/asf/geode.git


The following commit(s) were added to refs/heads/feature/GEODE-QueryProvider by this push:
     new 49190d1  use computeIfAbsent to calculate pointsConfigMap for PdxLuceneSerializer
49190d1 is described below

commit 49190d13a9ed8fb0424114149199aeb699be5acb
Author: zhouxh <gzhou@pivotal.io>
AuthorDate: Thu Jun 21 11:48:13 2018 -0700

    use computeIfAbsent to calculate pointsConfigMap for PdxLuceneSerializer
---
 .../geode/cache/lucene/internal/StringQueryProvider.java  | 14 +++++++++++++-
 .../serializer/HeterogeneousLuceneSerializer.java         |  6 +++---
 .../repository/serializer/PdxLuceneSerializer.java        | 15 +++++++--------
 .../repository/serializer/ReflectionLuceneSerializer.java |  7 ++++---
 4 files changed, 27 insertions(+), 15 deletions(-)

diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/StringQueryProvider.java
b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/StringQueryProvider.java
index 3dc16be..6f479e1 100644
--- a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/StringQueryProvider.java
+++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/StringQueryProvider.java
@@ -84,8 +84,20 @@ public class StringQueryProvider implements LuceneQueryProvider, DataSerializabl
       // pointsConfigMap.put("revenue", new PointsConfig(NumberFormat.getInstance(),
       // Integer.class));
       parser.setPointsConfigMap(pointsConfigMap);
-      // TODO: is DateTools.Resolution optional?
+      // TODO1: is DateTools.Resolution optional?
       // parser.setDateResolution(DateTools.Resolution.MILLISECOND);
+
+      // TODO2: HeterogeneousLuceneSerializer.getPointsConfigMap() calls putAll too often?
+      // TODO3: PdxLuceneSerializer.toDocuments().saveNumericFields's if (...) then
+      // computeIfAbsent(). Is it too expensive?
+      // TODO4: PdxLuceneSerializer and FlatFormatSerializer are using
+      // toDucuments().saveNumericFields() to get meta data, is it possible
+      // to move it to higher level for a generic method?
+      // TODO5: if a member is down, its meta data will be lost. How to recover it?
+      // TODO6: Short.class is not supported yet
+      // TODO7: Does PdxLuceneSerializer support nested field?
+      // TODO8: add example: numeric query __REGION_VALUE_FIELD:123
+      // TODO9: Can FlatFormatSerializer support pdx since it does not contain PdxLuceneSerializer
       parser.setAllowLeadingWildcard(true);
       try {
         luceneQuery = parser.parse(query, defaultField);
diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/repository/serializer/HeterogeneousLuceneSerializer.java
b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/repository/serializer/HeterogeneousLuceneSerializer.java
index 6fbb675..74f05af 100644
--- a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/repository/serializer/HeterogeneousLuceneSerializer.java
+++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/repository/serializer/HeterogeneousLuceneSerializer.java
@@ -16,8 +16,9 @@ package org.apache.geode.cache.lucene.internal.repository.serializer;
 
 import java.util.Collection;
 import java.util.Collections;
-import java.util.HashMap;
 import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
 
 import org.apache.logging.log4j.Logger;
 import org.apache.lucene.document.Document;
@@ -47,7 +48,7 @@ public class HeterogeneousLuceneSerializer implements LuceneSerializer {
   private Map<Class<?>, LuceneSerializer> mappers =
       new CopyOnWriteWeakHashMap<Class<?>, LuceneSerializer>();
 
-  private Map<String, PointsConfig> pointsConfigMap = new HashMap();
+  private ConcurrentMap<String, PointsConfig> pointsConfigMap = new ConcurrentHashMap();
 
   private static final Logger logger = LogService.getLogger();
 
@@ -93,7 +94,6 @@ public class HeterogeneousLuceneSerializer implements LuceneSerializer {
     }
   }
 
-  // TODO need a compute method to recalculate pointsConfigMap
   public Map<String, PointsConfig> getPointsConfigMap() {
     PdxLuceneSerializer pdxSerializer = (PdxLuceneSerializer) pdxMapper;
     pointsConfigMap.putAll(pdxSerializer.getPointsConfigMap());
diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/repository/serializer/PdxLuceneSerializer.java
b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/repository/serializer/PdxLuceneSerializer.java
index 11308b1..b62a05c 100644
--- a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/repository/serializer/PdxLuceneSerializer.java
+++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/repository/serializer/PdxLuceneSerializer.java
@@ -18,8 +18,9 @@ package org.apache.geode.cache.lucene.internal.repository.serializer;
 import java.text.NumberFormat;
 import java.util.Collection;
 import java.util.Collections;
-import java.util.HashMap;
 import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
 
 import org.apache.logging.log4j.Logger;
 import org.apache.lucene.document.Document;
@@ -36,18 +37,16 @@ import org.apache.geode.pdx.PdxInstance;
 class PdxLuceneSerializer implements LuceneSerializer {
 
   private static final Logger logger = LogService.getLogger();
-  private Map<String, PointsConfig> pointsConfigMap = new HashMap();
+  private ConcurrentMap<String, PointsConfig> pointsConfigMap = new ConcurrentHashMap();
 
   public PdxLuceneSerializer() {}
 
   private void saveNumericFields(String fieldName, Object fieldValue) {
     Class<?> clazz = fieldValue.getClass();
-    if (pointsConfigMap.get(fieldName) == null) {
-      if (clazz == Long.class || clazz == Integer.class || clazz == Float.class
-          || clazz == Double.class) {
-        pointsConfigMap.put(fieldName,
-            new PointsConfig(NumberFormat.getInstance(), (Class<? extends Number>)
clazz));
-      }
+    if (clazz == Integer.class || clazz == Long.class || clazz == Float.class
+        || clazz == Double.class) {
+      pointsConfigMap.computeIfAbsent(fieldName,
+          field -> new PointsConfig(NumberFormat.getInstance(), (Class<? extends Number>)
clazz));
     }
   }
 
diff --git a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/repository/serializer/ReflectionLuceneSerializer.java
b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/repository/serializer/ReflectionLuceneSerializer.java
index ea14f12..6f55251 100644
--- a/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/repository/serializer/ReflectionLuceneSerializer.java
+++ b/geode-lucene/src/main/java/org/apache/geode/cache/lucene/internal/repository/serializer/ReflectionLuceneSerializer.java
@@ -21,10 +21,11 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
-import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
 
 import org.apache.logging.log4j.Logger;
 import org.apache.lucene.document.Document;
@@ -41,7 +42,7 @@ import org.apache.geode.internal.logging.LogService;
 class ReflectionLuceneSerializer implements LuceneSerializer {
 
   private Field[] fields;
-  private Map<String, PointsConfig> pointsConfigMap = new HashMap();
+  private ConcurrentMap<String, PointsConfig> pointsConfigMap = new ConcurrentHashMap();
 
   private static final Logger logger = LogService.getLogger();
 
@@ -60,7 +61,7 @@ class ReflectionLuceneSerializer implements LuceneSerializer {
           field.setAccessible(true);
           foundFields.add(field);
 
-          if (type == Long.class || type == Integer.class || type == Float.class
+          if (type == Integer.class || type == Long.class || type == Float.class
               || type == Double.class) {
             pointsConfigMap.put(field.getName(),
                 new PointsConfig(NumberFormat.getInstance(), (Class<? extends Number>)
type));


Mime
View raw message