You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by sn...@apache.org on 2014/10/29 16:28:58 UTC
[1/5] git commit: adding gatling script
Repository: incubator-usergrid
Updated Branches:
refs/heads/two-dot-o-events 1f0e6e439 -> 2bacb5f17
adding gatling script
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/8df2185a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/8df2185a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/8df2185a
Branch: refs/heads/two-dot-o-events
Commit: 8df2185a4a8530a63fe8ea7382e5db758437605d
Parents: 744e5a8
Author: Shawn Feldman <sf...@apache.org>
Authored: Tue Oct 28 12:43:19 2014 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Tue Oct 28 12:43:19 2014 -0600
----------------------------------------------------------------------
stack/loadtests/src/main/scripts/gatling-mvn.sh | 15 +++++++++++++++
1 file changed, 15 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8df2185a/stack/loadtests/src/main/scripts/gatling-mvn.sh
----------------------------------------------------------------------
diff --git a/stack/loadtests/src/main/scripts/gatling-mvn.sh b/stack/loadtests/src/main/scripts/gatling-mvn.sh
new file mode 100644
index 0000000..ad02feb
--- /dev/null
+++ b/stack/loadtests/src/main/scripts/gatling-mvn.sh
@@ -0,0 +1,15 @@
+#!/bin/sh
+URL="$1"
+ORG="$2"
+APP="$3"
+NOTIFIER="$4"
+USERS="$5"
+RAMP="$6"
+shift 6
+rm -rf usergrid
+git clone https://github.com/apache/incubator-usergrid.git usergrid
+cd usergrid/stack
+git checkout -b two-dot-o origin/two-dot-o
+cd loadtests
+mvn clean install
+mvn gatling:execute -Dthrottle=3000 -Dduration=300 -DnumEntities=5000 -DnumUsers=${USERS} -DrampTime=${RAMP} -Dbaseurl=${URL} -Dorg=${ORG} -Dapp=${APP} -DpushNotifier=${NOTIFIER} -DpushProvider=noop
[4/5] git commit: Only init application index at most once per JVM.
Posted by sn...@apache.org.
Only init application index at most once per JVM.
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/89cf61f0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/89cf61f0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/89cf61f0
Branch: refs/heads/two-dot-o-events
Commit: 89cf61f08f795bea8d8bf23d5213644f1e1eac3d
Parents: c571965
Author: Dave Johnson <dm...@apigee.com>
Authored: Wed Oct 29 11:26:45 2014 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Wed Oct 29 11:26:45 2014 -0400
----------------------------------------------------------------------
.../corepersistence/CpEntityManagerFactory.java | 53 ++++++++++----------
1 file changed, 27 insertions(+), 26 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/89cf61f0/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
index bc45769..6e6b461 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
@@ -24,9 +24,11 @@ import static java.lang.String.CASE_INSENSITIVE_ORDER;
import java.util.Arrays;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import java.util.TreeMap;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -91,23 +93,23 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
public static final Class<DynamicEntity> APPLICATION_ENTITY_CLASS = DynamicEntity.class;
- // The System Application where we store app and org metadata
+ /** The System Application where we store app and org metadata */
public static final UUID SYSTEM_APP_ID =
UUID.fromString("b6768a08-b5d5-11e3-a495-10ddb1de66c3");
- /**
- * App where we store management info
- */
+ /** App where we store management info */
public static final UUID MANAGEMENT_APPLICATION_ID =
UUID.fromString("b6768a08-b5d5-11e3-a495-11ddb1de66c8");
- /**
- * TODO Dave what is this?
- */
+ /** TODO Do we need this in two-dot-o? */
public static final UUID DEFAULT_APPLICATION_ID =
UUID.fromString("b6768a08-b5d5-11e3-a495-11ddb1de66c9");
- private AtomicBoolean init_indexes = new AtomicBoolean( );
+ /** Have we already initialized the index for the management app? */
+ private AtomicBoolean indexInitialized = new AtomicBoolean( );
+
+ /** Keep track of applications that already have indexes to avoid redundant re-creation. */
+ private static final Set<UUID> applicationIndexesCreated = new HashSet<UUID>();
// cache of already instantiated entity managers
@@ -205,13 +207,16 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
private EntityManager _getEntityManager( UUID applicationId ) {
+
EntityManager em = new CpEntityManager();
em.init( this, applicationId );
- //TODO PERFORMANCE Can we remove this? Seems like we should fix our lifecycle instead...
- //if this is the first time we've loaded this entity manager in the JVM, create it's indexes, it may be new
- //not sure how to handle other than this if the system dies after the application em has been created
- //but before the create call can create the index
- em.createIndex();
+
+ // only need to do this once
+ if ( !applicationIndexesCreated.contains( applicationId ) ) {
+ em.createIndex();
+ applicationIndexesCreated.add( applicationId );
+ }
+
return em;
}
@@ -295,10 +300,6 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
properties.put( PROPERTY_NAME, appName );
EntityManager appEm = getEntityManager( applicationId );
- //create our ES index since we're initializing this application
-// TODO PERFORMANCE pushed this down into the cache load can we do this here?
-// appEm.createIndex();
-
appEm.create( applicationId, TYPE_APPLICATION, properties );
appEm.resetRoles();
appEm.refreshIndex();
@@ -640,7 +641,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
private void maybeCreateIndexes() {
// system app
- if ( init_indexes.getAndSet( true ) ) {
+ if ( indexInitialized.getAndSet( true ) ) {
return;
}
@@ -653,16 +654,16 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
private List<EntityIndex> getManagementIndexes() {
return Arrays.asList(
- getManagerCache().getEntityIndex(
- new ApplicationScopeImpl( new SimpleId( SYSTEM_APP_ID, "application" ) ) ),
+ getManagerCache().getEntityIndex(
+ new ApplicationScopeImpl( new SimpleId( SYSTEM_APP_ID, "application" ))),
- // default app
- getManagerCache().getEntityIndex(
- new ApplicationScopeImpl( new SimpleId( getManagementAppId(), "application" ) ) ),
+ // management app
+ getManagerCache().getEntityIndex(
+ new ApplicationScopeImpl( new SimpleId( getManagementAppId(), "application" ))),
- // management app
- getManagerCache().getEntityIndex(
- new ApplicationScopeImpl( new SimpleId( getDefaultAppId(), "application" ) ) ) );
+ // default app TODO: do we need this in two-dot-o
+ getManagerCache().getEntityIndex(
+ new ApplicationScopeImpl( new SimpleId( getDefaultAppId(), "application" ))));
}
[2/5] git commit: Use Guava Cache for manager caches.
Posted by sn...@apache.org.
Use Guava Cache for manager caches.
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/3d3f1897
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/3d3f1897
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/3d3f1897
Branch: refs/heads/two-dot-o-events
Commit: 3d3f1897953bffa96b18a9012b34c0480c849cee
Parents: 8df2185
Author: Dave Johnson <dm...@apigee.com>
Authored: Wed Oct 29 09:07:05 2014 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Wed Oct 29 09:07:05 2014 -0400
----------------------------------------------------------------------
.../corepersistence/CpManagerCache.java | 117 +++++++++++--------
1 file changed, 70 insertions(+), 47 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/3d3f1897/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 62ea81f..99bde22 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
@@ -15,6 +15,11 @@
*/
package org.apache.usergrid.corepersistence;
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.CacheLoader;
+import com.google.common.cache.LoadingCache;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
import org.apache.usergrid.persistence.collection.CollectionScope;
import org.apache.usergrid.persistence.collection.EntityCollectionManager;
import org.apache.usergrid.persistence.collection.EntityCollectionManagerFactory;
@@ -26,7 +31,7 @@ import org.apache.usergrid.persistence.index.EntityIndexFactory;
import org.apache.usergrid.persistence.map.MapManager;
import org.apache.usergrid.persistence.map.MapManagerFactory;
import org.apache.usergrid.persistence.map.MapScope;
-import org.apache.usergrid.utils.LRUCache2;
+
public class CpManagerCache {
@@ -36,19 +41,50 @@ public class CpManagerCache {
private final MapManagerFactory mmf;
// TODO: consider making these cache sizes and timeouts configurable
- // TODO: replace with Guava cache
- private final LRUCache2<CollectionScope, EntityCollectionManager> ecmCache
- = new LRUCache2<CollectionScope, EntityCollectionManager>(50, 1 * 60 * 60 * 1000);
-
- private final LRUCache2<ApplicationScope, EntityIndex> eiCache
- = new LRUCache2<>(50, 1 * 60 * 60 * 1000);
-
- private final LRUCache2<ApplicationScope, GraphManager> gmCache
- = new LRUCache2<ApplicationScope, GraphManager>(50, 1 * 60 * 60 * 1000);
-
- private final LRUCache2<MapScope, MapManager> mmCache
- = new LRUCache2<MapScope, MapManager>(50, 1 * 60 * 60 * 1000);
+ private LoadingCache<CollectionScope, EntityCollectionManager> ecmCache =
+ CacheBuilder.newBuilder()
+ .maximumSize(100)
+ .expireAfterWrite( 1, TimeUnit.HOURS)
+ .build( new CacheLoader<CollectionScope, EntityCollectionManager>() {
+ public EntityCollectionManager load( CollectionScope scope ) {
+ return ecmf.createCollectionManager( scope );
+ }
+ }
+ );
+
+ private LoadingCache<ApplicationScope, EntityIndex> eiCache =
+ CacheBuilder.newBuilder()
+ .maximumSize(100)
+ .expireAfterWrite( 1, TimeUnit.HOURS )
+ .build( new CacheLoader<ApplicationScope, EntityIndex>() {
+ public EntityIndex load( ApplicationScope scope ) {
+ return eif.createEntityIndex( scope );
+ }
+ }
+ );
+
+ private LoadingCache<ApplicationScope, GraphManager> gmCache =
+ CacheBuilder.newBuilder()
+ .maximumSize(100)
+ .expireAfterWrite( 1, TimeUnit.HOURS )
+ .build( new CacheLoader<ApplicationScope, GraphManager>() {
+ public GraphManager load( ApplicationScope scope ) {
+ return gmf.createEdgeManager( scope );
+ }
+ }
+ );
+
+ private LoadingCache<MapScope, MapManager> mmCache =
+ CacheBuilder.newBuilder()
+ .maximumSize(100)
+ .expireAfterWrite( 1, TimeUnit.HOURS )
+ .build( new CacheLoader<MapScope, MapManager>() {
+ public MapManager load( MapScope scope ) {
+ return mmf.createMapManager( scope );
+ }
+ }
+ );
public CpManagerCache(
EntityCollectionManagerFactory ecmf,
@@ -63,54 +99,41 @@ public class CpManagerCache {
}
public EntityCollectionManager getEntityCollectionManager(CollectionScope scope) {
-
- EntityCollectionManager ecm = ecmCache.get(scope);
-
- if (ecm == null) {
- ecm = ecmf.createCollectionManager(scope);
- ecmCache.put(scope, ecm);
+ try {
+ return ecmCache.get( scope );
+ } catch (ExecutionException ex) {
+ throw new RuntimeException("Error getting manager", ex);
}
- return ecm;
}
- public EntityIndex getEntityIndex(ApplicationScope applicationScope) {
-
- EntityIndex ei = eiCache.get(applicationScope);
-
- if (ei == null) {
- ei = eif.createEntityIndex(applicationScope);
- eiCache.put(applicationScope, ei);
+ public EntityIndex getEntityIndex(ApplicationScope appScope) {
+ try {
+ return eiCache.get( appScope );
+ } catch (ExecutionException ex) {
+ throw new RuntimeException("Error getting manager", ex);
}
- return ei;
}
public GraphManager getGraphManager(ApplicationScope appScope) {
-
- GraphManager gm = gmCache.get(appScope);
-
- if (gm == null) {
- gm = gmf.createEdgeManager(appScope);
- gmCache.put(appScope, gm);
+ try {
+ return gmCache.get( appScope );
+ } catch (ExecutionException ex) {
+ throw new RuntimeException("Error getting manager", ex);
}
- return gm;
}
public MapManager getMapManager( MapScope mapScope) {
-
- MapManager mm = mmCache.get(mapScope);
-
- if (mm == null) {
- mm = mmf.createMapManager(mapScope);
- mmCache.put(mapScope, mm);
+ try {
+ return mmCache.get( mapScope );
+ } catch (ExecutionException ex) {
+ throw new RuntimeException("Error getting manager", ex);
}
- return mm;
}
void flush() {
- gmCache.purge();
- ecmCache.purge();
- eiCache.purge();
+ ecmCache.invalidateAll();
+ eiCache.invalidateAll();
+ gmCache.invalidateAll();
+ mmCache.invalidateAll();
}
-
-
}
[5/5] git commit: Merge branch 'two-dot-o' into two-dot-o-events
Posted by sn...@apache.org.
Merge branch 'two-dot-o' into two-dot-o-events
Conflicts:
stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/2bacb5f1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/2bacb5f1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/2bacb5f1
Branch: refs/heads/two-dot-o-events
Commit: 2bacb5f1767115e34a38b9005533f4899efa6345
Parents: 1f0e6e4 89cf61f
Author: Dave Johnson <dm...@apigee.com>
Authored: Wed Oct 29 11:28:46 2014 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Wed Oct 29 11:28:46 2014 -0400
----------------------------------------------------------------------
.../main/resources/usergrid-default.properties | 3 +
.../corepersistence/CpEntityManager.java | 69 ++++++++++-
.../corepersistence/CpEntityManagerFactory.java | 53 ++++-----
.../corepersistence/CpManagerCache.java | 117 +++++++++++--------
.../corepersistence/CpRelationManager.java | 31 ++---
.../persistence/index/query/EntityResults.java | 6 +-
stack/loadtests/src/main/scripts/gatling-mvn.sh | 15 +++
7 files changed, 199 insertions(+), 95 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2bacb5f1/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
----------------------------------------------------------------------
[3/5] git commit: Add a short-term cache to avoid redundant Entity
reloading in CpEntityManager & CpRelationManager.
Posted by sn...@apache.org.
Add a short-term cache to avoid redundant Entity reloading in CpEntityManager & CpRelationManager.
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/c5719654
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/c5719654
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/c5719654
Branch: refs/heads/two-dot-o-events
Commit: c57196546f8c278b3eda3789015caa26d0c45229
Parents: 3d3f189
Author: Dave Johnson <dm...@apigee.com>
Authored: Wed Oct 29 10:38:14 2014 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Wed Oct 29 10:38:14 2014 -0400
----------------------------------------------------------------------
.../main/resources/usergrid-default.properties | 3 +
.../corepersistence/CpEntityManager.java | 73 +++++++++++++++++---
.../corepersistence/CpRelationManager.java | 31 +++++----
.../persistence/index/query/EntityResults.java | 6 +-
4 files changed, 87 insertions(+), 26 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c5719654/stack/config/src/main/resources/usergrid-default.properties
----------------------------------------------------------------------
diff --git a/stack/config/src/main/resources/usergrid-default.properties b/stack/config/src/main/resources/usergrid-default.properties
index a4760dd..fb043d4 100644
--- a/stack/config/src/main/resources/usergrid-default.properties
+++ b/stack/config/src/main/resources/usergrid-default.properties
@@ -62,6 +62,9 @@ elasticsearch.port=9300
index.query.limit.default=1000
+usergrid.entity_cache_size=200
+usergrid.entity_cache_timeout_ms=500
+
###############################################################################
#
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c5719654/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 c9ad87b..78c9433 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
@@ -17,6 +17,10 @@ package org.apache.usergrid.corepersistence;
import com.google.common.base.Preconditions;
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.CacheLoader;
+import com.google.common.cache.CacheLoader.InvalidCacheLoadException;
+import com.google.common.cache.LoadingCache;
import com.netflix.hystrix.exception.HystrixRuntimeException;
import com.yammer.metrics.annotation.Metered;
import static java.lang.String.CASE_INSENSITIVE_ORDER;
@@ -37,6 +41,8 @@ import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.UUID;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
import me.prettyprint.hector.api.Keyspace;
import me.prettyprint.hector.api.beans.ColumnSlice;
import me.prettyprint.hector.api.beans.CounterRow;
@@ -86,10 +92,8 @@ import static org.apache.usergrid.persistence.Schema.PROPERTY_TYPE;
import static org.apache.usergrid.persistence.Schema.PROPERTY_UUID;
import static org.apache.usergrid.persistence.Schema.TYPE_APPLICATION;
import static org.apache.usergrid.persistence.Schema.TYPE_ENTITY;
-import static org.apache.usergrid.persistence.Schema.getDefaultSchema;
import org.apache.usergrid.persistence.SimpleEntityRef;
import static org.apache.usergrid.persistence.SimpleEntityRef.getUuid;
-import static org.apache.usergrid.persistence.SimpleEntityRef.ref;
import org.apache.usergrid.persistence.SimpleRoleRef;
import org.apache.usergrid.persistence.TypedEntity;
import org.apache.usergrid.persistence.cassandra.ApplicationCF;
@@ -131,7 +135,6 @@ import org.apache.usergrid.persistence.index.query.CounterResolution;
import org.apache.usergrid.persistence.index.query.Identifier;
import org.apache.usergrid.persistence.index.query.Query;
import org.apache.usergrid.persistence.index.query.Query.Level;
-import static org.apache.usergrid.persistence.index.query.Query.Level.REFS;
import org.apache.usergrid.persistence.map.MapManager;
import org.apache.usergrid.persistence.map.MapScope;
import org.apache.usergrid.persistence.map.impl.MapScopeImpl;
@@ -140,7 +143,6 @@ import org.apache.usergrid.persistence.model.entity.SimpleId;
import org.apache.usergrid.persistence.model.field.Field;
import org.apache.usergrid.persistence.model.field.StringField;
import org.apache.usergrid.persistence.model.util.UUIDGenerator;
-import org.apache.usergrid.persistence.schema.CollectionInfo;
import org.apache.usergrid.utils.ClassUtils;
import static org.apache.usergrid.utils.ClassUtils.cast;
import org.apache.usergrid.utils.CompositeUtils;
@@ -185,6 +187,9 @@ public class CpEntityManager implements EntityManager {
private String TYPES_BY_UUID_MAP = "zzz_typesbyuuid_zzz";
+ /** Short-term cache to keep us from reloading same Entity during single request. */
+ private LoadingCache<EntityScope, org.apache.usergrid.persistence.model.entity.Entity> entityCache;
+
public CpEntityManager() {}
@@ -206,6 +211,56 @@ public class CpEntityManager implements EntityManager {
// set to false for now
this.skipAggregateCounters = false;
+
+ int entityCacheSize = Integer.parseInt(
+ cass.getProperties().getProperty("usergrid.entity_cache_size", "100"));
+
+ int entityCacheTimeout = Integer.parseInt(
+ cass.getProperties().getProperty("usergrid.entity_cache_timeout_ms", "500"));
+
+ this.entityCache = CacheBuilder.newBuilder()
+ .maximumSize( entityCacheSize )
+ .expireAfterWrite( entityCacheTimeout, TimeUnit.MILLISECONDS )
+ .build( new CacheLoader<EntityScope, org.apache.usergrid.persistence.model.entity.Entity>() {
+ public org.apache.usergrid.persistence.model.entity.Entity load( EntityScope entityScope ) {
+ return managerCache.getEntityCollectionManager(
+ entityScope.scope ).load( entityScope.entityId ).toBlocking().lastOrDefault(null);
+ }
+ }
+ );
+ }
+
+
+ /** Needed to support short-term Entity cache. */
+ public static class EntityScope {
+ CollectionScope scope;
+ Id entityId;
+ public EntityScope( CollectionScope scope, Id entityId ) {
+ this.scope = scope;
+ this.entityId = entityId;
+ }
+ }
+
+
+ /**
+ * Load entity from short-term cache.
+ * Package scope so that CpRelationManager can use it too.
+ *
+ * @param es Carries Entity Id and CollectionScope from which to load Entity.
+ * @return Entity or null if not found
+ */
+ org.apache.usergrid.persistence.model.entity.Entity load( EntityScope es ) {
+ try {
+ return entityCache.get( es );
+
+ } catch ( InvalidCacheLoadException icle ) {
+ // fine, entity not found
+ return null;
+
+ } catch ( ExecutionException exex ) {
+ // uh-oh, more serious problem
+ throw new RuntimeException( "Error loading entity", exex );
+ }
}
@@ -320,7 +375,7 @@ public class CpEntityManager implements EntityManager {
// }
org.apache.usergrid.persistence.model.entity.Entity cpEntity =
- ecm.load( id ).toBlockingObservable().last();
+ load( new EntityScope( collectionScope, id ) );
if ( cpEntity == null ) {
if ( logger.isDebugEnabled() ) {
@@ -407,7 +462,7 @@ public class CpEntityManager implements EntityManager {
// }
org.apache.usergrid.persistence.model.entity.Entity cpEntity =
- ecm.load( id ).toBlocking().last();
+ load( new EntityScope( collectionScope, id ) );
if ( cpEntity == null ) {
if ( logger.isDebugEnabled() ) {
@@ -497,6 +552,8 @@ public class CpEntityManager implements EntityManager {
try {
cpEntity = ecm.update( cpEntity ).toBlockingObservable().last();
+
+ // need to reload entity so bypass entity cache
cpEntity = ecm.load( entityId ).toBlockingObservable().last();
logger.debug("Wrote {}:{} version {}", new Object[] {
@@ -545,7 +602,7 @@ public class CpEntityManager implements EntityManager {
// }
org.apache.usergrid.persistence.model.entity.Entity entity =
- ecm.load( entityId ).toBlockingObservable().last();
+ load( new EntityScope( collectionScope, entityId ) );
if ( entity != null ) {
@@ -996,7 +1053,7 @@ public class CpEntityManager implements EntityManager {
// }
org.apache.usergrid.persistence.model.entity.Entity cpEntity =
- ecm.load( entityId ).toBlocking().last();
+ load( new EntityScope( collectionScope, entityId ) );
cpEntity.removeField( propertyName );
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c5719654/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManager.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManager.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManager.java
index d0da90f..1e8dcc3 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManager.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManager.java
@@ -234,9 +234,9 @@ public class CpRelationManager implements RelationManager {
} );
}
- //TODO PERFORMANCE why are we loading this again here?
- this.cpHeadEntity = ecm.load( new SimpleId(
- headEntity.getUuid(), headEntity.getType() )).toBlocking().lastOrDefault(null);
+ Id entityId = new SimpleId( headEntity.getUuid(), headEntity.getType() );
+ this.cpHeadEntity = ((CpEntityManager)em).load(
+ new CpEntityManager.EntityScope( headEntityScope, entityId));
// commented out because it is possible that CP entity has not been created yet
Assert.notNull( cpHeadEntity, "cpHeadEntity cannot be null" );
@@ -626,12 +626,12 @@ public class CpRelationManager implements RelationManager {
applicationScope.getApplication(),
applicationScope.getApplication(),
CpNamingUtils.getCollectionScopeNameFromEntityType( itemRef.getType() ) );
-
EntityCollectionManager memberMgr = managerCache.getEntityCollectionManager( memberScope );
//TODO, this double load should disappear once events are in
- org.apache.usergrid.persistence.model.entity.Entity memberEntity = memberMgr.load(
- new SimpleId( itemRef.getUuid(), itemRef.getType() ) ).toBlocking().last();
+ Id entityId = new SimpleId( itemRef.getUuid(), itemRef.getType() );
+ org.apache.usergrid.persistence.model.entity.Entity memberEntity =
+ ((CpEntityManager)em).load( new CpEntityManager.EntityScope( memberScope, entityId));
if ( memberEntity == null ) {
throw new RuntimeException(
@@ -796,8 +796,9 @@ public class CpRelationManager implements RelationManager {
});
}
- org.apache.usergrid.persistence.model.entity.Entity memberEntity = memberMgr.load(
- new SimpleId( itemRef.getUuid(), itemRef.getType() ) ).toBlockingObservable().last();
+ Id entityId = new SimpleId( itemRef.getUuid(), itemRef.getType() );
+ org.apache.usergrid.persistence.model.entity.Entity memberEntity =
+ ((CpEntityManager)em).load( new CpEntityManager.EntityScope( memberScope, entityId));
final EntityIndex ei = managerCache.getEntityIndex( applicationScope );
final EntityIndexBatch batch = ei.createBatch();
@@ -1015,9 +1016,9 @@ public class CpRelationManager implements RelationManager {
});
}
- org.apache.usergrid.persistence.model.entity.Entity targetEntity = targetEcm.load(
- new SimpleId( connectedEntityRef.getUuid(), connectedEntityRef.getType() ) )
- .toBlockingObservable().last();
+ Id entityId = new SimpleId( connectedEntityRef.getUuid(), connectedEntityRef.getType());
+ org.apache.usergrid.persistence.model.entity.Entity targetEntity =
+ ((CpEntityManager)em).load( new CpEntityManager.EntityScope( targetScope, entityId));
String edgeType = CpNamingUtils.getEdgeTypeFromConnectionType( connectionType );
@@ -1240,12 +1241,12 @@ public class CpRelationManager implements RelationManager {
connectingEntityRef.getUuid(),
connectedEntityRef.getType(),
connectedEntityRef.getUuid()
- } );
+ });
}
- org.apache.usergrid.persistence.model.entity.Entity targetEntity = targetEcm.load(
- new SimpleId( connectedEntityRef.getUuid(), connectedEntityRef.getType() ) )
- .toBlockingObservable().last();
+ Id entityId = new SimpleId( connectedEntityRef.getUuid(), connectedEntityRef.getType() );
+ org.apache.usergrid.persistence.model.entity.Entity targetEntity =
+ ((CpEntityManager)em).load( new CpEntityManager.EntityScope( targetScope, entityId));
// Delete graph edge connection from head entity to member entity
Edge edge = new SimpleEdge(
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c5719654/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/EntityResults.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/EntityResults.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/EntityResults.java
index 4ce3848..b2aef93 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/EntityResults.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/EntityResults.java
@@ -67,18 +67,18 @@ public class EntityResults implements Iterable<Entity>, Iterator<Entity> {
/**
- * Advance to our next candidate so that it is avaiablel
+ * Advance to our next candidate so that it is available
*/
private void doAdvance(){
while(itr.hasNext() && next == null){
CandidateResult candidate = itr.next();
- //our candidate is > our max, we can't use it
+ // our candidate is > our max, we can't use it
if( UUIDUtils.compare( candidate.getVersion(), maxVersion ) > 0){
continue;
}
- //our candidate was too new, ignore it
+ // our candidate was too new, ignore it
next = ecm.load( candidate.getId() ).toBlocking().single();
}
}