You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by sf...@apache.org on 2014/10/10 17:50:43 UTC

[36/43] git commit: Fixes bug in results loader

Fixes bug in results loader

Fixes system setup


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

Branch: refs/heads/two-dot-o-events
Commit: 62da6cf042d93d6da9c3c598ed07305541236601
Parents: de88712
Author: Todd Nine <to...@apache.org>
Authored: Thu Oct 9 18:32:18 2014 -0600
Committer: Todd Nine <to...@apache.org>
Committed: Thu Oct 9 18:32:18 2014 -0600

----------------------------------------------------------------------
 .../corepersistence/CpEntityManager.java        | 50 ++++++++++++--------
 .../results/FilteringLoader.java                | 14 +++---
 2 files changed, 38 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/62da6cf0/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 49b7d25..de68c24 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
@@ -810,12 +810,12 @@ public class CpEntityManager implements EntityManager {
 
         String propertyName = Schema.getDefaultSchema().aliasProperty( collName );
 
-        Map<String, EntityRef> results = new HashMap<String, EntityRef>();
+        Map<String, EntityRef> results = new HashMap<>();
 
         for ( String alias : aliases ) {
 
             Iterable<EntityRef> refs = 
-                    getEntityRefsForUniqueProperty( ownerRef, collName, propertyName, alias );
+                    getEntityRefsForUniqueProperty( collName, propertyName, alias );
 
             for ( EntityRef ref : refs ) {
                 results.put( alias, ref );
@@ -826,25 +826,18 @@ public class CpEntityManager implements EntityManager {
     }
 
 
-    private Iterable<EntityRef> getEntityRefsForUniqueProperty( 
-            EntityRef ownerRef, String collName, String propName, String alias ) throws Exception {
+    private Iterable<EntityRef> getEntityRefsForUniqueProperty( String collName, String propName,
+                                                                String alias ) throws Exception {
 
 
-        final CollectionScope collectionScope = new CollectionScopeImpl(
-                applicationScope.getApplication(),
-                new SimpleId(ownerRef.getUuid(), ownerRef.getType()),
-                collName );
-
-
-        final EntityCollectionManager ecm = managerCache.getEntityCollectionManager( collectionScope );
-
-        final Id results = ecm.getIdField( new StringField(propName, alias) ).toBlocking().lastOrDefault( null );
+        final Id id = getIdForUniqueEntityField( collName, propName, alias );
 
-        if(results == null){
+        if ( id == null ) {
             return Collections.emptyList();
         }
 
-        return Collections.<EntityRef>singleton( new SimpleEntityRef( results.getType(),  results.getUuid() ));
+
+        return Collections.<EntityRef>singleton( new SimpleEntityRef( id.getType(), id.getUuid() ) );
     }
 
 
@@ -2198,12 +2191,29 @@ public class CpEntityManager implements EntityManager {
             String entityType, String propertyName, Object propertyValue )
             throws Exception {
 
-        Results results= this.searchCollection(
-                getApplication(), 
-                Schema.defaultCollectionName( entityType), 
-                Query.searchForProperty(propertyName, propertyValue));
 
-        return results.isEmpty();
+
+        return getIdForUniqueEntityField( entityType, propertyName, propertyValue ) == null;
+    }
+
+
+    /**
+     * Load the unique property for the field
+     */
+    private Id getIdForUniqueEntityField( final String collectionName, final String propertyName,
+                                          final Object propertyValue ) {
+        CollectionScope collectionScope =
+                new CollectionScopeImpl( applicationScope.getApplication(), applicationScope.getApplication(),
+                        CpNamingUtils.getCollectionScopeNameFromEntityType( collectionName ) );
+
+
+        final EntityCollectionManager ecm = managerCache.getEntityCollectionManager( collectionScope );
+
+        //convert to a string, that's what we store
+        final Id results = ecm.getIdField( new StringField( propertyName, propertyValue.toString() ) ).toBlocking()
+                              .lastOrDefault( null );
+
+        return results;
     }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/62da6cf0/stack/core/src/main/java/org/apache/usergrid/corepersistence/results/FilteringLoader.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/results/FilteringLoader.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/results/FilteringLoader.java
index 8348832..40ff10d 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/results/FilteringLoader.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/results/FilteringLoader.java
@@ -123,9 +123,9 @@ public class FilteringLoader implements ResultsLoader {
 
             //if we've already seen this one, put which ever is greater
 
-            final CandidateResult seen = idResultMapping.get( entityId );
+            final CandidateResult previousMax = idResultMapping.get( entityId );
 
-            if ( seen == null ) {
+            if ( previousMax == null ) {
                 idResultMapping.put( entityId, cr );
                 orderIndex.put( entityId, i );
                 groupedByScopes.put( collectionType, cr );
@@ -133,19 +133,21 @@ public class FilteringLoader implements ResultsLoader {
 
             //we have seen it, compare them
             else {
-                final UUID seenVersion = seen.getVersion();
+
+                final UUID previousMaxVersion = previousMax.getVersion();
+
                 final UUID currentVersion = cr.getVersion();
 
                 //this is a newer version, we know we already have a stale entity, add it to be cleaned up
-                if ( UUIDComparator.staticCompare( currentVersion, seenVersion ) > 0 ) {
+                if ( UUIDComparator.staticCompare( currentVersion, previousMaxVersion ) > 0 ) {
 
                     //de-index it
                     logger.debug( "Stale version of Entity uuid:{} type:{}, stale v:{}, latest v:{}", new Object[] {
-                            entityId.getUuid(), entityId.getType(), seen, currentVersion
+                            entityId.getUuid(), entityId.getType(), previousMax, currentVersion
                     } );
 
                     //deindex
-                    deIndex( indexBatch, ownerId, cr );
+                    deIndex( indexBatch, ownerId, previousMax );
 
 
                     //TODO, fire the entity repair cleanup task here instead of de-indexing