Browse Source

Merge pull request #9215 from jakesmith/hpcc-16361

HPCC-16361 Respect 'sequential' flag when executing sibling child queries

Reviewed-By: Gavin Halliday <gavin.halliday@lexisnexis.com>
Reviewed-By: Richard Chapman <rchapman@hpccsystems.com>
Richard Chapman 8 years ago
parent
commit
c77dd2a79d
2 changed files with 22 additions and 8 deletions
  1. 20 8
      thorlcr/graph/thgraph.cpp
  2. 2 0
      thorlcr/graph/thgraph.hpp

+ 20 - 8
thorlcr/graph/thgraph.cpp

@@ -1253,6 +1253,8 @@ void CGraphBase::addChildGraph(CGraphStub *stub)
 {
     CriticalBlock b(crit);
     childGraphsTable.replace(*LINK(stub));
+    if (sequential)
+        orderedChildGraphs.append(*stub);
 }
 
 IThorGraphStubIterator *CGraphBase::getChildStubIterator() const
@@ -1900,7 +1902,6 @@ void CGraphBase::createFromXGMML(IPropertyTree *_node, CGraphBase *_owner, CGrap
             if (subGraphParentActivityId) // JCS - not sure if ever false
             {
                 Owned<CGraphStub> stub = new CChildParallelFactory(subGraph);
-                CGraphElementBase *subGraphParentElement = queryElement(subGraphParentActivityId);
                 addChildGraph(stub);
             }
             else
@@ -1954,14 +1955,25 @@ void CGraphBase::createFromXGMML(IPropertyTree *_node, CGraphBase *_owner, CGrap
 
 void CGraphBase::executeChildGraphs(size32_t parentExtractSz, const byte *parentExtract)
 {
-    // JCSMORE - would need to respect codegen 'sequential' flag, if these child graphs
-    // could be executed in parallel.
-    Owned<IThorGraphIterator> iter = getChildGraphIterator();
-    ForEach(*iter)
+    if (sequential)
     {
-        CGraphBase &graph = iter->query();
-        if (graph.isSink())
-            graph.execute(parentExtractSz, parentExtract, true, false);
+        // JCSMORE - would need to re-think how this is done if these sibling child queries could be executed in parallel
+        ForEachItemIn(o, orderedChildGraphs)
+        {
+            CGraphBase &graph = orderedChildGraphs.item(o).queryOriginalGraph();
+            if (graph.isSink())
+                graph.execute(parentExtractSz, parentExtract, true, false);
+        }
+    }
+    else
+    {
+        Owned<IThorGraphIterator> iter = getChildGraphIterator();
+        ForEach(*iter)
+        {
+            CGraphBase &graph = iter->query();
+            if (graph.isSink())
+                graph.execute(parentExtractSz, parentExtract, true, false);
+        }
     }
 }
 

+ 2 - 0
thorlcr/graph/thgraph.hpp

@@ -237,6 +237,7 @@ typedef OwningSimpleHashTableOf<CGraphBase, graph_id> CGraphTable;
 typedef OwningSimpleHashTableOf<CGraphStub, graph_id> CChildGraphTable;
 typedef CIArrayOf<CGraphBase> CGraphArray;
 typedef CICopyArrayOf<CGraphBase> CGraphArrayCopy;
+typedef CICopyArrayOf<CGraphStub> CGraphStubArrayCopy;
 typedef IIteratorOf<CGraphBase> IThorGraphIterator;
 typedef ArrayIIteratorOf<const CGraphArray, CGraphBase, IThorGraphIterator> CGraphArrayIterator;
 typedef ArrayIIteratorOf<const CGraphArrayCopy, CGraphBase, IThorGraphIterator> CGraphArrayCopyIterator;
@@ -454,6 +455,7 @@ class graph_decl CGraphBase : public CGraphStub, implements IEclGraphResults
     activity_id parentActivityId;
     IPropertyTree *xgmml;
     CChildGraphTable childGraphsTable;
+    CGraphStubArrayCopy orderedChildGraphs;
     Owned<IGraphTempHandler> tmpHandler;
 
     void clean();