From 93c7d4ef3ecf2945359ff740e920a14853c4bc17 Mon Sep 17 00:00:00 2001 From: Zoltan Ujhelyi Date: Fri, 20 Oct 2017 15:03:34 +0200 Subject: [PATCH] [526225] Fix a regression related to statistics indexing The fix for bug 518356 (http://git.eclipse.org/c/viatra/org.eclipse.viatra.git/commit/?id=aee1e492e61a238edd804dba7becd53af5a6f664 ) erased the statistics indexes before executing a full indexing. However, when moving model elements outside of the model scope, this might have resulted in clearing the statistics when it is not recalculated. This change (backported from master) fixes the issue by only clearing the stats store if the old indexing level had statistics indexing but did not have instance indexing. Conflicts: query/plugins/org.eclipse.viatra.query.runtime.base/src/org/eclipse/viatra/query/runtime/base/core/NavigationHelperImpl.java Change-Id: I2d7fe18ccbc4c0f43199a42f753b50edf96ff114 Signed-off-by: Zoltan Ujhelyi --- .../base/core/NavigationHelperImpl.java | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/query/plugins/org.eclipse.viatra.query.runtime.base/src/org/eclipse/viatra/query/runtime/base/core/NavigationHelperImpl.java b/query/plugins/org.eclipse.viatra.query.runtime.base/src/org/eclipse/viatra/query/runtime/base/core/NavigationHelperImpl.java index 38dd002657..f34dc52097 100644 --- a/query/plugins/org.eclipse.viatra.query.runtime.base/src/org/eclipse/viatra/query/runtime/base/core/NavigationHelperImpl.java +++ b/query/plugins/org.eclipse.viatra.query.runtime.base/src/org/eclipse/viatra/query/runtime/base/core/NavigationHelperImpl.java @@ -1263,6 +1263,8 @@ public V coalesceTraversals(Callable callable) throws InvocationTargetExc delayTraversals = false; callable = null; + // This set collects all types whose indexing level increases from statistics to full + Set moveFromStatsToFullRequests = new HashSet<>(); for(Entry entry: observedFeatures.entrySet()){ IndexingLevel requested = delayedFeatures.get(entry.getKey()); if (requested != null){ @@ -1270,9 +1272,12 @@ public V coalesceTraversals(Callable callable) throws InvocationTargetExc IndexingLevel merged = requested.merge(old); if (merged == old){ delayedFeatures.remove(entry.getKey()); - }else{ + } else { delayedFeatures.put(entry.getKey(), merged); } + if (merged.hasInstances() && old.hasStatistics() && !old.hasInstances()) { + moveFromStatsToFullRequests.add(entry.getKey()); + } } } for(Entry entry: directlyObservedClasses.entrySet()){ @@ -1285,6 +1290,9 @@ public V coalesceTraversals(Callable callable) throws InvocationTargetExc } else{ delayedClasses.put(entry.getKey(), merged); } + if (merged.hasInstances() && old.hasStatistics() && !old.hasInstances()) { + moveFromStatsToFullRequests.add(entry.getKey()); + } } } for(Entry entry: observedDataTypes.entrySet()){ @@ -1297,9 +1305,14 @@ public V coalesceTraversals(Callable callable) throws InvocationTargetExc } else { delayedDataTypes.put(entry.getKey(), merged); } + if (merged.hasInstances() && old.hasStatistics() && !old.hasInstances()) { + moveFromStatsToFullRequests.add(entry.getKey()); + } } } + + boolean classesWarrantTraversal = !Maps .difference(delayedClasses, getAllObservedClassesInternal()).areEqual(); @@ -1321,19 +1334,16 @@ public V coalesceTraversals(Callable callable) throws InvocationTargetExc delayedDataTypes); // Instance indexing would add extra entries to the statistics store, so we have to clean the - // appropriate entries. If no re-traversal is required, it is detected earlier; at this point we - // only have to consider the target indexing level. See bug + // appropriate entries. At this point we simply empty the stats store for elements where + // indexing level is increased from statistics to full. See bug // https://bugs.eclipse.org/bugs/show_bug.cgi?id=518356 for more details. - + // Technically, the statsStore cleanup seems only necessary for EDataTypes; otherwise everything // works as expected, but it seems a better idea to do the cleanup for all types in the same way - for (Entry entry : Iterables.concat(toGatherClasses.entrySet(), - toGatherFeatures.entrySet(), toGatherDataTypes.entrySet())) { - if (entry.getValue().hasInstances()) { - statsStore.removeType(entry.getKey()); - } + for (Object type : moveFromStatsToFullRequests) { + statsStore.removeType(type); } - + if (classesWarrantTraversal || !toGatherFeatures.isEmpty() || !toGatherDataTypes.isEmpty()) { // repeat the cycle with this visit final NavigationHelperVisitor visitor = new NavigationHelperVisitor.TraversingVisitor(this,