You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by sf...@apache.org on 2014/10/10 17:50:10 UTC

[03/43] git commit: Fixes rolling version bug when merge occurs.

Fixes rolling version bug when merge occurs.


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

Branch: refs/heads/two-dot-o-events
Commit: 2828e911e5888e5a2f26ff412c3182c22cbf09c2
Parents: 792b2b2
Author: Todd Nine <to...@apache.org>
Authored: Tue Oct 7 19:32:44 2014 -0600
Committer: Todd Nine <to...@apache.org>
Committed: Tue Oct 7 19:32:44 2014 -0600

----------------------------------------------------------------------
 .../impl/EntityCollectionManagerImpl.java       |  7 -----
 .../mvcc/stage/write/WriteCommit.java           |  2 ++
 .../collection/mvcc/stage/write/WriteStart.java |  4 +--
 .../persistence/collection/util/RepairUtil.java | 33 ++++++++++----------
 .../collection/EntityCollectionManagerIT.java   | 15 +++++++++
 5 files changed, 35 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2828e911/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityCollectionManagerImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityCollectionManagerImpl.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityCollectionManagerImpl.java
index 6299acb..b2b07e9 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityCollectionManagerImpl.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityCollectionManagerImpl.java
@@ -19,16 +19,11 @@
 package org.apache.usergrid.persistence.collection.impl;
 
 
-import java.util.List;
-import java.util.UUID;
-
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import org.apache.usergrid.persistence.collection.CollectionScope;
 import org.apache.usergrid.persistence.collection.EntityCollectionManager;
-import org.apache.usergrid.persistence.collection.event.EntityVersionCreated;
-import org.apache.usergrid.persistence.collection.event.EntityVersionDeleted;
 import org.apache.usergrid.persistence.collection.guice.CollectionTaskExecutor;
 import org.apache.usergrid.persistence.collection.guice.Write;
 import org.apache.usergrid.persistence.collection.guice.WriteUpdate;
@@ -44,7 +39,6 @@ import org.apache.usergrid.persistence.collection.mvcc.stage.write.WriteOptimist
 import org.apache.usergrid.persistence.collection.mvcc.stage.write.WriteStart;
 import org.apache.usergrid.persistence.collection.mvcc.stage.write.WriteUniqueVerify;
 import org.apache.usergrid.persistence.collection.service.UUIDService;
-import org.apache.usergrid.persistence.core.task.Task;
 import org.apache.usergrid.persistence.core.task.TaskExecutor;
 import org.apache.usergrid.persistence.core.util.ValidationUtils;
 import org.apache.usergrid.persistence.model.entity.Entity;
@@ -65,7 +59,6 @@ import rx.schedulers.Schedulers;
  *
  * TODO: maybe refactor the stage operations into their own classes for clarity and organization?
  *
- * @author tnine
  */
 public class EntityCollectionManagerImpl implements EntityCollectionManager {
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2828e911/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteCommit.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteCommit.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteCommit.java
index 584d7f1..82ef74c 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteCommit.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteCommit.java
@@ -93,6 +93,7 @@ public class WriteCommit implements Func1<CollectionIoEvent<MvccEntity>, Entity>
         final UUID version = mvccEntity.getVersion();
         final CollectionScope collectionScope = ioEvent.getEntityCollection();
 
+        //set the version into the entity
         EntityUtils.setVersion( mvccEntity.getEntity().get(), version );
 
         MvccValidationUtils.verifyMvccEntityWithEntity( ioEvent.getEvent() );
@@ -135,6 +136,7 @@ public class WriteCommit implements Func1<CollectionIoEvent<MvccEntity>, Entity>
                 "Failed to execute write asynchronously ", e );
         }
 
+
         return mvccEntity.getEntity().get();
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2828e911/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteStart.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteStart.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteStart.java
index 20fad0e..e2bad71 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteStart.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/write/WriteStart.java
@@ -87,9 +87,7 @@ public class WriteStart implements Func1<CollectionIoEvent<Entity>, CollectionIo
             }
 
 
-            EntityUtils.setVersion(entity, version);
-
-            //create the mvcc entity for the next stage
+          //create the mvcc entity for the next stage
             //todo, we need to create a complete or partial update here (or sooner)
 
             return new CollectionIoEvent<MvccEntity>( collectionScope, nextStage );

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2828e911/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/util/RepairUtil.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/util/RepairUtil.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/util/RepairUtil.java
index 8268d22..aac5794 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/util/RepairUtil.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/util/RepairUtil.java
@@ -39,28 +39,29 @@ public class RepairUtil {
             return null;
         }
 
-        MvccEntity mvccEntity = results.next();
+        final MvccEntity partialEntity = results.next();
         List<MvccEntity> partialEntities = new ArrayList<>();
 
         //this entity has been marked as cleared.(deleted)
         //The version exists, but does not have entity data
-        if ( !mvccEntity.getEntity().isPresent() && ( mvccEntity.getStatus() == MvccEntity.Status.DELETED
-                || mvccEntity.getStatus() == MvccEntity.Status.COMPLETE ) ) {
+        if ( !partialEntity.getEntity().isPresent() && ( partialEntity.getStatus() == MvccEntity.Status.DELETED
+                || partialEntity.getStatus() == MvccEntity.Status.COMPLETE ) ) {
             return null;
         }
 
-        if ( mvccEntity.getStatus() == MvccEntity.Status.COMPLETE ) {
-            return mvccEntity;
+        if ( partialEntity.getStatus() == MvccEntity.Status.COMPLETE ) {
+            return partialEntity;
         }
-        partialEntities.add( mvccEntity );
+
+        partialEntities.add( partialEntity );
 
 
         while ( results.hasNext() ) {
-            mvccEntity = results.next();
-            partialEntities.add( mvccEntity );
+           final MvccEntity previousEntity = results.next();
+            partialEntities.add( previousEntity );
 
-            if ( mvccEntity.getStatus() != MvccEntity.Status.PARTIAL ) {
-                return repairAndWrite( partialEntities, mvccEntity, entitySerializationStrategy, collectionScope );
+            if ( previousEntity.getStatus() != MvccEntity.Status.PARTIAL ) {
+                return repairAndWrite( partialEntities, partialEntity, entitySerializationStrategy, collectionScope );
             }
         }
         return null;
@@ -70,28 +71,28 @@ public class RepairUtil {
     /**
      * Repairs the entity then overwrites the previous entity to become the new completed entity.
      * @param partialEntities
-     * @param mvccEntity
+     * @param targetEntity The entity that should ultimately contain all merged data
      * @param entitySerializationStrategy
      * @param collectionScope
      * @return
      */
-    private static MvccEntity repairAndWrite( List<MvccEntity> partialEntities, MvccEntity mvccEntity,
+    private static MvccEntity repairAndWrite( List<MvccEntity> partialEntities, MvccEntity targetEntity,
                                               MvccEntitySerializationStrategy entitySerializationStrategy,
                                               CollectionScope collectionScope ) {
         Collections.reverse( partialEntities );
 
         //repair
-        mvccEntity = entityRepair( changeLogGenerator.getChangeLog( partialEntities.iterator(),
-                        partialEntities.get( partialEntities.size() - 1 ).getVersion() ), partialEntities, mvccEntity
+       final MvccEntity mergedEntity = entityRepair( changeLogGenerator.getChangeLog( partialEntities.iterator(),
+                        partialEntities.get( partialEntities.size() - 1 ).getVersion() ), partialEntities, targetEntity
                                  );
 
         try {
-            entitySerializationStrategy.write( collectionScope, mvccEntity ).execute();
+            entitySerializationStrategy.write( collectionScope, mergedEntity ).execute();
         }
         catch ( Exception e ) {
             throw new RuntimeException( "Couldn't rewrite repaired entity", e );
         }
-        return mvccEntity;
+        return mergedEntity;
     }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2828e911/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerIT.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerIT.java b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerIT.java
index 7a725a9..527099f 100644
--- a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerIT.java
+++ b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerIT.java
@@ -36,6 +36,7 @@ import org.apache.usergrid.persistence.model.entity.SimpleId;
 import org.apache.usergrid.persistence.model.field.IntegerField;
 import org.apache.usergrid.persistence.model.field.StringField;
 
+import com.fasterxml.uuid.UUIDComparator;
 import com.google.inject.Inject;
 
 import rx.Observable;
@@ -283,6 +284,10 @@ public class EntityCollectionManagerIT {
 
         assertNotNull( "Returned has a uuid", returned.getId() );
 
+        final UUID writeVersion = returned.getVersion();
+
+        assertNotNull("Write version was set", writeVersion);
+
         /**
          * Modify the oldEntity
          */
@@ -296,9 +301,19 @@ public class EntityCollectionManagerIT {
         assertNotNull( "Returned has a uuid", returned.getId() );
         assertEquals( oldEntity.getField( "testFud" ), returned.getField( "testFud" ) );
 
+        final UUID updatedVersion = updateReturned.getVersion();
+
+        assertNotNull("Updated version returned", updatedVersion);
+
+        assertTrue( "Updated version higher", UUIDComparator.staticCompare( updatedVersion, writeVersion ) > 0 );
+
         Observable<Entity> newEntityObs = manager.load( updateReturned.getId() );
         Entity newEntity = newEntityObs.toBlocking().last();
 
+        final UUID returnedVersion = newEntity.getVersion();
+
+        assertEquals("Loaded version matches updated version", updatedVersion, returnedVersion);
+
         assertNotNull( "Returned has a uuid", returned.getId() );
         assertEquals( addedField, newEntity.getField( "testFud" ));