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/17 18:35:28 UTC

[41/49] Fixed index refresh issue.

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c31c553f/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpWalker.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpWalker.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpWalker.java
index d491d3d..908e6bc 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpWalker.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpWalker.java
@@ -80,6 +80,7 @@ public class CpWalker {
                         applicationScope.getApplication().getUuid()
                 } );
 
+        //only search edge types that start with collections
         Observable<String> edgeTypes = gm.getEdgeTypesFromSource(
                 new SimpleSearchEdgeType( fromEntityId, CpNamingUtils.EDGE_COLL_SUFFIX, null ) );
 
@@ -100,16 +101,16 @@ public class CpWalker {
             @Override
             public void call( Edge edge ) {
 
-                EntityRef sourceEntityRef =
-                        new SimpleEntityRef( edge.getSourceNode().getType(), edge.getSourceNode().getUuid() );
+                EntityRef targetNodeEntityRef =
+                        new SimpleEntityRef( edge.getTargetNode().getType(), edge.getTargetNode().getUuid() );
 
                 Entity entity;
                 try {
-                    entity = em.get( sourceEntityRef );
+                    entity = em.get( targetNodeEntityRef );
                 }
                 catch ( Exception ex ) {
-                    logger.error( "Error getting sourceEntity {}:{}, continuing", sourceEntityRef.getType(),
-                            sourceEntityRef.getUuid() );
+                    logger.error( "Error getting sourceEntity {}:{}, continuing", targetNodeEntityRef.getType(),
+                            targetNodeEntityRef.getUuid() );
                     return;
                 }
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c31c553f/stack/core/src/test/java/org/apache/usergrid/persistence/PerformanceEntityRebuildIndexTest.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/persistence/PerformanceEntityRebuildIndexTest.java b/stack/core/src/test/java/org/apache/usergrid/persistence/PerformanceEntityRebuildIndexTest.java
index d2f7fef..2ef65ef 100644
--- a/stack/core/src/test/java/org/apache/usergrid/persistence/PerformanceEntityRebuildIndexTest.java
+++ b/stack/core/src/test/java/org/apache/usergrid/persistence/PerformanceEntityRebuildIndexTest.java
@@ -213,6 +213,7 @@ public class PerformanceEntityRebuildIndexTest extends AbstractCoreIT {
 //            setup.getEmf().refreshIndex();
             setup.getEmf().rebuildAllIndexes( po );
 
+            reporter.report();
             registry.remove( meterName );
             logger.info("Rebuilt index");
 
@@ -236,7 +237,6 @@ public class PerformanceEntityRebuildIndexTest extends AbstractCoreIT {
 
         Id appId = new SimpleId( appUuid, "application");
         ApplicationScope scope = new ApplicationScopeImpl( appId );
-        IndexScope is = new IndexScopeImpl( appId, "application");
         EntityIndex ei = eif.createEntityIndex(scope);
         EsEntityIndexImpl eeii = (EsEntityIndexImpl)ei;
 
@@ -247,6 +247,7 @@ public class PerformanceEntityRebuildIndexTest extends AbstractCoreIT {
     private int readData( String collectionName, int expected ) throws Exception {
 
         EntityManager em = app.getEntityManager();
+        em.refreshIndex();
 
         Query q = Query.fromQL("select * where key1=1000");
         q.setLimit(40);

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c31c553f/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 9ea14a1..821f7b9 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
@@ -116,7 +116,7 @@ public class EsEntityIndexImpl implements EntityIndex {
 
             AdminClient admin = client.admin();
             CreateIndexResponse cir = admin.indices().prepareCreate( indexName ).execute().actionGet();
-            log.debug( "Created new Index Name [{}] ACK=[{}]", indexName, cir.isAcknowledged() );
+            log.info( "Created new Index Name [{}] ACK=[{}]", indexName, cir.isAcknowledged() );
 
             RefreshResponse response;
 
@@ -128,11 +128,11 @@ public class EsEntityIndexImpl implements EntityIndex {
             /**
              * Immediately refresh to ensure the entire cluster is ready to receive this write.  Occasionally we see
              * errors.  See this post.
-             * http://elasticsearch-users.115913.n3.nabble.com/IndexMissingException-on-create-index-followed-by-refresh-td1832793.html
+             * http://elasticsearch-users.115913.n3.nabble
+             * .com/IndexMissingException-on-create-index-followed-by-refresh-td1832793.html
              *
              */
             refresh();
-
         }
         catch ( IndexAlreadyExistsException expected ) {
             // this is expected to happen if index already exists, it's a no-op and swallow
@@ -272,25 +272,33 @@ public class EsEntityIndexImpl implements EntityIndex {
 
     public void refresh() {
 
-            //now try to refresh, to ensure that it's recognized by everyone.  Occasionally we can get a success
-            //before we can write.
-            for(int i = 0 ; i < MAX_WAITS; i++ ){
-                try{
-                    client.admin().indices().prepareRefresh( indexName ).execute().actionGet();
-                    break;
 
-                }catch(IndexMissingException e){
-                   log.error( "Unable to refresh index after create. Waiting before sleeping.", e );
-                }
+        log.info( "Refreshing Created new Index Name [{}]", indexName );
 
-                try {
-                    Thread.sleep( WAIT_TIME );
-                }
-                catch ( InterruptedException e ) {
-                    //swallow it
-                }
+        //now try to refresh, to ensure that it's recognized by everyone.  Occasionally we can get a success
+        //before we can write.
+        for ( int i = 0; i < MAX_WAITS; i++ ) {
+            try {
+                client.admin().indices().prepareRefresh( indexName ).execute().actionGet();
+                return;
+            }
+            catch ( IndexMissingException e ) {
+                log.error( "Unable to refresh index after create. Waiting before sleeping.", e );
             }
 
+            try {
+                Thread.sleep( WAIT_TIME );
+            }
+            catch ( InterruptedException e ) {
+                //swallow it
+            }
+        }
+
+        /**
+         * Try the refresh one last time if we get here
+         */
+        client.admin().indices().prepareRefresh( indexName ).execute().actionGet();
+
         log.debug( "Refreshed index: " + indexName );
     }