Removes obscelete events.
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/2e5937b0 Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/2e5937b0 Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/2e5937b0 Branch: refs/heads/USERGRID-641 Commit: 2e5937b03df7be48a0c02a277d0c03e1b9908acc Parents: d0bde18 Author: Todd Nine <[email protected]> Authored: Sun May 10 05:10:58 2015 -0600 Committer: Todd Nine <[email protected]> Committed: Sun May 10 05:10:58 2015 -0600 ---------------------------------------------------------------------- .../usergrid/corepersistence/CoreModule.java | 22 +-- .../events/EntityDeletedHandler.java | 81 ----------- .../events/EntityVersionCreatedHandler.java | 83 ----------- .../events/EntityVersionDeletedHandler.java | 142 ------------------- 4 files changed, 2 insertions(+), 326 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2e5937b0/stack/core/src/main/java/org/apache/usergrid/corepersistence/CoreModule.java ---------------------------------------------------------------------- diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CoreModule.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CoreModule.java index d7038cd..f1e1596 100644 --- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CoreModule.java +++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CoreModule.java @@ -18,14 +18,11 @@ package org.apache.usergrid.corepersistence; import org.safehaus.guicyfig.GuicyFigModule; -import org.apache.usergrid.corepersistence.events.EntityDeletedHandler; -import org.apache.usergrid.corepersistence.events.EntityVersionCreatedHandler; -import org.apache.usergrid.corepersistence.events.EntityVersionDeletedHandler; -import org.apache.usergrid.corepersistence.asyncevents.AsyncIndexProvider; import org.apache.usergrid.corepersistence.asyncevents.AsyncEventService; +import org.apache.usergrid.corepersistence.asyncevents.AsyncIndexProvider; +import org.apache.usergrid.corepersistence.index.IndexProcessorFig; import org.apache.usergrid.corepersistence.index.IndexService; import org.apache.usergrid.corepersistence.index.IndexServiceImpl; -import org.apache.usergrid.corepersistence.index.IndexProcessorFig; import org.apache.usergrid.corepersistence.migration.AppInfoMigrationPlugin; import org.apache.usergrid.corepersistence.migration.CoreMigration; import org.apache.usergrid.corepersistence.migration.CoreMigrationPlugin; @@ -38,9 +35,6 @@ import org.apache.usergrid.corepersistence.rx.impl.AllEntitiesInSystemImpl; import org.apache.usergrid.corepersistence.rx.impl.AllEntityIdsObservable; import org.apache.usergrid.corepersistence.rx.impl.AllEntityIdsObservableImpl; import org.apache.usergrid.corepersistence.rx.impl.AllNodesInGraphImpl; -import org.apache.usergrid.persistence.collection.event.EntityDeleted; -import org.apache.usergrid.persistence.collection.event.EntityVersionCreated; -import org.apache.usergrid.persistence.collection.event.EntityVersionDeleted; import org.apache.usergrid.persistence.collection.guice.CollectionModule; import org.apache.usergrid.persistence.collection.serialization.impl.migration.EntityIdScope; import org.apache.usergrid.persistence.core.guice.CommonModule; @@ -111,18 +105,6 @@ public class CoreModule extends AbstractModule { bind(ManagerCache.class).to( CpManagerCache.class ); bind(ApplicationIdCacheFactory.class); - Multibinder<EntityDeleted> entityBinder = - Multibinder.newSetBinder(binder(), EntityDeleted.class); - entityBinder.addBinding().to(EntityDeletedHandler.class); - - Multibinder<EntityVersionDeleted> versionBinder = - Multibinder.newSetBinder(binder(), EntityVersionDeleted.class); - versionBinder.addBinding().to(EntityVersionDeletedHandler.class); - - Multibinder<EntityVersionCreated> versionCreatedMultibinder = - Multibinder.newSetBinder( binder(), EntityVersionCreated.class ); - versionCreatedMultibinder.addBinding().to(EntityVersionCreatedHandler.class); - /** * Create our migrations for within our core plugin http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2e5937b0/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 deleted file mode 100644 index 2de69ed..0000000 --- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/events/EntityDeletedHandler.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. The ASF licenses this file to You - * under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. For additional information regarding - * copyright in this work, please see the NOTICE file in the top level - * directory of this distribution. - */ -package org.apache.usergrid.corepersistence.events; - - -import java.util.UUID; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import org.apache.usergrid.persistence.EntityManagerFactory; -import org.apache.usergrid.persistence.collection.event.EntityDeleted; -import org.apache.usergrid.persistence.core.scope.ApplicationScope; -import org.apache.usergrid.persistence.model.entity.Id; - -import com.google.inject.Inject; -import com.google.inject.Singleton; - -import static org.apache.usergrid.corepersistence.CoreModule.EVENTS_DISABLED; - - -/** - * Delete all Query Index indexes associated with an Entity that has just been deleted. - */ -@Singleton -public class EntityDeletedHandler implements EntityDeleted { - private static final Logger logger = LoggerFactory.getLogger( EntityDeletedHandler.class ); - - - @Inject - public EntityDeletedHandler( ) {} - - - @Override - public void deleted( ApplicationScope scope, Id entityId, UUID version ) { - - // This check is for testing purposes and for a test that to be able to dynamically turn - // off and on delete previous versions so that it can test clean-up on read. - if ( System.getProperty( EVENTS_DISABLED, "false" ).equals( "true" ) ) { - return; - } - -// This is a NO-OP now, it's handled by the EntityVersionDeletedHandler - -// -// if(logger.isDebugEnabled()) { -// logger.debug( -// "Handling deleted event for entity {}:{} v {} " + " app: {}", -// new Object[] { -// entityId.getType(), entityId.getUuid(), version, -// scope.getApplication() -// } ); -// } -// -// CpEntityManagerFactory cpemf = ( CpEntityManagerFactory ) emf; -// final ApplicationEntityIndex ei = cpemf.getManagerCache().getEntityIndex( scope ); - -// throw new NotImplementedException( "Fix this" ); - - //read all edges to this node and de-index them - - - -// ei.createBatch().deindex( indexScope, entityId, version ).execute(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2e5937b0/stack/core/src/main/java/org/apache/usergrid/corepersistence/events/EntityVersionCreatedHandler.java ---------------------------------------------------------------------- diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/events/EntityVersionCreatedHandler.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/events/EntityVersionCreatedHandler.java deleted file mode 100644 index 20bdd55..0000000 --- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/events/EntityVersionCreatedHandler.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. The ASF licenses this file to You - * under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. For additional information regarding - * copyright in this work, please see the NOTICE file in the top level - * directory of this distribution. - */ -package org.apache.usergrid.corepersistence.events; - - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import org.apache.usergrid.persistence.EntityManagerFactory; -import org.apache.usergrid.persistence.collection.EntityCollectionManagerFactory; -import org.apache.usergrid.persistence.collection.event.EntityVersionCreated; -import org.apache.usergrid.persistence.core.scope.ApplicationScope; -import org.apache.usergrid.persistence.model.entity.Entity; - -import com.google.inject.Inject; -import com.google.inject.Singleton; - - -/** - * Clean up stale entity indexes when new version of Entity created. Called when an Entity is - * updated by the Collections module and we react by calling the Query Index module and removing - * any indexes that exist for previous versions of the the Entity. - */ -@Singleton -public class EntityVersionCreatedHandler implements EntityVersionCreated { - private static final Logger logger = LoggerFactory.getLogger(EntityVersionCreatedHandler.class ); - - - - - @Inject - public EntityVersionCreatedHandler( ) { - - } - - - @Override - public void versionCreated( final ApplicationScope scope, final Entity entity ) { - //not op, we're not migrating properly to this. Make this an event At the moment this is happening on write - -// // This check is for testing purposes and for a test that to be able to dynamically turn -// // off and on delete previous versions so that it can test clean-up on read. -// if ( System.getProperty( EVENTS_DISABLED, "false" ).equals( "true" )) { -// return; -// } -// -// logger.debug("Handling versionCreated for entity {}:{} v {} " -// + "scope\n name: {}\n owner: {}\n app: {}", -// new Object[] { -// entity.getId().getType(), -// entity.getId().getUuid(), -// entity.getVersion(), -// scope.getName(), -// scope.getOwner(), -// scope.getApplication()}); -// -// CpEntityManagerFactory cpemf = (CpEntityManagerFactory)emf; -// final EntityIndex ei = cpemf.getManagerCache().getEntityIndex(scope); -// -// -// -// -// -// - -// ei.deletePreviousVersions( entity.getId(), entity.getVersion() ); - } -} http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2e5937b0/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 deleted file mode 100644 index 0e12e85..0000000 --- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/events/EntityVersionDeletedHandler.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. The ASF licenses this file to You - * under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. For additional information regarding - * copyright in this work, please see the NOTICE file in the top level - * directory of this distribution. - */ -package org.apache.usergrid.corepersistence.events; - - -import java.util.List; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -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.core.scope.ApplicationScope; -import org.apache.usergrid.persistence.graph.GraphManager; -import org.apache.usergrid.persistence.graph.GraphManagerFactory; -import org.apache.usergrid.persistence.graph.serialization.EdgesObservable; -import org.apache.usergrid.persistence.index.ApplicationEntityIndex; -import org.apache.usergrid.persistence.index.EntityIndexBatch; -import org.apache.usergrid.persistence.index.EntityIndexFactory; -import org.apache.usergrid.persistence.index.IndexEdge; -import org.apache.usergrid.persistence.model.entity.Id; - -import com.google.inject.Inject; -import com.google.inject.Singleton; - -import rx.Observable; - -import static org.apache.usergrid.corepersistence.CoreModule.EVENTS_DISABLED; -import static org.apache.usergrid.corepersistence.util.CpNamingUtils.generateScopeFromSource; -import static org.apache.usergrid.corepersistence.util.CpNamingUtils.generateScopeFromTarget; - - -/** - * Remove Entity index when specific version of Entity is deleted. TODO: do we need this? Don't our version-created and - * entity-deleted handlers take care of this? If we do need it then it should be wired in via GuiceModule in the - * corepersistence package. - */ -@Singleton -public class EntityVersionDeletedHandler implements EntityVersionDeleted { - private static final Logger logger = LoggerFactory.getLogger( EntityVersionDeletedHandler.class ); - - - private final EdgesObservable edgesObservable; - private final SerializationFig serializationFig; - private final EntityIndexFactory entityIndexFactory; - private final GraphManagerFactory graphManagerFactory; - - - @Inject - public EntityVersionDeletedHandler( final EdgesObservable edgesObservable, final SerializationFig serializationFig, - final EntityIndexFactory entityIndexFactory, - final GraphManagerFactory graphManagerFactory ) { - this.edgesObservable = edgesObservable; - this.serializationFig = serializationFig; - this.entityIndexFactory = entityIndexFactory; - this.graphManagerFactory = graphManagerFactory; - } - - - @Override - public void versionDeleted( final ApplicationScope scope, final Id entityId, - final List<MvccLogEntry> entityVersions ) { - - - // This check is for testing purposes and for a test that to be able to dynamically turn - // off and on delete previous versions so that it can test clean-up on read. - if ( System.getProperty( EVENTS_DISABLED, "false" ).equals( "true" ) ) { - return; - } - - if ( logger.isDebugEnabled() ) { - logger.debug( "Handling versionDeleted count={} event for entity {}:{} v {} " + " app: {}", new Object[] { - entityVersions.size(), entityId.getType(), entityId.getUuid(), scope.getApplication() - } ); - } - - final ApplicationEntityIndex ei = entityIndexFactory.createApplicationEntityIndex( scope ); - final GraphManager gm = graphManagerFactory.createEdgeManager( scope ); - - - //create an observable of all scopes to deIndex - //remove all indexes pointing to this - final Observable<IndexEdge> targetScopes = edgesObservable.edgesToTarget( gm, entityId ).map( - edge -> generateScopeFromSource( edge) ); - - - //Remove all double indexes - final Observable<IndexEdge> sourceScopes = edgesObservable.edgesFromSourceAscending( gm, entityId ).map( - edge -> generateScopeFromTarget( edge ) ); - - - //create a stream of scopes - final Observable<IndexScopeVersion> versions = Observable.merge( targetScopes, sourceScopes ).flatMap( - indexScope -> Observable.from( entityVersions ) - .map( version -> new IndexScopeVersion( indexScope, version ) ) ); - - //create a set of batches - final Observable<EntityIndexBatch> batches = versions.buffer( serializationFig.getBufferSize() ).flatMap( - bufferedVersions -> Observable.from( bufferedVersions ).collect( () -> ei.createBatch(), - ( EntityIndexBatch batch, IndexScopeVersion version ) -> { - //deindex in this batch - batch.deindex( version.scope, version.version.getEntityId(), version.version.getVersion() ); - } ) ); - - - - //execute the batches - batches.doOnNext( batch -> batch.execute() ).toBlocking().lastOrDefault(null); - - } - - - - - - private static final class IndexScopeVersion{ - private final IndexEdge scope; - private final MvccLogEntry version; - - - private IndexScopeVersion( final IndexEdge scope, final MvccLogEntry version ) { - this.scope = scope; - this.version = version; - } - } -}
