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/16 23:11:52 UTC

git commit: Adds explicit refresh after create to ensure the index is actually ready to receive data.

Repository: incubator-usergrid
Updated Branches:
  refs/heads/index-rebuild f24f3ea7c -> 54b9a1197


Adds explicit refresh after create to ensure the index is actually ready to receive data.


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

Branch: refs/heads/index-rebuild
Commit: 54b9a1197edc6498629f3bdb78f95408c24c566d
Parents: f24f3ea
Author: Todd Nine <to...@apache.org>
Authored: Thu Oct 16 15:11:45 2014 -0600
Committer: Todd Nine <to...@apache.org>
Committed: Thu Oct 16 15:11:45 2014 -0600

----------------------------------------------------------------------
 .../index/impl/EsEntityIndexImpl.java           | 23 ++++++++++++++++++++
 1 file changed, 23 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/54b9a119/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 e55f7e0..495b9e1 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
@@ -87,6 +87,9 @@ public class EsEntityIndexImpl implements EntityIndex {
 
     private final IndexFig config;
 
+    private static final int MAX_WAITS = 10;
+    private static final int WAIT_TIME = 250;
+
 
     @Inject
     public EsEntityIndexImpl( @Assisted final ApplicationScope appScope, final IndexFig config,
@@ -120,6 +123,26 @@ public class EsEntityIndexImpl implements EntityIndex {
                 response = admin.indices().prepareRefresh( indexName ).execute().actionGet();
             }
             while ( response.getFailedShards() != 0 );
+
+            //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{
+                    refresh();
+                    break;
+
+                }catch(Exception e){
+                   log.error( "Unable to refresh index after create. Waiting before sleeping.", e );
+                }
+
+                try {
+                    Thread.sleep( WAIT_TIME );
+                }
+                catch ( InterruptedException e ) {
+                    //swallow it
+                }
+            }
+
             //
             //            response.getFailedShards();
             //