usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From toddn...@apache.org
Subject [05/13] incubator-usergrid git commit: if there is no alias then use the index
Date Wed, 10 Dec 2014 00:17:41 GMT
if there is no alias then use the index


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

Branch: refs/heads/two-dot-o
Commit: 983b20b2179f1363eebaf8cce5771d5d732b2409
Parents: 3d9137e
Author: Shawn Feldman <sfeldman@apache.org>
Authored: Mon Dec 8 10:11:11 2014 -0700
Committer: Shawn Feldman <sfeldman@apache.org>
Committed: Mon Dec 8 10:11:11 2014 -0700

----------------------------------------------------------------------
 .../index/impl/EsEntityIndexBatchImpl.java      | 33 ++++++++++++++------
 .../persistence/index/impl/EntityIndexTest.java |  7 +++--
 2 files changed, 28 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/983b20b2/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexBatchImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexBatchImpl.java
b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexBatchImpl.java
index ecc71e9..51fe63b 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexBatchImpl.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexBatchImpl.java
@@ -25,6 +25,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.UUID;
+import java.util.concurrent.atomic.AtomicInteger;
 
 import org.apache.usergrid.persistence.index.*;
 import org.elasticsearch.action.bulk.BulkItemResponse;
@@ -58,6 +59,7 @@ import org.apache.usergrid.persistence.model.field.value.EntityObject;
 import com.google.common.base.Joiner;
 import rx.Observable;
 import rx.functions.Action1;
+import rx.functions.Func1;
 import rx.schedulers.Schedulers;
 
 import static org.apache.usergrid.persistence.index.impl.IndexingUtils.ANALYZED_STRING_PREFIX;
@@ -184,16 +186,29 @@ public class EsEntityIndexBatchImpl implements EntityIndexBatch {
 
 
         log.debug( "De-indexing type {} with documentId '{}'" , entityType, indexId);
-        final String[] indexes = entityIndex.getIndexes(EntityIndex.AliasType.Read);
+        String[] indexes = entityIndex.getIndexes(EntityIndex.AliasType.Read);
+        if(indexes == null ||indexes.length == 0){
+            indexes = new String[]{indexIdentifier.getIndex(null)};
+        }
+        final AtomicInteger errorCount = new AtomicInteger();
         //get all indexes then flush everyone
-        Observable.from(indexes).subscribeOn(Schedulers.io()).forEach(new Action1<String>()
{
-            @Override
-            public void call(String index) {
-                bulkRequest.add(client.prepareDelete(index, entityType, indexId).setRefresh(refresh));
-
-            }
-        });
-
+        Observable.from(indexes).subscribeOn(Schedulers.io())
+               .map(new Func1<String, Object>() {
+                   @Override
+                   public Object call(String index) {
+                       try {
+                           bulkRequest.add(client.prepareDelete(index, entityType, indexId).setRefresh(refresh));
+                       }catch (Exception e){
+                           log.error("failed to deindex",e);
+                           errorCount.incrementAndGet();
+                       }
+                       return index;
+                   }
+               }).toBlocking().last();
+
+        if(errorCount.get()>0){
+            log.error("Failed to flush some indexes");
+        }
         log.debug( "Deindexed Entity with index id " + indexId );
 
         maybeFlush();

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/983b20b2/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityIndexTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityIndexTest.java
b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityIndexTest.java
index d00796d..47c4dbd 100644
--- a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityIndexTest.java
+++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityIndexTest.java
@@ -166,7 +166,7 @@ public class EntityIndexTest extends BaseIT {
 
         EntityIndexBatch entityIndexBatch = entityIndex.createBatch();
         entityIndexBatch.deindex(indexScope, crs.get(0));
-        entityIndexBatch.deindex(indexScope,crs.get(1));
+        entityIndexBatch.deindex(indexScope, crs.get(1));
         entityIndexBatch.executeAndRefresh();
         entityIndex.refresh();
 
@@ -248,8 +248,9 @@ public class EntityIndexTest extends BaseIT {
                 Query.fromQL( "name contains 'Ferrari*'" ) );
         assertEquals( 1, candidateResults.size() );
 
-        entityIndex.createBatch().deindex( indexScope, entity ).execute();
-
+        EntityIndexBatch batch = entityIndex.createBatch();
+        batch.deindex(indexScope, entity).execute();
+        batch.executeAndRefresh();
         entityIndex.refresh();
 
         candidateResults = entityIndex.search( indexScope, SearchTypes.fromTypes(entity.getId().getType()),
Query.fromQL( "name contains 'Ferrari*'" ) );


Mime
View raw message