From: Antti Villberg Date: Tue, 4 Feb 2020 15:24:39 +0000 (+0200) Subject: Wrong graph was used when performing async query from session X-Git-Tag: v1.43.0~109^2 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=472f4b2af82d02fb46f9a929fb6c8090bb4c5301;p=simantics%2Fplatform.git Wrong graph was used when performing async query from session gitlab #457 Change-Id: I3a38eed6b63eb2559893c831b05a9d512bf34745 --- diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/BlockingAsyncProcedure.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/BlockingAsyncProcedure.java index ecb66ff91..8f96bb9e6 100644 --- a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/BlockingAsyncProcedure.java +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/BlockingAsyncProcedure.java @@ -18,19 +18,19 @@ import org.simantics.db.impl.graph.ReadGraphImpl; import org.simantics.db.impl.query.AsyncReadEntry; import org.simantics.db.impl.query.PendingTaskSupport; import org.simantics.db.procedure.AsyncProcedure; - +import org.simantics.db.request.AsyncRead; public class BlockingAsyncProcedure implements AsyncProcedure { private static final Object NO_RESULT = new Object(); - public final Object key; - public final ReadGraphImpl queryGraph; - public final ReadGraphImpl callerGraph; - public final AsyncProcedure procedure; - public PendingTaskSupport pendingTaskSupport; - public final boolean needsToBlock; - public Object result = NO_RESULT; - public Throwable exception = null; + private final Object key; + private final ReadGraphImpl queryGraph; + private final ReadGraphImpl callerGraph; + private final AsyncProcedure procedure; + private PendingTaskSupport pendingTaskSupport; + private final boolean needsToBlock; + private Object result = NO_RESULT; + private Throwable exception = null; private ReadGraphImpl queryGraph() { return queryGraph; @@ -147,5 +147,33 @@ public class BlockingAsyncProcedure implements AsyncProcedure { } } + + public void print() { + System.err.println("BlockingAsyncProcedure"); + System.err.println("-key: " + key); + System.err.println("-queryGraph: " + queryGraph); + System.err.println("-callerGraph: " + callerGraph); + System.err.println("-procedure: " + procedure); + System.err.println("-pendingTaskSupport: " + pendingTaskSupport); + System.err.println("-result: " + result); + System.err.println("-exception: " + exception); + } + + public Result performSync(AsyncRead request) throws DatabaseException { + try { + request.perform(queryGraph, this); + } finally { + dec(); + } + return get(); + } + + public void performAsync(AsyncRead request) throws DatabaseException { + try { + request.perform(queryGraph, this); + } finally { + dec(); + } + } } diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/BarrierTracing.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/BarrierTracing.java index 2433b897f..68fdd824e 100644 --- a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/BarrierTracing.java +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/BarrierTracing.java @@ -32,16 +32,10 @@ public class BarrierTracing { synchronized public static void printBAPS() { for(BlockingAsyncProcedure bap : baps.keySet()) { - Throwable e = baps.get(bap); - System.err.println("BlockingAsyncProcedure"); - System.err.println("-key: " + bap.key); - System.err.println("-queryGraph: " + bap.queryGraph); - System.err.println("-callerGraph: " + bap.callerGraph); - System.err.println("-procedure: " + bap.procedure); - System.err.println("-pendingTaskSupport: " + bap.pendingTaskSupport); - System.err.println("-result: " + bap.result); - System.err.println("-exception: " + bap.exception); - e.printStackTrace(); + bap.print(); + Throwable t = baps.get(bap); + if(t != null) + t.printStackTrace(); } } 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 dfde4ec12..48662d190 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 @@ -5692,22 +5692,14 @@ public class ReadGraphImpl implements AsyncReadGraph { return new ReadGraphImpl(this, parent, callback, needsToBlock); } -// public ReadGraphImpl withParent(CacheEntry parent) { -// return withParent(parent, null); -// } - - public ReadGraphImpl syncWithParent(CacheEntry parent) { - return new ReadGraphImpl(this, parent, processor, null); - } - public ReadGraphImpl forRecompute(CacheEntry parent) { return new ReadGraphImpl(null, parent, processor); } - public static ReadGraphImpl create(QueryProcessor support) { - ReadGraphImpl result = new ReadGraphImpl(null, null, support); - return result; - } + public static ReadGraphImpl create(QueryProcessor support) { + ReadGraphImpl result = new ReadGraphImpl(null, null, support); + return result; + } public ReadGraphImpl newRestart(ReadGraphImpl impl) { diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/AsyncReadEntry.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/AsyncReadEntry.java index 0dd5730a5..5017151b1 100644 --- a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/AsyncReadEntry.java +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/AsyncReadEntry.java @@ -92,11 +92,8 @@ final public class AsyncReadEntry extends CacheEntryBase> i } }, id, true); - - id.perform(proc.queryGraph, proc); - proc.dec(); - proc.get(); + proc.performSync(id); } catch (Throwable t) { except(t); @@ -158,17 +155,10 @@ final public class AsyncReadEntry extends CacheEntryBase> i AsyncProcedure procedure_, boolean needsToBlock) throws DatabaseException { BlockingAsyncProcedure proc = new BlockingAsyncProcedure(callerGraph, entry, procedure_, request, needsToBlock); - - try { - request.perform(proc.queryGraph, proc); - } finally { - proc.queryGraph.asyncBarrier.dec(); - } - if(needsToBlock) { - proc.waitBarrier(); - return proc.get(); + return proc.performSync(request); } else { + proc.performAsync(request); return null; } diff --git a/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/SessionImplSocket.java b/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/SessionImplSocket.java index 030d512eb..22d0f3165 100644 --- a/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/SessionImplSocket.java +++ b/bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/SessionImplSocket.java @@ -1632,37 +1632,31 @@ public abstract class SessionImplSocket implements Session, WriteRequestSchedule if (listener != null) { try { - QueryCacheBase.resultAsyncReadEntry(newGraph, request, null, listener, procedure); - } catch (DatabaseException e) { - Logger.defaultLogError(e); - } + QueryCacheBase.resultAsyncReadEntry(newGraph, request, null, listener, procedure); + } catch (DatabaseException e) { + LOGGER.error("Unhandled query exception", e); + } } else { - BlockingAsyncProcedure wrap = new BlockingAsyncProcedure(newGraph, null, procedure, request, true) { - - public void execute(AsyncReadGraph graph_, T result) { - task.finish(); - super.execute(graph_, result); - } - - public void exception(AsyncReadGraph graph_, Throwable t) { - task.finish(); - super.exception(graph_, t); - } - - }; - - try { + BlockingAsyncProcedure wrap = new BlockingAsyncProcedure(newGraph, null, procedure, request, true) { - request.perform(newGraph, wrap); - wrap.dec(); - wrap.get(); + public void execute(AsyncReadGraph graph_, T result) { + task.finish(); + super.execute(graph_, result); + } - } catch (DatabaseException e) { + public void exception(AsyncReadGraph graph_, Throwable t) { + task.finish(); + super.exception(graph_, t); + } - Logger.defaultLogError(e); + }; + try { + wrap.performSync(request); + } catch (DatabaseException e) { + LOGGER.error("Unhandled query exception", e); } } diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/NodeClassRequest.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/NodeClassRequest.java index d99d2963b..8ab24b71a 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/NodeClassRequest.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/NodeClassRequest.java @@ -36,18 +36,6 @@ public class NodeClassRequest extends BaseRequest2 { @Override public void perform(AsyncReadGraph graph, final AsyncProcedure procedure) { -// System.out.println("NodeClassRequest " + data.getResourceId()); -// graph.asyncRequest(new SafeName(data), new Procedure() { -// @Override -// public void exception(Throwable t) { -// } -// @Override -// public void execute(String result) { -// System.out.println("NodeClassRequest " + result); -// debug = result; -// } -// }); - graph.forAdapted(data, ElementFactory.class, new AsyncProcedure() { @Override @@ -61,18 +49,6 @@ public class NodeClassRequest extends BaseRequest2 { @Override public void execute(AsyncReadGraph graph, final ElementFactory factory) { -// System.out.println("NodeClassRequest factory " + data.getResourceId() + " = " + factory.getClass().getName()); -// graph.asyncRequest(new SafeName(data), new Procedure() { -// @Override -// public void exception(Throwable t) { -// } -// @Override -// public void execute(String result) { -// System.out.println("NodeClassRequest " + result + " " + factory.getClass().getName()); -// debug = result; -// } -// }); - if (factory == null) { // Should never happen since we are using forAdapted System.out.println("No factory in NodeClassRequest! " + this);