X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.db.impl%2Fsrc%2Forg%2Fsimantics%2Fdb%2Fimpl%2Fquery%2FAsyncReadEntry.java;h=972bd381f222207b2ff91d02d33b13269321913c;hp=e6d42750d37b9caf62196bd50c043b802093d7e6;hb=ff1c29bf73b3e5ea939dc1987540aa0240dc4ae6;hpb=277b1c7fb3fdd8effb4bf2b447358d0e4ef0e302 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 e6d42750d..972bd381f 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 @@ -13,10 +13,10 @@ package org.simantics.db.impl.query; import org.simantics.db.AsyncReadGraph; import org.simantics.db.exception.DatabaseException; -import org.simantics.db.exception.RuntimeDatabaseException; import org.simantics.db.impl.BlockingAsyncProcedure; import org.simantics.db.impl.DebugPolicy; import org.simantics.db.impl.graph.AsyncBarrierImpl; +import org.simantics.db.impl.graph.BarrierTracing; import org.simantics.db.impl.graph.ReadGraphImpl; import org.simantics.db.impl.query.QueryProcessor.SessionTask; import org.simantics.db.procedure.AsyncProcedure; @@ -72,7 +72,7 @@ final public class AsyncReadEntry extends CacheEntryBase> i try { - BlockingAsyncProcedure proc = new BlockingAsyncProcedure<>(graph, new AsyncProcedure() { + BlockingAsyncProcedure proc = new BlockingAsyncProcedure<>(graph.asyncBarrier, graph, new AsyncProcedure() { @Override public void execute(AsyncReadGraph graph, T result) { @@ -153,11 +153,13 @@ final public class AsyncReadEntry extends CacheEntryBase> i AsyncProcedure procedure = entry != null ? entry : procedure_; ReadGraphImpl queryGraph = graph.withParent(entry); + queryGraph.asyncBarrier.inc(); - BlockingAsyncProcedure proc = new BlockingAsyncProcedure<>(queryGraph, null, request); + BlockingAsyncProcedure proc = new BlockingAsyncProcedure<>(queryGraph.asyncBarrier, graph, null, request); class AsyncTask extends SessionTask { + int counter = 0; T result; DatabaseException exception; @@ -166,32 +168,58 @@ final public class AsyncReadEntry extends CacheEntryBase> i } @Override - public void run(int thread) { + public void run0(int thread) { if(needsToBlock) proc.waitBarrier(); if(proc.isDone()) { + ReadGraphImpl executeGraph = graph.withParent(graph.parent); + executeGraph.asyncBarrier.inc(); try { result = (T)proc.get(); - if(procedure != null) procedure.execute(graph, result); + if(procedure != null) { + procedure.execute(executeGraph, result); + } } catch (DatabaseException e) { - if(procedure != null) procedure.exception(graph, e); + if(procedure != null) procedure.exception(executeGraph, e); exception = e; } catch (Throwable t) { DatabaseException dbe = new DatabaseException(t); - if(procedure != null) procedure.exception(graph, dbe); + if(procedure != null) procedure.exception(executeGraph, dbe); exception = dbe; } finally { - if (entry != null) - entry.performFromCache(queryGraph, procedure_); + if (entry != null) { + // This does not throw + entry.performFromCache(executeGraph, procedure_); + } + executeGraph.asyncBarrier.dec(); + executeGraph.asyncBarrier.waitBarrier(procedure, executeGraph); } } else { - graph.processor.schedule(this); + if(counter++ > 10000) { + if(BarrierTracing.BOOKKEEPING) { + AsyncBarrierImpl.printReverse(queryGraph.asyncBarrier, 2); + AsyncBarrierImpl caller = queryGraph.asyncBarrier.caller; + while(caller != null) { + System.err.println("called by " + AsyncBarrierImpl.report(caller)); + caller = caller.caller; + } + for(AsyncBarrierImpl ab : BarrierTracing.debuggerMap.keySet()) { + AsyncBarrierImpl.printReverse(ab, 2); + } + } + throw new IllegalStateException("Eternal loop in queries."); + } + graph.processor.schedule(new AsyncTask(graph)); } } } - - request.perform(queryGraph, proc); - + + try { + request.perform(queryGraph, proc); + } finally { + queryGraph.asyncBarrier.dec(); + } + AsyncTask task = new AsyncTask(graph); if(needsToBlock) task.run(0); @@ -200,7 +228,7 @@ final public class AsyncReadEntry extends CacheEntryBase> i graph.processor.schedule(task); return null; } - + if(task.exception != null) throw task.exception; else return task.result;