Skip to content
This repository has been archived by the owner on Jan 5, 2022. It is now read-only.

Commit

Permalink
tests passing in queryindex
Browse files Browse the repository at this point in the history
  • Loading branch information
Shawn Feldman committed Mar 19, 2015
1 parent b5ce085 commit 5f75292
Show file tree
Hide file tree
Showing 13 changed files with 76 additions and 102 deletions.
Expand Up @@ -36,6 +36,7 @@
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;
Expand Down Expand Up @@ -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;
Expand All @@ -221,7 +223,8 @@ public CpEntityManager() {
}

@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" );
Expand Down Expand Up @@ -286,7 +289,6 @@ public void init( EntityManagerFactory emf, UUID applicationId ) {

@Override
public Health getIndexHealth() {
EntityIndex ei = managerCache.getEntityIndex( applicationScope );
return ei.getIndexHealth();
}

Expand Down Expand Up @@ -1079,7 +1081,7 @@ public void deleteProperty( EntityRef entityRef, String propertyName ) throws Ex
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() );

Expand All @@ -1106,7 +1108,7 @@ public void deleteProperty( EntityRef entityRef, String propertyName ) throws Ex

//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 );
Expand Down Expand Up @@ -2889,24 +2891,15 @@ public void refreshIndex() {
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
Expand Down Expand Up @@ -2981,8 +2974,8 @@ void indexEntityIntoCollection( org.apache.usergrid.persistence.model.entity.Ent
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(),
Expand Down
Expand Up @@ -199,7 +199,7 @@ public EntityManager getEntityManager(UUID applicationId) {
private EntityManager _getEntityManager( UUID applicationId ) {

EntityManager em = new CpEntityManager();
em.init( this, applicationId );
em.init( this,entityIndex ,applicationId );

return em;
}
Expand Down
Expand Up @@ -25,6 +25,7 @@
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;
Expand Down Expand Up @@ -62,16 +63,15 @@ public CpManagerCache( final EntityCollectionManagerFactory ecmf, final EntityIn

@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 );

}

Expand Down
Expand Up @@ -30,6 +30,7 @@
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;
Expand Down Expand Up @@ -75,10 +76,6 @@
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;
Expand Down Expand Up @@ -397,7 +394,7 @@ public void updateContainingCollectionAndCollectionIndexes(
// 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();

Expand Down Expand Up @@ -828,7 +825,7 @@ public void removeFromCollection( String collName, EntityRef itemRef ) throws Ex
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
Expand Down Expand Up @@ -945,7 +942,7 @@ public Results searchCollection( String collName, Query query ) throws Exception
cpHeadEntity.getId(),
CpNamingUtils.getCollectionScopeNameFromCollectionName( collName ) );

final EntityIndex ei = managerCache.getEntityIndex( applicationScope );
final ApplicationEntityIndex ei = managerCache.getEntityIndex( applicationScope );

final SearchTypes types = SearchTypes.fromTypes( collection.getType() );

Expand Down Expand Up @@ -1060,7 +1057,7 @@ public ConnectionRef createConnection( String connectionType, EntityRef connecte
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
Expand Down Expand Up @@ -1292,7 +1289,7 @@ public void deleteConnection( ConnectionRef connectionRef ) throws Exception {
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
Expand Down Expand Up @@ -1372,7 +1369,7 @@ public Results getConnectedEntities(
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 {}:{}",
Expand Down Expand Up @@ -1465,7 +1462,7 @@ public Results searchConnectedEntities( Query query ) throws Exception {

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
Expand Down
Expand Up @@ -20,6 +20,7 @@

import java.util.UUID;

import org.apache.usergrid.persistence.index.ApplicationEntityIndex;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -70,7 +71,7 @@ public void deleted( CollectionScope scope, Id entityId, UUID version ) {
} );

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() ),
Expand Down
Expand Up @@ -29,6 +29,7 @@
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;
Expand Down Expand Up @@ -85,7 +86,7 @@ public void versionDeleted( final CollectionScope scope, final Id entityId,

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()),
Expand Down
Expand Up @@ -30,6 +30,7 @@

import javax.annotation.Nullable;

import org.apache.usergrid.persistence.index.ApplicationEntityIndex;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -82,7 +83,7 @@ protected FilteringLoader(
this.applicationScope = applicationScope;
this.indexScope = indexScope;

final EntityIndex index = managerCache.getEntityIndex( applicationScope );
final ApplicationEntityIndex index = managerCache.getEntityIndex( applicationScope );

indexBatch = index.createBatch();
}
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -694,12 +695,8 @@ Mutator<ByteBuffer> batchUpdateProperties(Mutator<ByteBuffer> batch,
*/
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();
Expand Down
Expand Up @@ -36,6 +36,7 @@

import javax.annotation.Resource;

import org.apache.usergrid.persistence.index.EntityIndex;
import org.elasticsearch.action.ListenableActionFuture;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -214,7 +215,7 @@ public EntityManagerImpl() {


@Override
public void init(EntityManagerFactory emf, UUID applicationId) {
public void init(EntityManagerFactory emf, EntityIndex entityIndex, UUID applicationId) {
init( (EntityManagerFactoryImpl)emf, null, null, applicationId, false);
}

Expand Down Expand Up @@ -2895,12 +2896,6 @@ public void createIndex() {
}


@Override
public ListenableActionFuture deleteIndex() {
//no op
return null;
}


@Override
public EntityRef getGroupRoleRef( UUID ownerId, String roleName) throws Exception {
Expand Down
Expand Up @@ -24,6 +24,7 @@
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;
Expand All @@ -46,10 +47,6 @@
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;
Expand Down Expand Up @@ -155,12 +152,12 @@ public void testUpdateVersionMaxFirst() throws Exception {
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" ));
Expand All @@ -169,9 +166,9 @@ public void testUpdateVersionMaxFirst() throws Exception {

//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());
}


Expand Down Expand Up @@ -483,7 +480,7 @@ private CandidateResults queryCollectionCp(

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 ) );
Expand Down
Expand Up @@ -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;
}
Expand Down

0 comments on commit 5f75292

Please sign in to comment.