usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sfeld...@apache.org
Subject [40/50] [abbrv] incubator-usergrid git commit: Fixes issue with repair logic with incorrect assumptions of version ordering. Versions can appear in any order during arbitrary order by statements.
Date Thu, 19 Mar 2015 23:26:57 GMT
Fixes issue with repair logic with incorrect assumptions of version ordering.  Versions can
appear in any order during arbitrary order by statements.

Also fixes overflow logic during repair when you may be more results than anticipated.


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

Branch: refs/heads/USERGRID-480
Commit: 407a4f55eff3adb01f69e7e45f943918e60dd240
Parents: 0334119
Author: Todd Nine <tnine@apigee.com>
Authored: Wed Mar 18 15:53:43 2015 -0600
Committer: Todd Nine <tnine@apigee.com>
Committed: Wed Mar 18 15:53:43 2015 -0600

----------------------------------------------------------------------
 .../corepersistence/CpRelationManager.java      |  7 ++-
 .../results/FilteringLoader.java                | 50 +++++++++++++-------
 2 files changed, 38 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/407a4f55/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 ee81a67..2eeee28 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
@@ -987,7 +987,12 @@ public class CpRelationManager implements RelationManager {
             if ( crs.isEmpty() || !crs.hasCursor() ) { // no results, no cursor, can't get
more
                 satisfied = true;
             }
-            else if ( results.size() == originalLimit ) { // got what we need
+
+            /**
+             * In an edge case where we delete stale entities, we could potentially get more
results than expected.  This will only occur once during the repair phase.
+             * We need to ensure that we short circuit if we overflow the requested limit
during a repair.
+             */
+            else if ( results.size() >= originalLimit ) { // got what we need
                 satisfied = true;
             }
             else if ( crs.hasCursor() ) {

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/407a4f55/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 2cd9fdc..b571f21 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
@@ -143,30 +143,44 @@ public class FilteringLoader implements ResultsLoader {
 
             final UUID currentVersion = currentCandidate.getVersion();
 
+
+            final CandidateResult toRemove;
+            final CandidateResult toKeep;
+
+            //current is newer than previous.  Remove previous and keep current
+            if(UUIDComparator.staticCompare( currentVersion, previousMaxVersion ) > 0
){
+                toRemove = previousMax;
+                toKeep = currentCandidate;
+            }
+            //previously seen value is newer than current.  Remove the current and keep the
previously seen value
+            else{
+                toRemove = currentCandidate;
+                toKeep = previousMax;
+            }
+
             //this is a newer version, we know we already have a stale entity, add it to
be cleaned up
-            if ( UUIDComparator.staticCompare( currentVersion, previousMaxVersion ) >
0 ) {
 
-                //de-index it
-                logger.warn( "Stale version of Entity uuid:{} type:{}, stale v:{}, latest
v:{}",
-                    new Object[] {
-                        entityId.getUuid(),
-                        entityId.getType(),
-                        previousMaxVersion,
-                        currentVersion } );
 
-                //deindex this document, and remove the previous maxVersion
-                //we have to deindex this from our ownerId, since this is what gave us the
reference
-                indexBatch.deindex( indexScope, previousMax );
-                groupedByScopes.remove( collectionType, previousMax );
+            //de-index it
+            logger.warn( "Stale version of Entity uuid:{} type:{}, stale v:{}, latest v:{}",
+                new Object[] {
+                    entityId.getUuid(),
+                    entityId.getType(),
+                    toRemove.getVersion(),
+                    toKeep.getVersion() } );
 
+            //deindex this document, and remove the previous maxVersion
+            //we have to deindex this from our ownerId, since this is what gave us the reference
+            indexBatch.deindex( indexScope, toRemove );
+            groupedByScopes.remove( collectionType, toRemove );
 
-                //TODO, fire the entity repair cleanup task here instead of de-indexing
 
-                //replace the value with a more current version
-                maxCandidateMapping.put( entityId, currentCandidate );
-                orderIndex.put( entityId, i );
-                groupedByScopes.put( collectionType, currentCandidate );
-            }
+            //TODO, fire the entity repair cleanup task here instead of de-indexing
+
+            //replace the value with a more current version
+            maxCandidateMapping.put( entityId, toKeep );
+            orderIndex.put( entityId, i );
+            groupedByScopes.put( collectionType, toKeep );
         }
 
 


Mime
View raw message