You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by gr...@apache.org on 2015/03/23 19:30:21 UTC
[11/50] [abbrv] incubator-usergrid git commit: tests passing in
queryindex
tests passing in queryindex
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/5f75292c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/5f75292c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/5f75292c
Branch: refs/heads/USERGRID-347
Commit: 5f75292c13fbb8c8acd722ce59c014828f1619c6
Parents: b5ce085
Author: Shawn Feldman <sf...@apache.org>
Authored: Thu Mar 19 13:57:19 2015 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Thu Mar 19 13:57:19 2015 -0600
----------------------------------------------------------------------
.../corepersistence/CpEntityManager.java | 23 +++----
.../corepersistence/CpEntityManagerFactory.java | 2 +-
.../corepersistence/CpManagerCache.java | 6 +-
.../corepersistence/CpRelationManager.java | 19 +++---
.../events/EntityDeletedHandler.java | 3 +-
.../events/EntityVersionDeletedHandler.java | 3 +-
.../results/FilteringLoader.java | 3 +-
.../usergrid/persistence/EntityManager.java | 7 +--
.../cassandra/EntityManagerImpl.java | 9 +--
.../corepersistence/StaleIndexCleanupTest.java | 17 +++--
.../persistence/index/IndexIdentifier.java | 3 +
.../index/impl/EsEntityIndexImpl.java | 66 +++++++++-----------
.../persistence/index/impl/EntityIndexTest.java | 17 +++--
13 files changed, 76 insertions(+), 102 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5f75292c/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 8787410..b23111a 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
@@ -36,6 +36,7 @@ import java.util.UUID;
import com.codahale.metrics.Meter;
import org.apache.usergrid.persistence.collection.FieldSet;
import org.apache.usergrid.persistence.core.future.BetterFuture;
+import org.apache.usergrid.persistence.index.ApplicationEntityIndex;
import org.elasticsearch.action.ListenableActionFuture;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -211,6 +212,7 @@ public class CpEntityManager implements EntityManager {
private Timer entGetRepairedEntityTimer;
private Timer updateEntityTimer;
private Meter updateEntityMeter;
+ private EntityIndex ei;
// /** Short-term cache to keep us from reloading same Entity during single request. */
// private LoadingCache<EntityScope, org.apache.usergrid.persistence.model.entity.Entity> entityCache;
@@ -221,7 +223,8 @@ public class CpEntityManager implements EntityManager {
}
@Override
- public void init( EntityManagerFactory emf, UUID applicationId ) {
+ public void init( EntityManagerFactory emf, EntityIndex ei, UUID applicationId ) {
+ this.ei = ei;
Preconditions.checkNotNull( emf, "emf must not be null" );
Preconditions.checkNotNull( applicationId, "applicationId must not be null" );
@@ -286,7 +289,6 @@ public class CpEntityManager implements EntityManager {
@Override
public Health getIndexHealth() {
- EntityIndex ei = managerCache.getEntityIndex( applicationScope );
return ei.getIndexHealth();
}
@@ -1079,7 +1081,7 @@ public class CpEntityManager implements EntityManager {
getCollectionScopeNameFromEntityType( entityRef.getType() ) );
EntityCollectionManager ecm = managerCache.getEntityCollectionManager( collectionScope );
- EntityIndex ei = managerCache.getEntityIndex( getApplicationScope() );
+ ApplicationEntityIndex aei = managerCache.getEntityIndex( getApplicationScope() );
Id entityId = new SimpleId( entityRef.getUuid(), entityRef.getType() );
@@ -1106,7 +1108,7 @@ public class CpEntityManager implements EntityManager {
//Adding graphite metrics
Timer.Context timeESBatch = esDeletePropertyTimer.time();
- BetterFuture future = ei.createBatch().index( defaultIndexScope, cpEntity ).execute();
+ BetterFuture future = aei.createBatch().index( defaultIndexScope, cpEntity ).execute();
timeESBatch.stop();
// update in all containing collections and connection indexes
CpRelationManager rm = ( CpRelationManager ) getRelationManager( entityRef );
@@ -2889,24 +2891,15 @@ public class CpEntityManager implements EntityManager {
emf.refreshIndex();
// refresh this Entity Manager's application's index
- EntityIndex ei = managerCache.getEntityIndex( getApplicationScope() );
ei.refresh();
}
@Override
public void createIndex() {
- EntityIndex ei = managerCache.getEntityIndex( applicationScope );
ei.initializeIndex();
}
- public ListenableActionFuture deleteIndex(){
- EntityIndex ei = managerCache.getEntityIndex( applicationScope );
- return ei.deleteIndex();
- }
-
-
-
@Override
@@ -2981,8 +2974,8 @@ public class CpEntityManager implements EntityManager {
org.apache.usergrid.persistence.model.entity.Entity memberEntity,
String collName ) {
- final EntityIndex ei = getManagerCache().getEntityIndex( getApplicationScope() );
- final EntityIndexBatch batch = ei.createBatch();
+ final ApplicationEntityIndex aie = getManagerCache().getEntityIndex( getApplicationScope() );
+ final EntityIndexBatch batch = aie.createBatch();
// index member into entity collection | type scope
IndexScope collectionIndexScope = new IndexScopeImpl( collectionEntity.getId(),
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5f75292c/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
index e70e538..14b7865 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
@@ -199,7 +199,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
private EntityManager _getEntityManager( UUID applicationId ) {
EntityManager em = new CpEntityManager();
- em.init( this, applicationId );
+ em.init( this,entityIndex ,applicationId );
return em;
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5f75292c/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpManagerCache.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpManagerCache.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpManagerCache.java
index aa8a139..4e35f8c 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpManagerCache.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpManagerCache.java
@@ -25,6 +25,7 @@ import org.apache.usergrid.persistence.collection.EntityCollectionManagerFactory
import org.apache.usergrid.persistence.core.scope.ApplicationScope;
import org.apache.usergrid.persistence.graph.GraphManager;
import org.apache.usergrid.persistence.graph.GraphManagerFactory;
+import org.apache.usergrid.persistence.index.ApplicationEntityIndex;
import org.apache.usergrid.persistence.index.EntityIndex;
import org.apache.usergrid.persistence.index.EntityIndexFactory;
import org.apache.usergrid.persistence.map.MapManager;
@@ -62,16 +63,15 @@ public class CpManagerCache implements ManagerCache {
@Override
public EntityCollectionManager getEntityCollectionManager( CollectionScope scope ) {
-
//cache is now in the colletion manager level
return ecmf.createCollectionManager( scope );
}
@Override
- public EntityIndex getEntityIndex( ApplicationScope appScope ) {
+ public ApplicationEntityIndex getEntityIndex( ApplicationScope appScope ) {
- return eif.createEntityIndex( appScope );
+ return eif.createApplicationEntityIndex( appScope );
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5f75292c/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 2eeee28..df01c47 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
@@ -30,6 +30,7 @@ import java.util.Set;
import java.util.UUID;
import org.apache.usergrid.persistence.core.future.BetterFuture;
+import org.apache.usergrid.persistence.index.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.Assert;
@@ -75,10 +76,6 @@ import org.apache.usergrid.persistence.graph.impl.SimpleEdge;
import org.apache.usergrid.persistence.graph.impl.SimpleSearchByEdge;
import org.apache.usergrid.persistence.graph.impl.SimpleSearchByEdgeType;
import org.apache.usergrid.persistence.graph.impl.SimpleSearchEdgeType;
-import org.apache.usergrid.persistence.index.EntityIndex;
-import org.apache.usergrid.persistence.index.EntityIndexBatch;
-import org.apache.usergrid.persistence.index.IndexScope;
-import org.apache.usergrid.persistence.index.SearchTypes;
import org.apache.usergrid.persistence.index.impl.IndexScopeImpl;
import org.apache.usergrid.persistence.index.query.CandidateResult;
import org.apache.usergrid.persistence.index.query.CandidateResults;
@@ -397,7 +394,7 @@ public class CpRelationManager implements RelationManager {
// loop through all types of edge to target
- final EntityIndex ei = managerCache.getEntityIndex( applicationScope );
+ final ApplicationEntityIndex ei = managerCache.getEntityIndex(applicationScope);
final EntityIndexBatch entityIndexBatch = ei.createBatch();
@@ -828,7 +825,7 @@ public class CpRelationManager implements RelationManager {
org.apache.usergrid.persistence.model.entity.Entity memberEntity =
((CpEntityManager)em).load( new CpEntityManager.EntityScope( memberScope, entityId));
- final EntityIndex ei = managerCache.getEntityIndex( applicationScope );
+ final ApplicationEntityIndex ei = managerCache.getEntityIndex( applicationScope );
final EntityIndexBatch batch = ei.createBatch();
// remove item from collection index
@@ -945,7 +942,7 @@ public class CpRelationManager implements RelationManager {
cpHeadEntity.getId(),
CpNamingUtils.getCollectionScopeNameFromCollectionName( collName ) );
- final EntityIndex ei = managerCache.getEntityIndex( applicationScope );
+ final ApplicationEntityIndex ei = managerCache.getEntityIndex( applicationScope );
final SearchTypes types = SearchTypes.fromTypes( collection.getType() );
@@ -1060,7 +1057,7 @@ public class CpRelationManager implements RelationManager {
GraphManager gm = managerCache.getGraphManager( applicationScope );
gm.writeEdge( edge ).toBlockingObservable().last();
- EntityIndex ei = managerCache.getEntityIndex( applicationScope );
+ ApplicationEntityIndex ei = managerCache.getEntityIndex( applicationScope );
EntityIndexBatch batch = ei.createBatch();
// Index the new connection in app|source|type context
@@ -1292,7 +1289,7 @@ public class CpRelationManager implements RelationManager {
GraphManager gm = managerCache.getGraphManager( applicationScope );
gm.deleteEdge( edge ).toBlockingObservable().last();
- final EntityIndex ei = managerCache.getEntityIndex( applicationScope );
+ final ApplicationEntityIndex ei = managerCache.getEntityIndex( applicationScope );
final EntityIndexBatch batch = ei.createBatch();
// Deindex the connection in app|source|type context
@@ -1372,7 +1369,7 @@ public class CpRelationManager implements RelationManager {
final SearchTypes searchTypes = SearchTypes.fromNullableTypes( connectedEntityType );
- final EntityIndex ei = managerCache.getEntityIndex( applicationScope );
+ final ApplicationEntityIndex ei = managerCache.getEntityIndex( applicationScope );
logger.debug("Searching connected entities from scope {}:{}",
@@ -1465,7 +1462,7 @@ public class CpRelationManager implements RelationManager {
final SearchTypes searchTypes = SearchTypes.fromNullableTypes( query.getEntityType() );
- EntityIndex ei = managerCache.getEntityIndex( applicationScope );
+ ApplicationEntityIndex ei = managerCache.getEntityIndex( applicationScope );
logger.debug( "Searching connections from the scope {}:{} with types {}", new Object[] {
indexScope.getOwner().toString(), indexScope.getName(), searchTypes
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5f75292c/stack/core/src/main/java/org/apache/usergrid/corepersistence/events/EntityDeletedHandler.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/events/EntityDeletedHandler.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/events/EntityDeletedHandler.java
index 94ef5e4..85c59da 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/events/EntityDeletedHandler.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/events/EntityDeletedHandler.java
@@ -20,6 +20,7 @@ package org.apache.usergrid.corepersistence.events;
import java.util.UUID;
+import org.apache.usergrid.persistence.index.ApplicationEntityIndex;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -70,7 +71,7 @@ public class EntityDeletedHandler implements EntityDeleted {
} );
CpEntityManagerFactory cpemf = ( CpEntityManagerFactory ) emf;
- final EntityIndex ei = cpemf.getManagerCache().getEntityIndex( scope );
+ final ApplicationEntityIndex ei = cpemf.getManagerCache().getEntityIndex( scope );
final IndexScope indexScope =
new IndexScopeImpl( new SimpleId( scope.getOwner().getUuid(), scope.getOwner().getType() ),
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5f75292c/stack/core/src/main/java/org/apache/usergrid/corepersistence/events/EntityVersionDeletedHandler.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/events/EntityVersionDeletedHandler.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/events/EntityVersionDeletedHandler.java
index c45949b..ece7562 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/events/EntityVersionDeletedHandler.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/events/EntityVersionDeletedHandler.java
@@ -29,6 +29,7 @@ import org.apache.usergrid.persistence.collection.MvccEntity;
import org.apache.usergrid.persistence.collection.MvccLogEntry;
import org.apache.usergrid.persistence.collection.event.EntityVersionDeleted;
import org.apache.usergrid.persistence.collection.serialization.SerializationFig;
+import org.apache.usergrid.persistence.index.ApplicationEntityIndex;
import org.apache.usergrid.persistence.index.EntityIndex;
import org.apache.usergrid.persistence.index.EntityIndexBatch;
import org.apache.usergrid.persistence.index.IndexScope;
@@ -85,7 +86,7 @@ public class EntityVersionDeletedHandler implements EntityVersionDeleted {
CpEntityManagerFactory cpemf = (CpEntityManagerFactory)emf;
- final EntityIndex ei = cpemf.getManagerCache().getEntityIndex( scope );
+ final ApplicationEntityIndex ei = cpemf.getManagerCache().getEntityIndex( scope );
final IndexScope indexScope = new IndexScopeImpl(
new SimpleId(scope.getOwner().getUuid(), scope.getOwner().getType()),
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5f75292c/stack/core/src/main/java/org/apache/usergrid/corepersistence/results/FilteringLoader.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/results/FilteringLoader.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/results/FilteringLoader.java
index b571f21..0a0f71a 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/results/FilteringLoader.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/results/FilteringLoader.java
@@ -30,6 +30,7 @@ import java.util.UUID;
import javax.annotation.Nullable;
+import org.apache.usergrid.persistence.index.ApplicationEntityIndex;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -82,7 +83,7 @@ public class FilteringLoader implements ResultsLoader {
this.applicationScope = applicationScope;
this.indexScope = indexScope;
- final EntityIndex index = managerCache.getEntityIndex( applicationScope );
+ final ApplicationEntityIndex index = managerCache.getEntityIndex( applicationScope );
indexBatch = index.createBatch();
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5f75292c/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java b/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java
index 2a951aa..71dcd07 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java
@@ -17,6 +17,7 @@
package org.apache.usergrid.persistence;
+import org.apache.usergrid.persistence.index.EntityIndex;
import org.apache.usergrid.persistence.index.query.Query;
import java.nio.ByteBuffer;
import java.util.Collection;
@@ -694,12 +695,8 @@ public interface EntityManager {
*/
void createIndex();
- /**
- * Create the index, should ONLY ever be called the first time an application is created
- */
- ListenableActionFuture deleteIndex();
- public void init( EntityManagerFactory emf, UUID applicationId);
+ public void init( EntityManagerFactory emf, EntityIndex entityIndex, UUID applicationId);
/** For testing purposes */
public void flushManagerCaches();
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5f75292c/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerImpl.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerImpl.java b/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerImpl.java
index 966a601..803512b 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerImpl.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerImpl.java
@@ -36,6 +36,7 @@ import java.util.UUID;
import javax.annotation.Resource;
+import org.apache.usergrid.persistence.index.EntityIndex;
import org.elasticsearch.action.ListenableActionFuture;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -214,7 +215,7 @@ public class EntityManagerImpl implements EntityManager {
@Override
- public void init(EntityManagerFactory emf, UUID applicationId) {
+ public void init(EntityManagerFactory emf, EntityIndex entityIndex, UUID applicationId) {
init( (EntityManagerFactoryImpl)emf, null, null, applicationId, false);
}
@@ -2895,12 +2896,6 @@ public class EntityManagerImpl implements EntityManager {
}
- @Override
- public ListenableActionFuture deleteIndex() {
- //no op
- return null;
- }
-
@Override
public EntityRef getGroupRoleRef( UUID ownerId, String roleName) throws Exception {
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5f75292c/stack/core/src/test/java/org/apache/usergrid/corepersistence/StaleIndexCleanupTest.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/corepersistence/StaleIndexCleanupTest.java b/stack/core/src/test/java/org/apache/usergrid/corepersistence/StaleIndexCleanupTest.java
index 1becee4..fdd230c 100644
--- a/stack/core/src/test/java/org/apache/usergrid/corepersistence/StaleIndexCleanupTest.java
+++ b/stack/core/src/test/java/org/apache/usergrid/corepersistence/StaleIndexCleanupTest.java
@@ -24,6 +24,7 @@ import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
+import org.apache.usergrid.persistence.index.*;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
@@ -46,10 +47,6 @@ import org.apache.usergrid.persistence.collection.EntityCollectionManager;
import org.apache.usergrid.persistence.collection.EntityCollectionManagerFactory;
import org.apache.usergrid.persistence.core.scope.ApplicationScope;
import org.apache.usergrid.persistence.core.scope.ApplicationScopeImpl;
-import org.apache.usergrid.persistence.index.EntityIndex;
-import org.apache.usergrid.persistence.index.EntityIndexFactory;
-import org.apache.usergrid.persistence.index.IndexScope;
-import org.apache.usergrid.persistence.index.SearchTypes;
import org.apache.usergrid.persistence.index.impl.IndexScopeImpl;
import org.apache.usergrid.persistence.index.query.CandidateResults;
import org.apache.usergrid.persistence.index.query.Query;
@@ -155,12 +152,12 @@ public class StaleIndexCleanupTest extends AbstractCoreIT {
UUID newVersion = getCpEntity( thing ).getVersion();
- assertEquals( 2, queryCollectionCp( "things", "thing", "select * order by ordinal desc" ).size() );
+ assertEquals(2, queryCollectionCp("things", "thing", "select * order by ordinal desc").size());
//now run enable events and ensure we clean up
- System.setProperty( EVENTS_DISABLED, "false" );
+ System.setProperty(EVENTS_DISABLED, "false");
- final Results results = queryCollectionEm( "things", "select * order by ordinal desc" );
+ final Results results = queryCollectionEm("things", "select * order by ordinal desc");
assertEquals( 1, results.size() );
assertEquals(1, results.getEntities().get( 0 ).getProperty( "ordinal" ));
@@ -169,9 +166,9 @@ public class StaleIndexCleanupTest extends AbstractCoreIT {
//ensure it's actually gone
final CandidateResults candidates = queryCollectionCp( "things", "thing", "select * order by ordinal desc" );
- assertEquals( 1, candidates.size() );
+ assertEquals(1, candidates.size());
- assertEquals(newVersion, candidates.get( 0 ).getVersion());
+ assertEquals(newVersion, candidates.get(0).getVersion());
}
@@ -483,7 +480,7 @@ public class StaleIndexCleanupTest extends AbstractCoreIT {
ApplicationScope as = new ApplicationScopeImpl(
new SimpleId( em.getApplicationId(), TYPE_APPLICATION ) );
- EntityIndex ei = eif.createEntityIndex( as );
+ ApplicationEntityIndex ei = eif.createApplicationEntityIndex(as);
IndexScope is = new IndexScopeImpl( new SimpleId( em.getApplicationId(), TYPE_APPLICATION ),
CpNamingUtils.getCollectionScopeNameFromCollectionName( collName ) );
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5f75292c/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexIdentifier.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexIdentifier.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexIdentifier.java
index 1ac9d49..c659ed6 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexIdentifier.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexIdentifier.java
@@ -20,12 +20,15 @@
package org.apache.usergrid.persistence.index;
+import com.google.inject.Inject;
+
/**
* Class is used to generate an index name and alias name
*/
public class IndexIdentifier{
private final IndexFig config;
+ @Inject
public IndexIdentifier(IndexFig config) {
this.config = config;
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5f75292c/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 d510a8d..e92e133 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
@@ -55,6 +55,8 @@ import org.elasticsearch.index.query.*;
import org.elasticsearch.indices.IndexAlreadyExistsException;
import org.elasticsearch.indices.IndexMissingException;
+import org.elasticsearch.indices.InvalidAliasNameException;
+import org.elasticsearch.rest.action.admin.indices.alias.delete.AliasesMissingException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -119,9 +121,6 @@ public class EsEntityIndexImpl implements AliasedEntityIndex {
this.esProvider = provider;
this.config = config;
-
-
-
this.alias = indexIdentifier.getAlias();
this.aliasCache = indexCache;
this.addTimer = metricsFactory
@@ -143,14 +142,14 @@ public class EsEntityIndexImpl implements AliasedEntityIndex {
if(indexes == null || indexes.length==0) {
addIndex(null, numberOfShards, numberOfReplicas, config.getWriteConsistencyLevel());
}
+
}
@Override
public void addIndex(final String indexSuffix,final int numberOfShards, final int numberOfReplicas, final String writeConsistency) {
- String normalizedSuffix = StringUtils.isNotEmpty(indexSuffix) ? indexSuffix : null;
try {
//get index name with suffix attached
- String indexName = indexIdentifier.getIndex(normalizedSuffix);
+ String indexName = indexIdentifier.getIndex(indexSuffix);
//Create index
try {
@@ -186,12 +185,10 @@ public class EsEntityIndexImpl implements AliasedEntityIndex {
//We do NOT want to create an alias if the index already exists, we'll overwrite the indexes that
//may have been set via other administrative endpoint
- addAlias(normalizedSuffix);
+ addAlias(indexSuffix);
testNewIndex();
-
-
} catch (IndexAlreadyExistsException expected) {
// this is expected to happen if index already exists, it's a no-op and swallow
} catch (IOException e) {
@@ -202,51 +199,47 @@ public class EsEntityIndexImpl implements AliasedEntityIndex {
@Override
public void addAlias(final String indexSuffix) {
-
- final Timer.Context timeRemoveAlias = updateAliasTimer.time();
+ Timer.Context timer = updateAliasTimer.time();
try {
-
-
+ Boolean isAck;
String indexName = indexIdentifier.getIndex(indexSuffix);
final AdminClient adminClient = esProvider.getClient().admin();
- String[] indexNames = getIndexesFromEs(AliasType.Write);
-
-
- final IndicesAliasesRequestBuilder aliasesRequestBuilder = adminClient.indices().prepareAliases();
+ String[] indexNames = getIndexes(AliasType.Write);
- //remove the write alias from it's target
+ int count = 0;
+ IndicesAliasesRequestBuilder aliasesRequestBuilder = adminClient.indices().prepareAliases();
for ( String currentIndex : indexNames ) {
aliasesRequestBuilder.removeAlias( currentIndex, alias.getWriteAlias() );
- logger.info("Removing existing write Alias Name [{}] from Index [{}]", alias.getWriteAlias(), currentIndex);
+ count++;
}
+ if(count>0) {
+ isAck = aliasesRequestBuilder.execute().actionGet().isAcknowledged();
+ logger.info("Removed Index Name from Alias=[{}] ACK=[{}]", alias, isAck);
+ }
+ aliasesRequestBuilder = adminClient.indices().prepareAliases();
//Added For Graphite Metrics
-
// add read alias
- aliasesRequestBuilder.addAlias( indexName, alias.getReadAlias());
- logger.info("Created new read Alias Name [{}] on Index [{}]", alias.getReadAlias(), indexName);
-
+ aliasesRequestBuilder.addAlias(
+ indexName, alias.getReadAlias());
+ //Added For Graphite Metrics
//add write alias
- aliasesRequestBuilder.addAlias( indexName, alias.getWriteAlias() );
-
- logger.info("Created new write Alias Name [{}] on Index [{}]", alias.getWriteAlias(), indexName);
+ aliasesRequestBuilder.addAlias(
+ indexName, alias.getWriteAlias());
- final IndicesAliasesResponse result = aliasesRequestBuilder.execute().actionGet();
+ isAck = aliasesRequestBuilder.execute().actionGet().isAcknowledged();
- final boolean isAcknowledged = result.isAcknowledged();
+ logger.info("Created new aliases ACK=[{}]", isAck);
- if(!isAcknowledged){
- throw new RuntimeException( "Unable to add aliases to the new index. Elasticsearch did not acknowledge to the alias change for index '" + indexSuffix + "'");
- }
+ aliasCache.invalidate(alias);
+ } catch (Exception e) {
+ logger.warn("Failed to create alias ", e);
}
- finally{
- //invalidate the alias
- aliasCache.invalidate(alias);
- //stop the timer
- timeRemoveAlias.stop();
+ finally {
+ timer.stop();
}
}
@@ -255,7 +248,6 @@ public class EsEntityIndexImpl implements AliasedEntityIndex {
return aliasCache.getIndexes(alias, aliasType);
}
-
/**
* Get our index info from ES, but clear our cache first
* @param aliasType
@@ -266,8 +258,6 @@ public class EsEntityIndexImpl implements AliasedEntityIndex {
return getIndexes( aliasType );
}
-
-
/**
* Tests writing a document to a new index to ensure it's working correctly. See this post:
* http://s.apache.org/index-missing-exception
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5f75292c/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 483efb9..28c548d 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
@@ -81,22 +81,21 @@ public class EntityIndexTest extends BaseIT {
@Test
public void testIndex() throws IOException, InterruptedException {
- Id appId = new SimpleId( "application" );
+ Id appId = new SimpleId("application");
+ ei.initializeIndex();
- ApplicationScope applicationScope = new ApplicationScopeImpl( appId );
+ ApplicationScope applicationScope = new ApplicationScopeImpl(appId);
ApplicationEntityIndex entityIndex = eif.createApplicationEntityIndex(applicationScope);
-
final String entityType = "thing";
- IndexScope indexScope = new IndexScopeImpl( appId, "things" );
- final SearchTypes searchTypes = SearchTypes.fromTypes( entityType );
+ IndexScope indexScope = new IndexScopeImpl(appId, "things");
+ final SearchTypes searchTypes = SearchTypes.fromTypes(entityType);
- insertJsonBlob(entityIndex, entityType, indexScope, "/sample-large.json",101,0);
-
- ei.refresh();
+ insertJsonBlob(entityIndex, entityType, indexScope, "/sample-large.json", 101, 0);
+ ei.refresh();
- testQueries( indexScope, searchTypes, entityIndex );
+ testQueries(indexScope, searchTypes, entityIndex);
}
@Test