usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From g...@apache.org
Subject [29/36] usergrid git commit: Forced the indexing schema to store the map instead of the JSON string that way we only do the parsing once if we're doing a lot of get's on the schema.
Date Fri, 08 Apr 2016 20:21:16 GMT
Forced the indexing schema to store the map instead of the JSON string that way we only do
the parsing once if we're doing a lot of get's on the schema.


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

Branch: refs/heads/release-2.1.1
Commit: 1736ce15762fa8d1e0341b8383890854b2c0a18e
Parents: 37eca05
Author: George Reyes <grey@apache.org>
Authored: Thu Mar 31 16:38:16 2016 -0700
Committer: George Reyes <grey@apache.org>
Committed: Thu Mar 31 16:38:16 2016 -0700

----------------------------------------------------------------------
 .../corepersistence/CpEntityManager.java        | 17 +++++----------
 .../corepersistence/index/IndexSchemaCache.java |  3 ++-
 .../index/IndexSchemaCacheImpl.java             | 22 +++++++++++++-------
 .../corepersistence/index/IndexServiceImpl.java | 13 +++---------
 .../index/ReIndexServiceImpl.java               | 13 +++---------
 5 files changed, 28 insertions(+), 40 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/1736ce15/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
index 08204c9..6bbf0a3 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
@@ -1772,27 +1772,20 @@ public class CpEntityManager implements EntityManager {
 
         IndexSchemaCache indexSchemaCache = indexSchemaCacheFactory.getInstance( mm );
 
-        java.util.Optional<String> collectionIndexingSchema = indexSchemaCache.getCollectionSchema(
collectionName );
+        java.util.Optional<Map> collectionIndexingSchema = indexSchemaCache.getCollectionSchema(
collectionName );
 
-        String jsonSchemaMap = null;
-
-        if(collectionIndexingSchema.isPresent()){
-            jsonSchemaMap = collectionIndexingSchema.get();
-        }
 
         //If we do have a schema then parse it and add it to a list of properties we want
to keep.Otherwise return.
-        if ( jsonSchemaMap != null ) {
-            Map jsonMapData = ( Map ) JsonUtils.parse( jsonSchemaMap );
+        if ( collectionIndexingSchema.isPresent() ) {
+            Map jsonMapData = collectionIndexingSchema.get();
             schemaMap.put( "lastReindexed", jsonMapData.get( "lastReindexed" ) );
         }
         else {
             schemaMap.put( "lastReindexed", 0 );
         }
 
-
         ArrayList<String> fieldProperties = ( ArrayList<String> ) properties.get(
"fields" );
 
-        //TODO: do tests for * , and now add put and delete.
         if(fieldProperties.contains( "*" )){
             ArrayList<String> wildCardArrayList = new ArrayList<>(  );
             wildCardArrayList.add( "*" );
@@ -1828,10 +1821,10 @@ public class CpEntityManager implements EntityManager {
 
         IndexSchemaCache indexSchemaCache = indexSchemaCacheFactory.getInstance( mm ); //managerCache.getIndexSchema(
mm );
 
-        java.util.Optional<String> collectionIndexingSchema =  indexSchemaCache.getCollectionSchema(
collectionName );
+        java.util.Optional<Map> collectionIndexingSchema =  indexSchemaCache.getCollectionSchema(
collectionName );
 
         if(collectionIndexingSchema.isPresent()){
-            return JsonUtils.parse( collectionIndexingSchema.get() );
+            return collectionIndexingSchema.get();
         }
         else{
             return null;

http://git-wip-us.apache.org/repos/asf/usergrid/blob/1736ce15/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/IndexSchemaCache.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/IndexSchemaCache.java
b/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/IndexSchemaCache.java
index debfe2a..a56ffd6 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/IndexSchemaCache.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/IndexSchemaCache.java
@@ -17,6 +17,7 @@
 package org.apache.usergrid.corepersistence.index;
 
 
+import java.util.Map;
 import java.util.Optional;
 
 
@@ -27,7 +28,7 @@ public interface IndexSchemaCache {
      * @param collectionName
      * @return
      */
-    public Optional<String> getCollectionSchema(String collectionName);
+    public Optional<Map> getCollectionSchema( String collectionName );
 
     void putCollectionSchema( String collectionName, String collectionSchema );
 

http://git-wip-us.apache.org/repos/asf/usergrid/blob/1736ce15/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/IndexSchemaCacheImpl.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/IndexSchemaCacheImpl.java
b/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/IndexSchemaCacheImpl.java
index 14752b4..3df31cc 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/IndexSchemaCacheImpl.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/IndexSchemaCacheImpl.java
@@ -18,12 +18,14 @@
 package org.apache.usergrid.corepersistence.index;
 
 
+import java.util.Map;
 import java.util.Optional;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import org.apache.usergrid.persistence.map.MapManager;
+import org.apache.usergrid.utils.JsonUtils;
 
 import com.google.common.cache.CacheBuilder;
 import com.google.common.cache.CacheLoader;
@@ -39,7 +41,7 @@ import com.google.inject.Singleton;
 public class IndexSchemaCacheImpl implements IndexSchemaCache {
     private static final Logger logger = LoggerFactory.getLogger(IndexSchemaCacheImpl.class
);
 
-    private final LoadingCache<String,Optional<String>> indexSchemaCache;
+    private final LoadingCache<String,Optional<Map>> indexSchemaCache;
     private final MapManager mapManager;
 
 
@@ -48,23 +50,29 @@ public class IndexSchemaCacheImpl implements IndexSchemaCache {
         indexSchemaCache = CacheBuilder.newBuilder()
             .maximumSize( indexSchemaCacheFig.getCacheSize() )
             //.expireAfterWrite( indexSchemaCacheFig.getCacheTimeout(), TimeUnit.MILLISECONDS
) <-- I don't think we want this to expire that quickly.
-            .build( new CacheLoader<String, Optional<String>>() {
+            .build( new CacheLoader<String, Optional<Map>>() {
                 @Override
-                public Optional<String> load( final String collectionName ) throws
Exception {
+                public Optional<Map> load( final String collectionName ) throws Exception
{
                     return Optional.ofNullable( retrieveCollectionSchema( collectionName
) );
                 }
             } );
     }
 
-    private String retrieveCollectionSchema( final String collectionName ){
-        return mapManager.getString( collectionName );
+    private Map retrieveCollectionSchema( final String collectionName ){
+        String collectionIndexingSchema = mapManager.getString( collectionName );
+        Map parsedCollectionIndexingSchema = null;
+        if(collectionIndexingSchema!=null){
+            return (Map) JsonUtils.parse( collectionIndexingSchema );
+
+        }
+        return parsedCollectionIndexingSchema;
     }
 
 
     @Override
-    public Optional<String> getCollectionSchema( final String collectionName ) {
+    public Optional<Map> getCollectionSchema( final String collectionName ) {
         try {
-            Optional<String> optionalCollectionSchema = indexSchemaCache.get( collectionName
);
+            Optional<Map> optionalCollectionSchema = indexSchemaCache.get( collectionName
);
             if(!optionalCollectionSchema.isPresent()){
                 indexSchemaCache.invalidate( collectionName );
                 return Optional.empty();

http://git-wip-us.apache.org/repos/asf/usergrid/blob/1736ce15/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/IndexServiceImpl.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/IndexServiceImpl.java
b/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/IndexServiceImpl.java
index 9e05df3..c81c4ef 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/IndexServiceImpl.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/IndexServiceImpl.java
@@ -212,19 +212,12 @@ public class IndexServiceImpl implements IndexService {
 
         IndexSchemaCache indexSchemaCache = indexSchemaCacheFactory.getInstance( mm );
 
-        Optional<String> collectionIndexingSchema =  indexSchemaCache.getCollectionSchema(
collectionName );
-
-
-        String jsonSchemaMap =  null;
-
-        if(collectionIndexingSchema.isPresent()){
-            jsonSchemaMap = collectionIndexingSchema.get();
-        }
+        Optional<Map> collectionIndexingSchema =  indexSchemaCache.getCollectionSchema(
collectionName );
 
         //If we do have a schema then parse it and add it to a list of properties we want
to keep.Otherwise return.
-        if ( jsonSchemaMap != null ) {
+        if ( collectionIndexingSchema.isPresent()) {
 
-            Map jsonMapData = ( Map ) JsonUtils.parse( jsonSchemaMap );
+            Map jsonMapData = collectionIndexingSchema.get();
             Schema schema = Schema.getDefaultSchema();
             defaultProperties = schema.getRequiredProperties( collectionName );
             fieldsToKeep = ( ArrayList ) jsonMapData.get( "fields" );

http://git-wip-us.apache.org/repos/asf/usergrid/blob/1736ce15/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/ReIndexServiceImpl.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/ReIndexServiceImpl.java
b/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/ReIndexServiceImpl.java
index 591fcd6..125222a 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/ReIndexServiceImpl.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/ReIndexServiceImpl.java
@@ -142,19 +142,12 @@ public class ReIndexServiceImpl implements ReIndexService {
             MapManager collectionMapStorage = mapManagerFactory.createMapManager( CpNamingUtils.getEntityTypeMapScope(
appId.get().getApplication()  ) );
             IndexSchemaCache indexSchemaCache = indexSchemaCacheFactory.getInstance( collectionMapStorage
);
 
-            java.util.Optional<String> collectionIndexingSchema =  indexSchemaCache.getCollectionSchema(
collectionName );
-
-
-            String jsonSchemaMap =  null;
-
-            if(collectionIndexingSchema.isPresent()){
-                jsonSchemaMap = collectionIndexingSchema.get();
-            }
+            java.util.Optional<Map> collectionIndexingSchema =  indexSchemaCache.getCollectionSchema(
collectionName );
 
             //If we do have a schema then parse it and add it to a list of properties we
want to keep.Otherwise return.
-            if ( jsonSchemaMap != null ) {
+            if ( collectionIndexingSchema.isPresent() ) {
 
-                Map jsonMapData = ( Map ) JsonUtils.parse( jsonSchemaMap );
+                Map jsonMapData = collectionIndexingSchema.get();
 
                 jsonMapData.put( "lastReindexed", Instant.now().toEpochMilli() );
                 //should probably roll this into the cache.


Mime
View raw message