You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by mr...@apache.org on 2015/10/21 23:07:22 UTC

usergrid git commit: USERGRID-1056 - Move the filtering of older entity versions on index deletes to Usergrid and not in the Elasticsearch query.

Repository: usergrid
Updated Branches:
  refs/heads/USERGRID-1052 c417099d6 -> 2c1147e49


USERGRID-1056 - Move the filtering of older entity versions on index deletes to Usergrid and not in the Elasticsearch query.


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

Branch: refs/heads/USERGRID-1052
Commit: 2c1147e49f76702dcf03ecaef6ece1f30306aa5f
Parents: c417099
Author: Michael Russo <mi...@gmail.com>
Authored: Wed Oct 21 14:07:18 2015 -0700
Committer: Michael Russo <mi...@gmail.com>
Committed: Wed Oct 21 14:07:18 2015 -0700

----------------------------------------------------------------------
 .../index/impl/EsEntityIndexImpl.java           | 45 +++++++++++++++-----
 1 file changed, 35 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/2c1147e4/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 f6ebce2..9be591e 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
@@ -460,7 +460,7 @@ public class EsEntityIndexImpl implements EntityIndex,VersionedData {
 
             while(true){
                 //add search result hits to some sort of running tally of hits.
-                candidates = aggregateScrollResults( candidates, searchResponse );
+                candidates = aggregateScrollResults( candidates, searchResponse, null );
 
                 SearchScrollRequestBuilder ssrb = searchRequestBuilderStrategyV2
                     .getScrollBuilder( searchResponse.getScrollId() )
@@ -510,11 +510,7 @@ public class EsEntityIndexImpl implements EntityIndex,VersionedData {
         FilterBuilder entityIdFilter = FilterBuilders.termFilter(IndexingUtils.ENTITY_ID_FIELDNAME,
             IndexingUtils.entityId(entityId));
 
-        FilterBuilder entityVersionFilter = FilterBuilders.rangeFilter( IndexingUtils.ENTITY_VERSION_FIELDNAME ).lte(markedVersion);
-
-        FilterBuilder andFilter = FilterBuilders.andFilter(entityIdFilter, entityVersionFilter);
-
-        srb.setPostFilter(andFilter);
+        srb.setPostFilter(entityIdFilter);
 
 
 
@@ -536,7 +532,7 @@ public class EsEntityIndexImpl implements EntityIndex,VersionedData {
 
             while(true){
                 //add search result hits to some sort of running tally of hits.
-                candidates = aggregateScrollResults( candidates, searchResponse );
+                candidates = aggregateScrollResults( candidates, searchResponse, markedVersion);
 
                 SearchScrollRequestBuilder ssrb = searchRequestBuilderStrategyV2
                     .getScrollBuilder( searchResponse.getScrollId() )
@@ -649,8 +645,8 @@ public class EsEntityIndexImpl implements EntityIndex,VersionedData {
         return candidateResults;
     }
 
-    private List<CandidateResult> aggregateScrollResults( List<CandidateResult> candidates,
-                                                          final SearchResponse searchResponse ){
+    private List<CandidateResult> aggregateScrollResults(List<CandidateResult> candidates,
+                                                         final SearchResponse searchResponse, final UUID markedVersion){
 
         final SearchHits searchHits = searchResponse.getHits();
         final SearchHit[] hits = searchHits.getHits();
@@ -659,7 +655,36 @@ public class EsEntityIndexImpl implements EntityIndex,VersionedData {
 
             final CandidateResult candidateResult = parseIndexDocId( hit.getId() );
 
-            candidates.add( candidateResult );
+            // if comparing against the latestVersion, make sure we only add the candidateResult if it's
+            // older than or equal to the latest marked version
+            if (markedVersion != null) {
+
+                if(candidateResult.getVersion().timestamp() <= markedVersion.timestamp()){
+
+                    if(logger.isDebugEnabled()){
+                        logger.debug("Candidate version {} is <= provided entity version {} for entityId {}",
+                            candidateResult.getVersion(),
+                            markedVersion,
+                            candidateResult.getId()
+                            );
+                    }
+
+                    candidates.add(candidateResult);
+
+                }else{
+                    if(logger.isDebugEnabled()){
+                        logger.debug("Candidate version {} is > provided entity version {} for entityId {}. Not" +
+                                "adding to candidate results",
+                            candidateResult.getVersion(),
+                            markedVersion,
+                            candidateResult.getId()
+                        );
+                    }
+                }
+
+            }else{
+                candidates.add(candidateResult);
+            }
         }
 
         logger.debug( "Aggregated {} out of {} hits ",candidates.size(),searchHits.getTotalHits() );