usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From g...@apache.org
Subject [23/36] usergrid git commit: Added the index schema cache to the index service.
Date Fri, 08 Apr 2016 20:21:10 GMT
Added the index schema cache to the index service.


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

Branch: refs/heads/release-2.1.1
Commit: 12a3be9d7c3b5d35c6ee243b06a8e4613835514d
Parents: 7e180af
Author: George Reyes <grey@apache.org>
Authored: Wed Mar 30 17:02:30 2016 -0700
Committer: George Reyes <grey@apache.org>
Committed: Wed Mar 30 17:02:30 2016 -0700

----------------------------------------------------------------------
 .../usergrid/corepersistence/CpEntityManager.java   | 16 +++++++++++++---
 .../usergrid/corepersistence/CpManagerCache.java    |  4 ++--
 .../usergrid/corepersistence/ManagerCache.java      |  3 ++-
 .../corepersistence/index/IndexServiceImpl.java     | 15 ++++++++++++++-
 4 files changed, 31 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/12a3be9d/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 d1f28be..751fd9a 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
@@ -1760,8 +1760,15 @@ public class CpEntityManager implements EntityManager {
 
         MapManager mm = getMapManagerForTypes();
 
-        //TODO: add a cache around
-        String jsonSchemaMap = mm.getString( collectionName );
+        IndexSchemaCache indexSchemaCache = managerCache.getIndexSchema( mm );
+
+        java.util.Optional<String> 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 ) {
@@ -1773,7 +1780,9 @@ public class CpEntityManager implements EntityManager {
         }
         schemaMap.putAll( properties );
 
+        //TODO: we have to update then invalidate previous entry.
         mm.putString( collectionName,JsonUtils.mapToJsonString( schemaMap ) );
+        indexSchemaCache.evictCollectionSchema( collectionName );
 
         return schemaMap;
 
@@ -1783,8 +1792,9 @@ public class CpEntityManager implements EntityManager {
     public Object getCollectionSchema( String collectionName ){
         MapManager mm = getMapManagerForTypes();
 
+        IndexSchemaCache indexSchemaCache = managerCache.getIndexSchema( mm );
 
-        java.util.Optional<String> collectionIndexingSchema =  managerCache.getIndexSchema(
mm,collectionName );
+        java.util.Optional<String> collectionIndexingSchema =  indexSchemaCache.getCollectionSchema(
collectionName );
 
         if(collectionIndexingSchema.isPresent()){
             return JsonUtils.parse( collectionIndexingSchema.get() );

http://git-wip-us.apache.org/repos/asf/usergrid/blob/12a3be9d/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpManagerCache.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpManagerCache.java
b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpManagerCache.java
index dfbab00..e30de0f 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpManagerCache.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpManagerCache.java
@@ -106,8 +106,8 @@ public class CpManagerCache implements ManagerCache {
     //could be called an index schema manager.
 
     @Override
-    public Optional<String> getIndexSchema( MapManager mapManager, String collectionName
) {
-        return indexSchemaCacheFactory.getInstance( mapManager ).getCollectionSchema( collectionName
);
+    public IndexSchemaCache getIndexSchema( MapManager mapManager ) {
+        return indexSchemaCacheFactory.getInstance( mapManager );
     }
 
 

http://git-wip-us.apache.org/repos/asf/usergrid/blob/12a3be9d/stack/core/src/main/java/org/apache/usergrid/corepersistence/ManagerCache.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/ManagerCache.java
b/stack/core/src/main/java/org/apache/usergrid/corepersistence/ManagerCache.java
index e0a8257..c07930c 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/ManagerCache.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/ManagerCache.java
@@ -22,6 +22,7 @@ package org.apache.usergrid.corepersistence;
 
 import java.util.Optional;
 
+import org.apache.usergrid.corepersistence.index.IndexSchemaCache;
 import org.apache.usergrid.persistence.collection.EntityCollectionManager;
 import org.apache.usergrid.persistence.core.scope.ApplicationScope;
 import org.apache.usergrid.persistence.graph.GraphManager;
@@ -68,7 +69,7 @@ public interface ManagerCache {
      */
     MapManager getMapManager(MapScope mapScope);
 
-    Optional<String> getIndexSchema( MapManager mapManager, String collectionName );
+    IndexSchemaCache getIndexSchema( MapManager mapManager );
 
     /**
      * gets index producer

http://git-wip-us.apache.org/repos/asf/usergrid/blob/12a3be9d/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 f3a3389..f931528 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
@@ -84,6 +84,7 @@ public class IndexServiceImpl implements IndexService {
     private final GraphManagerFactory graphManagerFactory;
     private final EntityIndexFactory entityIndexFactory;
     private final MapManagerFactory mapManagerFactory;
+    private final IndexSchemaCacheFactory indexSchemaCacheFactory;
     private final EdgesObservable edgesObservable;
     private final IndexFig indexFig;
     private final IndexLocationStrategyFactory indexLocationStrategyFactory;
@@ -94,6 +95,7 @@ public class IndexServiceImpl implements IndexService {
     @Inject
     public IndexServiceImpl( final GraphManagerFactory graphManagerFactory, final EntityIndexFactory
entityIndexFactory,
                              final MapManagerFactory mapManagerFactory,
+                             final IndexSchemaCacheFactory indexSchemaCacheFactory,
                              final EdgesObservable edgesObservable, final IndexFig indexFig,
                              final IndexLocationStrategyFactory indexLocationStrategyFactory,
                              final MetricsFactory metricsFactory ) {
@@ -103,6 +105,7 @@ public class IndexServiceImpl implements IndexService {
         this.edgesObservable = edgesObservable;
         this.indexFig = indexFig;
         this.indexLocationStrategyFactory = indexLocationStrategyFactory;
+        this.indexSchemaCacheFactory = indexSchemaCacheFactory;
         this.indexTimer = metricsFactory.getTimer( IndexServiceImpl.class, "index.update_all");
         this.addTimer = metricsFactory.getTimer( IndexServiceImpl.class, "index.add" );
     }
@@ -206,7 +209,17 @@ public class IndexServiceImpl implements IndexService {
         ArrayList fieldsToKeep;
 
         String collectionName = CpNamingUtils.getCollectionNameFromEdgeName( indexEdge.getEdgeName()
);
-        String jsonSchemaMap = mm.getString( collectionName );
+
+        IndexSchemaCache indexSchemaCache = indexSchemaCacheFactory.getInstance( mm );
+
+        Optional<String> 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 ) {


Mime
View raw message