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

[09/13] git commit: Updated batching calls

Updated batching calls


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

Branch: refs/heads/two-dot-o
Commit: c051fdaecf3c7e86ce6188a7f56dd2310e1d1ec1
Parents: ae9974d
Author: Todd Nine <to...@apache.org>
Authored: Wed Oct 1 23:44:03 2014 -0600
Committer: Todd Nine <to...@apache.org>
Committed: Wed Oct 1 23:44:03 2014 -0600

----------------------------------------------------------------------
 .../corepersistence/CpEntityManager.java        | 55 ++++++++++++--------
 .../corepersistence/CpRelationManager.java      | 21 +++++---
 .../index/impl/EsEntityIndexImpl.java           |  7 +--
 3 files changed, 51 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c051fdae/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 5ce871b..8b8dc8d 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
@@ -626,7 +626,7 @@ public class CpEntityManager implements EntityManager {
             logger.debug( "Deleting indexes of all {} collections owning the entity", 
                     owners.keySet().size() );
 
-            final  EntityIndex ei = managerCache.getEntityIndex( appScope );
+            final  EntityIndex ei = managerCache.getEntityIndex( applicationScope );
 
             final EntityIndexBatch batch = ei.createBatch();
 
@@ -1054,7 +1054,7 @@ public class CpEntityManager implements EntityManager {
                 getCollectionScopeNameFromEntityType( entityRef.getType()) );
 
         EntityCollectionManager ecm = managerCache.getEntityCollectionManager( collectionScope );
-        EntityIndex ei = managerCache.getEntityIndex( appScope );
+        EntityIndex ei = managerCache.getEntityIndex( applicationScope );
 
         Id entityId = new SimpleId( entityRef.getUuid(), entityRef.getType() );
 
@@ -2611,12 +2611,12 @@ public class CpEntityManager implements EntityManager {
         }
 
         // Index CP entity into default collection scope
-        IndexScope defaultIndexScope = new IndexScopeImpl( 
-            applicationScope.getApplication(), 
-            applicationScope.getApplication(), 
-            CpEntityManager.getCollectionScopeNameFromEntityType( entity.getType() ) );
-        EntityIndex ei = managerCache.getEntityIndex( defaultIndexScope );
-        ei.index( cpEntity );
+//        IndexScope defaultIndexScope = new IndexScopeImpl(
+//            applicationScope.getApplication(),
+//            applicationScope.getApplication(),
+//            CpEntityManager.getCollectionScopeNameFromEntityType( entity.getType() ) );
+//        EntityIndex ei = managerCache.getEntityIndex( applicationScope );
+//        ei.createBatch().index( defaultIndexScope, cpEntity ).execute();
 
         // reflect changes in the legacy Entity
         entity.setUuid( cpEntity.getId().getUuid() );
@@ -3033,7 +3033,7 @@ public class CpEntityManager implements EntityManager {
             collName, collectionEntity.getId().getType(), collectionEntity.getId().getUuid(),
             memberEntity.getId().getType(), memberEntity.getId().getUuid() });
 
-        indexEntityIntoCollection( collectionEntity, memberEntity, collName );
+        indexEntityIntoCollection( collectionEntity, memberEntity, collName);
 
         CollectionInfo collection = getDefaultSchema()
                 .getCollection( memberEntity.getId().getType(), collName);
@@ -3053,58 +3053,71 @@ public class CpEntityManager implements EntityManager {
             org.apache.usergrid.persistence.model.entity.Entity sourceEntity,
             org.apache.usergrid.persistence.model.entity.Entity targetEntity,
             String targetEntityType,
-            String connType ) {
+            String connType) {
 
         logger.debug("Indexing into connection {} source {}:{} target {}:{}", new Object[] { 
             connType, sourceEntity.getId().getType(), sourceEntity.getId().getUuid(),
             targetEntity.getId().getType(), targetEntity.getId().getUuid() });
 
+
+        final EntityIndex ei = getManagerCache().getEntityIndex( applicationScope );
+        final EntityIndexBatch batch = ei.createBatch();
+
+
+
+
         // Index the new connection in app|source|type context
         IndexScope indexScope = new IndexScopeImpl(
                 applicationScope.getApplication(),
                 sourceEntity.getId(),
                 CpEntityManager.getConnectionScopeName(targetEntityType, connType));
-        EntityIndex ei = managerCache.getEntityIndex(indexScope);
-        ei.index(targetEntity);
+        batch.index(indexScope, targetEntity);
         
         // Index the new connection in app|scope|all-types context
         IndexScope allTypesIndexScope = new IndexScopeImpl(
                 applicationScope.getApplication(),
                 sourceEntity.getId(),
                 ALL_TYPES);
-        EntityIndex aei = managerCache.getEntityIndex(allTypesIndexScope);
-        aei.index(targetEntity);
+
+        batch.index(allTypesIndexScope, targetEntity);
+
+        batch.execute();
     }
 
 
     void indexEntityIntoCollection(
             org.apache.usergrid.persistence.model.entity.Entity collectionEntity, 
             org.apache.usergrid.persistence.model.entity.Entity memberEntity, 
-            String collName ) {
+            String collName) {
+
+        final EntityIndex ei = getManagerCache().getEntityIndex( applicationScope );
+        final EntityIndexBatch batch = ei.createBatch();
 
         // index member into entity collection | type scope
         IndexScope collectionIndexScope = new IndexScopeImpl(
                 applicationScope.getApplication(),
                 collectionEntity.getId(),
                 CpEntityManager.getCollectionScopeNameFromCollectionName(collName));
-        EntityIndex collectionIndex = managerCache.getEntityIndex(collectionIndexScope);
-        collectionIndex.index(memberEntity);
+
+        batch.index(collectionIndexScope, memberEntity);
         
         // index member into entity | all-types scope
         IndexScope entityAllTypesScope = new IndexScopeImpl(
                 applicationScope.getApplication(),
                 collectionEntity.getId(),
                 ALL_TYPES);
-        EntityIndex entityAllCollectionIndex = managerCache.getEntityIndex(entityAllTypesScope);
-        entityAllCollectionIndex.index(memberEntity);
+
+        batch.index(entityAllTypesScope, memberEntity);
         
         // index member into application | all-types scope
         IndexScope appAllTypesScope = new IndexScopeImpl(
                 applicationScope.getApplication(),
                 applicationScope.getApplication(),
                 ALL_TYPES);
-        EntityIndex allCollectionIndex = managerCache.getEntityIndex(appAllTypesScope);
-        allCollectionIndex.index(memberEntity);
+
+        batch.index(appAllTypesScope, memberEntity);
+
+        batch.execute();
     }
 }
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c051fdae/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 0073eb1..14f9359 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
@@ -16,6 +16,8 @@
 
 package org.apache.usergrid.corepersistence;
 
+import static me.prettyprint.hector.api.factory.HFactory.createMutator;
+import static org.apache.usergrid.corepersistence.CpEntityManager.*;
 import com.yammer.metrics.annotation.Metered;
 import java.nio.ByteBuffer;
 import java.util.AbstractMap;
@@ -30,6 +32,7 @@ import java.util.Map;
 import java.util.Set;
 import java.util.UUID;
 
+import org.apache.usergrid.persistence.index.EntityIndexBatch;
 import org.apache.usergrid.utils.UUIDUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -140,6 +143,11 @@ import static org.apache.usergrid.utils.UUIDUtils.getTimestampInMicros;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.util.Assert;
+
+import me.prettyprint.hector.api.Keyspace;
+import me.prettyprint.hector.api.beans.DynamicComposite;
+import me.prettyprint.hector.api.beans.HColumn;
+import me.prettyprint.hector.api.mutation.Mutator;
 import rx.Observable;
 
 
@@ -917,7 +925,7 @@ public class CpRelationManager implements RelationManager {
 
         while ( !satisfied && queryCount++ < maxQueries ) {
 
-            CandidateResults crs = ei.search( query );
+            CandidateResults crs = ei.search( indexScope, query );
 
             if ( results == null ) {
                 results = buildResults( query, crs, collName );
@@ -1009,23 +1017,24 @@ public class CpRelationManager implements RelationManager {
         GraphManager gm = managerCache.getGraphManager(applicationScope);
         gm.writeEdge(edge).toBlockingObservable().last();
 
+        EntityIndex ei = managerCache.getEntityIndex(applicationScope);
+        EntityIndexBatch batch = ei.createBatch();
+
         // Index the new connection in app|source|type context
         IndexScope indexScope = new IndexScopeImpl(
             applicationScope.getApplication(), 
             cpHeadEntity.getId(), 
             CpEntityManager.getConnectionScopeName( connectedEntityRef.getType(), connectionType ));
-        EntityIndex ei = managerCache.getEntityIndex(indexScope);
-        ei.index( targetEntity );
+
+        batch.index(indexScope, targetEntity );
 
         // Index the new connection in app|scope|all-types context
         IndexScope allTypesIndexScope = new IndexScopeImpl(
             applicationScope.getApplication(), 
             cpHeadEntity.getId(), 
             ALL_TYPES);
-        EntityIndex aei = managerCache.getEntityIndex(allTypesIndexScope);
-        aei.index( targetEntity );
+        batch.index(allTypesIndexScope,  targetEntity );
 
-        batch.index( allTypesIndexScope, targetEntity );
 
         batch.execute();
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c051fdae/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
index 7851afe..264eb1d 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
@@ -26,6 +26,7 @@ import java.util.TreeSet;
 import java.util.UUID;
 
 import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
+import org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse;
 import org.elasticsearch.action.search.SearchRequestBuilder;
 import org.elasticsearch.action.search.SearchResponse;
 import org.elasticsearch.action.search.SearchScrollRequestBuilder;
@@ -308,9 +309,5 @@ public class EsEntityIndexImpl implements EntityIndex {
     }
 
 
-    @Override
-    public void refresh() {
-        client.admin().indices().prepareRefresh( indexName ).execute().actionGet();
-        log.debug( "Refreshed index: " + indexName );
-    }
+
 }