Procházet zdrojové kódy

Merge pull request #2138 from ghalliday/globalcrash

Fix potential problems with dynamic cluster names

Reviewed-By: Richard Chapman <rchapman@hpccsystems.com>
Richard Chapman před 13 roky
rodič
revize
35c6fe3eb6

+ 6 - 1
ecl/hql/hqlgram.y

@@ -2494,9 +2494,14 @@ actionStmt
                             $$.setExpr(createValue(no_distribution, makeVoidType(), dataset, fields, $7.getExpr()));
                         }
     | assertAction
+    | GLOBAL '(' action ')'
+                        {
+                            $$.setExpr($3.getExpr());
+                            $$.setPosition($1);
+                        }
     | GLOBAL '(' action ',' expression ')'
                         {
-                            parser->normalizeExpression($5, type_string, false);
+                            parser->normalizeExpression($5, type_string, true);
                             if (isBlankString($5.queryExpr()))
                             {
                                 $5.release();

+ 6 - 1
ecl/hql/hqltrans.cpp

@@ -2247,8 +2247,13 @@ IHqlExpression * HoistingHqlTransformer::createTransformed(IHqlExpression * expr
         if (!(flags & HTFtraverseallnodes))
             return LINK(expr);
         break;
-    case no_colon:
     case no_cluster:
+        {
+            HqlExprArray args;
+            args.append(*transformIndependent(expr->queryChild(0)));
+            return completeTransform(expr, args);
+        }
+    case no_colon:
     case no_sequential:
         {
             HqlExprArray args;

+ 2 - 4
ecl/hqlcpp/hqlcpp.ipp

@@ -1222,8 +1222,8 @@ public:
     void doBuildHashMd5Element(BuildCtx & ctx, IHqlExpression * elem, CHqlBoundExpr & state);
     AliasKind doBuildAliasValue(BuildCtx & ctx, IHqlExpression * value, CHqlBoundExpr & tgt);
 
-    void pushCluster(BuildCtx & ctx, IHqlExpression * cluster, StringAttr & savedCluster);
-    void popCluster(BuildCtx & ctx, const char * savedCluster);
+    void pushCluster(BuildCtx & ctx, IHqlExpression * cluster);
+    void popCluster(BuildCtx & ctx);
 
     void noteResultAccessed(BuildCtx & ctx, IHqlExpression * seq, IHqlExpression * name);
     void noteResultDefined(BuildCtx & ctx, ActivityInstance * activityInstance, IHqlExpression * seq, IHqlExpression * name, bool alwaysExecuted);
@@ -1846,8 +1846,6 @@ protected:
     Owned<IPropertyTree> graph;
     unsigned            graphSeqNumber;
     StringAttr          graphLabel;
-    StringAttr          defaultCluster;
-    StringAttr          curCluster;
     NlpParseContext *   nlpParse;               // Not linked so it can try and stay opaque.
     bool                xmlUsesContents;
     CIArrayOf<GlobalFileTracker> globalFiles;

+ 10 - 21
ecl/hqlcpp/hqlhtcpp.cpp

@@ -5506,9 +5506,6 @@ bool HqlCppTranslator::buildCpp(IHqlCppInstance & _code, IHqlExpression * exprli
         unsigned time = msTick();
 
         wu()->setCodeVersion(ACTIVITY_INTERFACE_VERSION,BUILD_TAG,LANGUAGE_VERSION);
-        StringAttrAdaptor adaptor(defaultCluster);
-        wu()->getClusterName(adaptor);
-        curCluster.set(defaultCluster);
         cacheOptions();
 
         useLibrary(ECLRTL_LIB);
@@ -7119,26 +7116,23 @@ void HqlCppTranslator::doBuildAssignGetResult(BuildCtx & ctx, const CHqlBoundTar
 }
 
 
-void HqlCppTranslator::pushCluster(BuildCtx & ctx, IHqlExpression * cluster, StringAttr & savedCluster)
+void HqlCppTranslator::pushCluster(BuildCtx & ctx, IHqlExpression * cluster)
 {
-    savedCluster.set(curCluster);
-
     HqlExprArray args;
     args.append(*LINK(cluster));
-    callProcedure(ctx, selectClusterAtom, args);
+    buildFunctionCall(ctx, selectClusterAtom, args);
 
     StringBuffer clusterText;
-    cluster->queryValue()->getStringValue(clusterText);
-    ctxCallback->noteCluster(clusterText.str());
-    curCluster.set(clusterText.str());
+    getStringValue(clusterText, cluster);
+    if (clusterText.length())
+        ctxCallback->noteCluster(clusterText.str());
 }
 
 
-void HqlCppTranslator::popCluster(BuildCtx & ctx, const char * savedCluster)
+void HqlCppTranslator::popCluster(BuildCtx & ctx)
 {
     HqlExprArray args;
     callProcedure(ctx, restoreClusterAtom, args);
-    curCluster.set(savedCluster);
 }
 
 
@@ -7169,9 +7163,8 @@ void HqlCppTranslator::doBuildStmtSetResult(BuildCtx & ctx, IHqlExpression * exp
         graphLabel.set(text.str());
     }
 
-    StringAttr prevClusterName;
     if (cluster)
-        pushCluster(subctx, cluster->queryChild(0), prevClusterName);
+        pushCluster(subctx, cluster->queryChild(0));
 
     switch (value->queryType()->getTypeCode())
     {
@@ -7235,7 +7228,7 @@ void HqlCppTranslator::doBuildStmtSetResult(BuildCtx & ctx, IHqlExpression * exp
     }
 
     if (cluster)
-        popCluster(subctx, prevClusterName);
+        popCluster(subctx);
 
     if (matchesConstantValue(seq, ResultSequenceStored) || matchesConstantValue(seq, ResultSequencePersist))
         graphLabel.clear();
@@ -8296,10 +8289,9 @@ void HqlCppTranslator::doBuildStmtAssert(BuildCtx & ctx, IHqlExpression * expr)
 
 void HqlCppTranslator::doBuildStmtCluster(BuildCtx & ctx, IHqlExpression * expr)
 {
-    StringAttr prevClusterName;
-    pushCluster(ctx, expr->queryChild(1), prevClusterName);
+    pushCluster(ctx, expr->queryChild(1));
     buildStmt(ctx, expr->queryChild(0));
-    popCluster(ctx, prevClusterName);
+    popCluster(ctx);
 }
 
 //---------------------------------------------------------------------------
@@ -8746,9 +8738,6 @@ IHqlExpression * HqlCppTranslator::getResourcedGraph(IHqlExpression * expr, IHql
 
     //Now resource the graph....
     unsigned numNodes = 0;
-//  Owned<IConstWUClusterInfo> clusterInfo = wu()->getClusterInfo(curCluster);
-//  if (clusterInfo)
-//      numNodes = clusterInfo->getSize();
     if (options.specifiedClusterSize != 0)
         numNodes = options.specifiedClusterSize;
 

+ 4 - 17
ecl/hqlcpp/hqlttcpp.cpp

@@ -11893,8 +11893,9 @@ protected:
     IHqlExpression * createSubstitutedChild(IHqlExpression * expr, IHqlExpression * cluster)
     {
         StringBuffer clusterText;
-        cluster->queryValue()->getStringValue(clusterText);
-        ctxCallback->noteCluster(clusterText.str());
+        getStringValue(clusterText, cluster);
+        if (clusterText.length())
+            ctxCallback->noteCluster(clusterText.str());
 #if 0
         Owned<IConstWUClusterInfo> clusterInfo = wu->getClusterInfo(clusterText.str());
         if (clusterInfo)
@@ -11926,21 +11927,7 @@ IHqlExpression * substituteClusterSize(unsigned numNodes, IHqlExpression * expr,
 
 void HqlCppTranslator::substituteClusterSize(HqlExprArray & exprs)
 {
-    unsigned numNodes = 0;
-#if 0
-    if (curCluster)
-    {
-        Owned<IConstWUClusterInfo> clusterInfo = wu()->getClusterInfo(curCluster);
-        if (clusterInfo)
-        {
-            numNodes = clusterInfo->getSize();
-            if (numNodes == 0)
-                numNodes = 1;
-        }
-    }
-    else
-#endif
-        numNodes = options.specifiedClusterSize;
+    unsigned numNodes = options.specifiedClusterSize;
 
     ClusterSubstitueTransformer transformer(numNodes, ctxCallback, wu());
     HqlExprArray transformed;

+ 21 - 0
ecl/regress/issue2138.ecl

@@ -0,0 +1,21 @@
+/*##############################################################################
+
+    Copyright (C) 2011 HPCC Systems.
+
+    All rights reserved. This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU Affero General Public License as
+    published by the Free Software Foundation, either version 3 of the
+    License, or (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU Affero General Public License for more details.
+
+    You should have received a copy of the GNU Affero General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+############################################################################## */
+
+string targetCluster := '' : stored('targetCluster');
+
+global(output(dataset([1,2,3], { unsigned i })), targetCluster);