]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Wrong graph was used when performing async query from session 29/3829/1
authorAntti Villberg <antti.villberg@semantum.fi>
Tue, 4 Feb 2020 15:24:39 +0000 (17:24 +0200)
committerAntti Villberg <antti.villberg@semantum.fi>
Tue, 4 Feb 2020 15:24:39 +0000 (17:24 +0200)
gitlab #457

Change-Id: I3a38eed6b63eb2559893c831b05a9d512bf34745

bundles/org.simantics.db.impl/src/org/simantics/db/impl/BlockingAsyncProcedure.java
bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/BarrierTracing.java
bundles/org.simantics.db.impl/src/org/simantics/db/impl/graph/ReadGraphImpl.java
bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/AsyncReadEntry.java
bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/SessionImplSocket.java
bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/NodeClassRequest.java

index ecb66ff91e3ea5df7aea462e57e5d578608ee970..8f96bb9e6d3a51a48c7b98baa40f962fc83f5617 100644 (file)
@@ -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<Result> implements AsyncProcedure<Result> {
 
     private static final Object NO_RESULT = new Object();
 
-    public final Object key;
-    public final ReadGraphImpl queryGraph;
-    public final ReadGraphImpl callerGraph;
-    public final AsyncProcedure<Result> 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<Result> 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<Result> implements AsyncProcedure<Result> {
         }
 
     }
+    
+    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<Result> request) throws DatabaseException {
+        try {
+            request.perform(queryGraph, this);
+        } finally {
+            dec();
+        }
+        return get();
+    }
+
+    public void performAsync(AsyncRead<Result> request) throws DatabaseException {
+        try {
+            request.perform(queryGraph, this);
+        } finally {
+            dec();
+        }
+    }
 
 }
index 2433b897f888d15044e135433aa444fb48f498d0..68fdd824ed29f95eee0fa8f1cb0a49eb9dcebf92 100644 (file)
@@ -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();
         }
     }
     
index dfde4ec12973663737cb3e53244d32a0190e410a..48662d1903a08267a13dded57e04e04f8b85db6d 100644 (file)
@@ -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) {
 
index 0dd5730a5f3a1f5c6c232063741bf4343303feb4..5017151b10b9f8478bf1df7319326d020b0fb583 100644 (file)
@@ -92,11 +92,8 @@ final public class AsyncReadEntry<T> extends CacheEntryBase<AsyncProcedure<T>> 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<T> extends CacheEntryBase<AsyncProcedure<T>> i
             AsyncProcedure<T> procedure_, boolean needsToBlock) throws DatabaseException {
 
         BlockingAsyncProcedure<T> 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;
         }
 
index 030d512eb736e2f6303f0d68c1d0b0e3d2e57b97..22d0f316545762d4937b384bea9fd648e8bdd441 100644 (file)
@@ -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<T> wrap = new BlockingAsyncProcedure<T>(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<T> wrap = new BlockingAsyncProcedure<T>(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);
                         }
 
                     }
index d99d2963ba12f79b55ad586113683a8b53b0a4ff..8ab24b71ab083012ca97fd695e90592b0304d929 100644 (file)
@@ -36,18 +36,6 @@ public class NodeClassRequest extends BaseRequest2<Resource, ElementClass> {
     @Override
     public void perform(AsyncReadGraph graph, final AsyncProcedure<ElementClass> procedure) {
 
-//        System.out.println("NodeClassRequest " + data.getResourceId());
-//        graph.asyncRequest(new SafeName(data), new Procedure<String>() {
-//            @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<ElementFactory>() {
 
             @Override
@@ -61,18 +49,6 @@ public class NodeClassRequest extends BaseRequest2<Resource, ElementClass> {
             @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<String>() {
-//                    @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);