From ad52c4f20eb1364a48294120a5acd1ecf08e43f7 Mon Sep 17 00:00:00 2001 From: Marko Luukkainen Date: Mon, 7 Feb 2022 16:56:25 +0200 Subject: [PATCH] Resolve "A tag with an associated listener causes issues in DelayedWrite transactions" Merged master/2cfb8969 to 1.43.1 manually. gitlab #761 Change-Id: I65961a7bf3a295bfd14bf0677ed9791c5c7aabc1 --- .../org/simantics/db/impl/graph/ReadGraphImpl.java | 4 ++++ .../simantics/db/impl/query/QueryListening.java | 10 ++++++++++ .../simantics/db/impl/query/QueryProcessor.java | 14 +++++++++++++- .../fi/vtt/simantics/procore/internal/State.java | 11 +++++++---- 4 files changed, 34 insertions(+), 5 deletions(-) diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/ReadGraphImpl.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/ReadGraphImpl.java index 776b448bf..8baacb10f 100644 --- a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/ReadGraphImpl.java +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/ReadGraphImpl.java @@ -5686,6 +5686,10 @@ public class ReadGraphImpl implements AsyncReadGraph { public ReadGraphImpl forRecompute(CacheEntry parent) { return new ReadGraphImpl(null, parent, processor); } + + public ReadGraphImpl forSyncExecute() { + return withParent(null, null, true); + } public static ReadGraphImpl create(QueryProcessor support) { ReadGraphImpl result = new ReadGraphImpl(null, null, support); diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryListening.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryListening.java index 075281035..5a7ab819d 100644 --- a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryListening.java +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryListening.java @@ -413,6 +413,16 @@ public class QueryListening { public void fireListeners(ReadGraphImpl graph) { + ReadGraphImpl listenerGraph = graph.forSyncExecute(); + listenerGraph.asyncBarrier.inc(); + fireListeners_(listenerGraph); + listenerGraph.asyncBarrier.dec(); + listenerGraph.asyncBarrier.waitBarrier(this, listenerGraph); + + } + + private void fireListeners_(ReadGraphImpl graph) { + assert (!processor.updating); assert (!processor.cache.collecting); assert (!firingListeners); diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryProcessor.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryProcessor.java index 6d9560940..4917bbe25 100644 --- a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryProcessor.java +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryProcessor.java @@ -1430,6 +1430,17 @@ final public class QueryProcessor extends AbstractDisposable implements ReadGrap public void propagateChangesInQueryCache(final ReadGraphImpl graph) { + ReadGraphImpl syncGraph = graph.forSyncExecute(); + syncGraph.asyncBarrier.inc(); + propagateChangesInQueryCache_(syncGraph); + syncGraph.asyncBarrier.dec(); + syncGraph.asyncBarrier.waitBarrier(this, syncGraph); + + } + + + public void propagateChangesInQueryCache_(final ReadGraphImpl graph) { + // Make sure that listening has performed its work listening.sync(); @@ -1657,7 +1668,8 @@ final public class QueryProcessor extends AbstractDisposable implements ReadGrap public void invalidateResource(final int resource) { if(lastInvalidate == resource) return; - scheduledValueUpdates.add(resource); + //scheduledValueUpdates.add(resource); + scheduledInvalidates.add(resource); lastInvalidate = resource; cache.dirty = true; } diff --git a/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/State.java b/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/State.java index 1e468f2c3..815ba7f15 100644 --- a/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/State.java +++ b/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/State.java @@ -341,10 +341,13 @@ class State { // start = System.nanoTime(); queryProvider.propagateChangesInQueryCache(graph); - ReadGraphImpl listenerGraph = graph.forRecompute(null); - listenerGraph.asyncBarrier.inc(); - queryProvider.listening.fireListeners(listenerGraph); - listenerGraph.asyncBarrier.dec(); + queryProvider.listening.fireListeners(graph); + +// ReadGraphImpl listenerGraph = graph.forRecompute(null); +// listenerGraph.asyncBarrier.inc(); +// queryProvider.listening.fireListeners(listenerGraph); +// listenerGraph.asyncBarrier.dec(); + // duration = System.nanoTime() - start; // System.out.println("performScheduledUpdates " + 1e-9*duration + "s. "); -- 2.47.1