usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sfeld...@apache.org
Subject incubator-usergrid git commit: changing how core uses index promises
Date Wed, 25 Feb 2015 18:21:13 GMT
Repository: incubator-usergrid
Updated Branches:
  refs/heads/USERGRID-273-indexbuffer a4caa7a8b -> 9d7c1bb6c


changing how core uses index promises


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

Branch: refs/heads/USERGRID-273-indexbuffer
Commit: 9d7c1bb6cc3064f67fd27c8f06412f4f47b36fa4
Parents: a4caa7a
Author: Shawn Feldman <sfeldman@apache.org>
Authored: Wed Feb 25 11:20:17 2015 -0700
Committer: Shawn Feldman <sfeldman@apache.org>
Committed: Wed Feb 25 11:20:17 2015 -0700

----------------------------------------------------------------------
 .../corepersistence/CpRelationManager.java      | 11 +++--
 .../persistence/core/future/BetterFuture.java   | 12 +++---
 .../persistence/index/EntityIndexBatch.java     |  2 +
 .../index/impl/CorePerformanceIT.java           | 44 ++++++++++----------
 .../impl/EntityConnectionIndexImplTest.java     |  6 +--
 5 files changed, 40 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9d7c1bb6/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 7be6dea..00ba390 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
@@ -29,6 +29,7 @@ import java.util.Map;
 import java.util.Set;
 import java.util.UUID;
 
+import org.apache.usergrid.persistence.core.future.BetterFuture;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.util.Assert;
@@ -441,7 +442,7 @@ public class CpRelationManager implements RelationManager {
                 } ).count().toBlocking().lastOrDefault( 0 );
 
 
-        entityIndexBatch.execute();
+        entityIndexBatch.execute().get();
 
         logger.debug( "updateContainingCollectionsAndCollections() updated {} indexes", count
);
     }
@@ -834,7 +835,7 @@ public class CpRelationManager implements RelationManager {
 
         batch.deindex( itemScope, cpHeadEntity );
 
-        batch.execute();
+        BetterFuture future = batch.execute();
 
         // remove edge from collection to item
         GraphManager gm = managerCache.getGraphManager( applicationScope );
@@ -870,9 +871,9 @@ public class CpRelationManager implements RelationManager {
                 }
             }
         }
+        future.get();
     }
 
-
     @Override
     public void copyRelationships(String srcRelationName, EntityRef dstEntityRef,
             String dstRelationName) throws Exception {
@@ -1060,13 +1061,15 @@ public class CpRelationManager implements RelationManager {
 //        batch.index( allTypesIndexScope, targetEntity );
 
 
-        batch.execute();
+        BetterFuture future = batch.execute();
 
         Keyspace ko = cass.getApplicationKeyspace( applicationId );
         Mutator<ByteBuffer> m = createMutator( ko, be );
         batchUpdateEntityConnection( m, false, connection, UUIDGenerator.newTimeUUID() );
         batchExecute( m, CassandraService.RETRY_COUNT );
 
+        future.get();
+
         return connection;
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9d7c1bb6/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/future/BetterFuture.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/future/BetterFuture.java
b/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/future/BetterFuture.java
index 6146fe8..926003c 100644
--- a/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/future/BetterFuture.java
+++ b/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/future/BetterFuture.java
@@ -22,21 +22,21 @@ import java.util.concurrent.FutureTask;
 /**
  * Future without the exception nastiness
  */
-public  class BetterFuture<T>{
-    FutureTask<T> future;
+public  class BetterFuture<T> extends FutureTask<T>{
     public BetterFuture(Callable<T> callable){
-        future = new FutureTask<>(callable);
+        super(callable);
     }
 
     public void done(){
-        future.run();
+        run();
     }
 
+    @Override
     public T get(){
         try {
-            return future.get();
+            return get();
         }catch (Exception e){
             throw new RuntimeException(e);
         }
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9d7c1bb6/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityIndexBatch.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityIndexBatch.java
b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityIndexBatch.java
index a02d0da..bf606bc 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityIndexBatch.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityIndexBatch.java
@@ -64,11 +64,13 @@ public interface EntityIndexBatch {
 
     /**
      * Execute the batch
+     * @return future to guarantee execution
      */
     public BetterFuture execute();
 
     /**
      * Execute the batch and force the refresh
+     * @return future to guarantee execution
      */
     public BetterFuture executeAndRefresh();
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9d7c1bb6/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/CorePerformanceIT.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/CorePerformanceIT.java
b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/CorePerformanceIT.java
index 6d09ccb..c1bfe38 100644
--- a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/CorePerformanceIT.java
+++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/CorePerformanceIT.java
@@ -72,12 +72,12 @@ public class CorePerformanceIT extends BaseIT {
     public static ElasticSearchResource es = new ElasticSearchResource();
 
     // max entities we will write and read
-    static int maxEntities = 10; // TODO: make this configurable when you add Chop 
+    static int maxEntities = 10; // TODO: make this configurable when you add Chop
 
     // each app will get all data
     static int appCount = 10;
 
-    // number of threads = orgCount x appCount 
+    // number of threads = orgCount x appCount
 
     // total number of records = orgCount x appCount x numRecords
 
@@ -191,14 +191,14 @@ public class CorePerformanceIT extends BaseIT {
                 count += candidateResults.size();
 
                 //cause retrieval from cassandra
-                EntityResults entityResults = new EntityResults( 
+                EntityResults entityResults = new EntityResults(
                     candidateResults, ecm, UUIDGenerator.newTimeUUID() );
 
                 while(entityResults.hasNext()){
                     entityResults.next();
                 }
 
-                log.info("Read {} reviews in {} / {} ", new Object[] { 
+                log.info("Read {} reviews in {} / {} ", new Object[] {
                     count, indexScope.getOwner(), indexScope.getName() } );
             }
         }
@@ -216,7 +216,7 @@ public class CorePerformanceIT extends BaseIT {
 
         public void run() {
 
-            CollectionScope collectionScope = new CollectionScopeImpl( 
+            CollectionScope collectionScope = new CollectionScopeImpl(
                     applicationScope.getApplication(), indexScope.getOwner(), indexScope.getName()
);
             EntityCollectionManager ecm = ecmf.createCollectionManager(collectionScope );
             EntityIndex eci = ecif.createEntityIndex(applicationScope );
@@ -232,7 +232,7 @@ public class CorePerformanceIT extends BaseIT {
 
             // create the first entry
             Entity current = new Entity(
-                new SimpleId(UUIDGenerator.newTimeUUID(), "review")); 
+                new SimpleId(UUIDGenerator.newTimeUUID(), "review"));
 
 //            Id orgId = orgAppScope.scope.getApplication();
 //            Id appId = orgAppScope.scope.getOwner();
@@ -243,54 +243,54 @@ public class CorePerformanceIT extends BaseIT {
 
             try {
                 while ( (s = br.readLine()) != null && count < maxEntities ) {
-                    
+
                     try {
-                        
+
                         if ( s.trim().equals("")) { // then we are at end of a record
-                            
+
                             // write and index current entity
                             ecm.write( current ).toBlocking().last();
 
                             entityIndexBatch.index(indexScope, current  );
-                            
+
                             if ( maxEntities < 20 ) {
                                 log.info("Index written for {}", current.getId());
                                 log.info("---");
                             }
-                            
+
                             // create the next entity
                             current = new Entity(
                                     new SimpleId(UUIDGenerator.newTimeUUID(), "review"));
-                            
+
                             count++;
                             if(count % 1000 == 0){
-                                entityIndexBatch.execute();
+                                entityIndexBatch.execute().get();
                             }
 
                             if (count % 100000 == 0) {
-                                log.info("Indexed {} reviews in {} / {} ", 
-                                    new Object[] { 
-                                        count, 
+                                log.info("Indexed {} reviews in {} / {} ",
+                                    new Object[] {
+                                        count,
                                             applicationScope,
                                         indexScope.getOwner() } );
                             }
                             continue;
                         }
-                        
+
                         // process a field
                         String name = s.substring( 0, s.indexOf(":")).replace("/", "_").toLowerCase()
;
                         String value = s.substring( s.indexOf(":") + 1 ).trim();
-                        
+
                         if ( maxEntities < 20 ) {
                             log.info("Indexing {} = {}", name, value);
                         }
-                        
+
                         if ( NumberUtils.isNumber(value) && value.contains("."))
{
                             current.setField( new DoubleField( name, Double.parseDouble(value)));
-                            
+
                         } else if ( NumberUtils.isNumber(value) ) {
                             current.setField( new LongField( name, Long.parseLong(value)));
-                            
+
                         } else {
                             current.setField( new StringField( name, value.toString() ));
                         }
@@ -306,7 +306,7 @@ public class CorePerformanceIT extends BaseIT {
 
             eci.refresh();
         }
-    }   
+    }
 
 
     public void runSelectedQueries(final ApplicationScope scope,  List<IndexScope>
indexScopes ) {

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9d7c1bb6/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityConnectionIndexImplTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityConnectionIndexImplTest.java
b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityConnectionIndexImplTest.java
index b07bd21..c65f106 100644
--- a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityConnectionIndexImplTest.java
+++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityConnectionIndexImplTest.java
@@ -136,7 +136,7 @@ public class EntityConnectionIndexImplTest extends BaseIT {
         batch.index( searchScope, oj );
         batch.index( otherIndexScope, oj );
 
-        batch.executeAndRefresh();
+        batch.executeAndRefresh().get();
         personLikesIndex.refresh();
 
 
@@ -267,7 +267,7 @@ public class EntityConnectionIndexImplTest extends BaseIT {
         batch.index( searchScope, oj );
         batch.index( otherIndexScope, oj );
 
-        batch.executeAndRefresh();
+        batch.executeAndRefresh().get();
         personLikesIndex.refresh();
 
         EsTestUtils.waitForTasks( personLikesIndex );
@@ -287,7 +287,7 @@ public class EntityConnectionIndexImplTest extends BaseIT {
         batch.deindex( searchScope, egg );
         batch.deindex( searchScope, muffin );
         batch.deindex( searchScope, oj );
-        batch.executeAndRefresh();
+        batch.executeAndRefresh().get();
 
         likes = personLikesIndex.search( searchScope,
                 SearchTypes.fromTypes( muffin.getId().getType(), egg.getId().getType(), oj.getId().getType()
),


Mime
View raw message