Uploaded image for project: 'Red Hat Decision Manager'
  1. Red Hat Decision Manager
  2. RHDM-1790

Mvel optimization concurrency issue

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • 7.12.0.GA
    • 7.9.0.GA
    • BRE
    • This issue is reproducible on RHDM 7.9.0 + RHDM-1777 one-off patch.

    • False
    • False
    • CR2
    • ?
    • Undefined
    • Hide
      1. Extract reproducer.
        $ unzip reproducer_mt_3d.zip
        $ cd reproducer_mt_3d
        
      2. Build and execute the rule on a machine with many cpu/cores.
        $ ./run_mvn
        

        run_mvn script builds with -DgenerateModel=NO and then runs the test (*2) 100 times. The output is written to reproducer_mt_3d_output_YYYYMMDDhhmmss.log.txt. You might be able to see exceptions like (*e1) or (*e2) several times of 100 times.

      Show
      Extract reproducer. $ unzip reproducer_mt_3d.zip $ cd reproducer_mt_3d Build and execute the rule on a machine with many cpu/cores. $ ./run_mvn run_mvn script builds with -DgenerateModel=NO and then runs the test (*2) 100 times. The output is written to reproducer_mt_3d_output_ YYYYMMDDhhmmss .log.txt . You might be able to see exceptions like (*e1) or (*e2) several times of 100 times.

      When we build a rule written in MVEL dialect like (*1) with executable model disabled and run the rule using the test code like (*2), MVEL syntax error like (*e1) or (*e2) sometimes occurs though the rule normally does not cause errors. The test code simultaneously executes multiple jobs each of which creates a new KieSession, inserts objects and calls fireAllRules.

      This issue is similar to RHDM-1629 in the way that it occurs inside MvelConstraint#evaluate from the stack trace of the exception (*e1) and (*e2). However, from (*e1-1) and (*e2-1), it seems that this is the case which has not been covered by the fixes for RHDM-1629 and RHDM-1764.

      (*1)

      package com.example.reproducer
      
      import static com.example.reproducer.Utils.TOSTRING
      
      dialect "mvel"
      
      rule "rule_mt_3d"
          when
              $bus1 : Bus()
              $bus2 : Bus( $check: "GAMMA RAY",
                           $title: "POWER PLANT",
                           $bus1.karaoke.dvd[$title] != null,
                           TOSTRING($bus1.karaoke.dvd[$title].artist) >= "01",
                           TOSTRING($bus1.karaoke.dvd[$title].artist) <= "39" )
          then
      end
      

      (*2) Test code (In the actual code in the reproducer, java.util.concurrent.CountDownLatch is used for making reproducibility higher.)

          KieServices kServices = KieServices.Factory.get();
          KieContainer kContainer = kServices.getKieClasspathContainer();
      
          int THREADS = 32;
          int REQUESTS = 32;
      
          // 1st run
          KieSession kSession1 = kContainer.newKieSession();
          Bus bus1 = new Bus("red", 30);
          bus1.getKaraoke().getDvd().put("POWER PLANT", new Album("POWER PLANT", "00")); // not match the 1st condition -> short circuit
          bus1.getKaraoke().getDvd().put("Somewhere Out In Space", new Album("Somewhere Out In Space", "GAMMA RAY"));
          kSession1.insert(bus1);
          kSession1.fireAllRules();
          kSession1.dispose();
      
          ExecutorService executor = Executors.newFixedThreadPool(THREADS);
          
          System.out.println("***** start threads");
          for (int i = 0; i < REQUESTS; i++) {
              executor.execute(new Runnable() {
      
                  public void run() {
                      KieSession kSession = kContainer.newKieSession();
      
                      Bus bus1 = new Bus("red", 30);
                      bus1.getKaraoke().getDvd().put("POWER PLANT", new Album("POWER PLANT", "10")); // match the 1st & 2nd condition
                      bus1.getKaraoke().getDvd().put("Somewhere Out In Space", new Album("Somewhere Out In Space", "GAMMA RAY"));
                      kSession.insert(bus1);
      
                      try {
                          kSession.fireAllRules();
                      } catch (Exception e) {
                          e.printStackTrace();
                      } finally {
                          kSession.dispose();
                      }
                  }
              });
          }
      

      (*e1)

      org.drools.core.rule.constraint.ConstraintEvaluationException: Error evaluating constraint '$bus1.karaoke.dvd[$title] != null && TOSTRING($bus1.karaoke.dvd[$title].artist) >= "01" && TOSTRING($bus1.karaoke.dvd[$title].artist) <= "39"' in [Rule "rule_mt_3d" in /work2/testdir/reproducer_mt_3d/target/classes/com/example/reproducer/Sample.drl]
              at org.drools.core.rule.constraint.MvelConstraint.evaluate(MvelConstraint.java:310)
              at org.drools.core.rule.constraint.MvelConstraint.isAllowedCachedLeft(MvelConstraint.java:239)
              at org.drools.core.common.SingleBetaConstraints.isAllowedCachedLeft(SingleBetaConstraints.java:135)
              at org.drools.core.phreak.PhreakJoinNode.doLeftInserts(PhreakJoinNode.java:108)
              at org.drools.core.phreak.PhreakJoinNode.doNode(PhreakJoinNode.java:71)
              at org.drools.core.phreak.RuleNetworkEvaluator.switchOnDoBetaNode(RuleNetworkEvaluator.java:568)
              at org.drools.core.phreak.RuleNetworkEvaluator.evalBetaNode(RuleNetworkEvaluator.java:554)
              at org.drools.core.phreak.RuleNetworkEvaluator.evalNode(RuleNetworkEvaluator.java:381)
              at org.drools.core.phreak.RuleNetworkEvaluator.innerEval(RuleNetworkEvaluator.java:341)
              at org.drools.core.phreak.RuleNetworkEvaluator.outerEval(RuleNetworkEvaluator.java:177)
              at org.drools.core.phreak.RuleNetworkEvaluator.evaluateNetwork(RuleNetworkEvaluator.java:135)
              at org.drools.core.phreak.RuleExecutor.reEvaluateNetwork(RuleExecutor.java:213)
              at org.drools.core.phreak.RuleExecutor.evaluateNetworkAndFire(RuleExecutor.java:88)
              at org.drools.core.concurrent.AbstractRuleEvaluator.internalEvaluateAndFire(AbstractRuleEvaluator.java:33)
              at org.drools.core.concurrent.SequentialRuleEvaluator.evaluateAndFire(SequentialRuleEvaluator.java:43)
              at org.drools.core.common.DefaultAgenda.fireLoop(DefaultAgenda.java:1111)
              at org.drools.core.common.DefaultAgenda.internalFireAllRules(DefaultAgenda.java:1058)
              at org.drools.core.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1050)
              at org.drools.core.impl.StatefulKnowledgeSessionImpl.internalFireAllRules(StatefulKnowledgeSessionImpl.java:1345)
              at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1336)
              at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1320)
              at com.example.reproducer.DroolsTest$1.run(DroolsTest.java:61)
              at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
              at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
              at java.base/java.lang.Thread.run(Thread.java:834)
      Caused by: [Error: unable to resolve method using strict-mode: java.lang.Object.artist()]
      [Near : {... karaoke.dvd[$title].artist) >= "01" && TOSTRING($b ....}]
                                                     ^
      [Line: 1, Column: 73]
              at org.mvel2.compiler.PropertyVerifier.getMethod(PropertyVerifier.java:581)
              at org.mvel2.compiler.PropertyVerifier.getBeanProperty(PropertyVerifier.java:295)
              at org.mvel2.compiler.PropertyVerifier.analyze(PropertyVerifier.java:133)
              at org.mvel2.compiler.ExpressionCompiler.verify(ExpressionCompiler.java:399)
              at org.mvel2.compiler.ExpressionCompiler._compile(ExpressionCompiler.java:281)
              at org.mvel2.util.ParseTools.subCompileExpression(ParseTools.java:2112)
              at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.getMethod(ReflectiveAccessorOptimizer.java:969)
              at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:400)
              at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.optimizeAccessor(ReflectiveAccessorOptimizer.java:167)
              at org.mvel2.ast.ASTNode.optimize(ASTNode.java:159)
              at org.mvel2.ast.ASTNode.getReducedValueAccelerated(ASTNode.java:115)
              at org.mvel2.ast.BinaryOperation.getReducedValueAccelerated(BinaryOperation.java:139)
              at org.mvel2.ast.And.getReducedValueAccelerated(And.java:35)
              at org.mvel2.ast.And.getReducedValueAccelerated(And.java:35)
              at org.mvel2.MVELRuntime.execute(MVELRuntime.java:85)
              at org.mvel2.compiler.CompiledExpression.getDirectValue(CompiledExpression.java:123)
              at org.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:119)
              at org.mvel2.MVEL.executeExpression(MVEL.java:945)
              at org.kie.soup.project.datamodel.commons.util.RawMVELEvaluator.executeExpression(RawMVELEvaluator.java:103)
              at org.drools.core.rule.constraint.MvelConditionEvaluator.evaluate(MvelConditionEvaluator.java:113)    <---------- (\*e1-1)
              at org.drools.core.rule.constraint.MvelConditionEvaluator.evaluate(MvelConditionEvaluator.java:89)
              at org.drools.core.rule.constraint.MvelConstraint.evaluate(MvelConstraint.java:308)
              ... 24 more
      

      (*e2)

      org.drools.core.rule.constraint.ConstraintEvaluationException: Error evaluating constraint '$bus1.karaoke.dvd[$title] != null && TOSTRING($bus1.karaoke.dvd[$title].artist) >= "01" && TOSTRING($bus1.karaoke.dvd[$title].artist) <= "39"' in [Rule "rule_mt_3d" in /work2/testdir/reproducer_mt_3d/target/classes/com/example/reproducer/Sample.drl]
              at org.drools.core.rule.constraint.MvelConstraint.evaluate(MvelConstraint.java:310)
              at org.drools.core.rule.constraint.MvelConstraint.isAllowedCachedLeft(MvelConstraint.java:239)
              at org.drools.core.common.SingleBetaConstraints.isAllowedCachedLeft(SingleBetaConstraints.java:135)
              at org.drools.core.phreak.PhreakJoinNode.doLeftInserts(PhreakJoinNode.java:108)
              at org.drools.core.phreak.PhreakJoinNode.doNode(PhreakJoinNode.java:71)
              at org.drools.core.phreak.RuleNetworkEvaluator.switchOnDoBetaNode(RuleNetworkEvaluator.java:568)
              at org.drools.core.phreak.RuleNetworkEvaluator.evalBetaNode(RuleNetworkEvaluator.java:554)
              at org.drools.core.phreak.RuleNetworkEvaluator.evalNode(RuleNetworkEvaluator.java:381)
              at org.drools.core.phreak.RuleNetworkEvaluator.innerEval(RuleNetworkEvaluator.java:341)
              at org.drools.core.phreak.RuleNetworkEvaluator.outerEval(RuleNetworkEvaluator.java:177)
              at org.drools.core.phreak.RuleNetworkEvaluator.evaluateNetwork(RuleNetworkEvaluator.java:135)
              at org.drools.core.phreak.RuleExecutor.reEvaluateNetwork(RuleExecutor.java:213)
              at org.drools.core.phreak.RuleExecutor.evaluateNetworkAndFire(RuleExecutor.java:88)
              at org.drools.core.concurrent.AbstractRuleEvaluator.internalEvaluateAndFire(AbstractRuleEvaluator.java:33)
              at org.drools.core.concurrent.SequentialRuleEvaluator.evaluateAndFire(SequentialRuleEvaluator.java:43)
              at org.drools.core.common.DefaultAgenda.fireLoop(DefaultAgenda.java:1111)
              at org.drools.core.common.DefaultAgenda.internalFireAllRules(DefaultAgenda.java:1058)
              at org.drools.core.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1050)
              at org.drools.core.impl.StatefulKnowledgeSessionImpl.internalFireAllRules(StatefulKnowledgeSessionImpl.java:1345)
              at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1336)
              at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1320)
              at com.example.reproducer.DroolsTest$1.run(DroolsTest.java:65)
              at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
              at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
              at java.base/java.lang.Thread.run(Thread.java:834)
      Caused by: [Error: not a statement, or badly formed structure]
      [Near : {... != null && TOSTRING($bus1.karaoke.dvd[$title].arti ....}]
                                       ^
      [Line: 1, Column: 47]
              at org.mvel2.compiler.ExpressionCompiler._compile(ExpressionCompiler.java:311)
              at org.mvel2.util.ParseTools.subCompileExpression(ParseTools.java:2112)
              at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.getMethod(ReflectiveAccessorOptimizer.java:969)
              at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:400)
              at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.optimizeAccessor(ReflectiveAccessorOptimizer.java:167)
              at org.mvel2.ast.ASTNode.optimize(ASTNode.java:159)
              at org.mvel2.ast.ASTNode.getReducedValueAccelerated(ASTNode.java:115)
              at org.mvel2.ast.BinaryOperation.getReducedValueAccelerated(BinaryOperation.java:139)
              at org.mvel2.ast.And.getReducedValueAccelerated(And.java:35)
              at org.mvel2.ast.And.getReducedValueAccelerated(And.java:35)
              at org.mvel2.MVELRuntime.execute(MVELRuntime.java:85)
              at org.mvel2.compiler.CompiledExpression.getDirectValue(CompiledExpression.java:123)
              at org.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:119)
              at org.mvel2.MVEL.executeExpression(MVEL.java:945)
              at org.kie.soup.project.datamodel.commons.util.RawMVELEvaluator.executeExpression(RawMVELEvaluator.java:103)
              at org.drools.core.rule.constraint.MvelConditionEvaluator.evaluate(MvelConditionEvaluator.java:113)    <---------- (\*e2-1)
              at org.drools.core.rule.constraint.MvelConditionEvaluator.evaluate(MvelConditionEvaluator.java:89)
              at org.drools.core.rule.constraint.MvelConstraint.evaluate(MvelConstraint.java:308)
              ... 24 more
      Caused by: java.lang.NullPointerException
              at org.mvel2.compiler.PropertyVerifier.getCollectionProperty(PropertyVerifier.java:403)
              at org.mvel2.compiler.PropertyVerifier.analyze(PropertyVerifier.java:139)
              at org.mvel2.compiler.ExpressionCompiler.verify(ExpressionCompiler.java:399)
              at org.mvel2.compiler.ExpressionCompiler._compile(ExpressionCompiler.java:281)
              ... 41 more
      

              rhn-support-tkobayas Toshiya Kobayashi
              rhn-support-myoshida Masato Yoshida
              Paolo Bizzarri Paolo Bizzarri
              Paolo Bizzarri Paolo Bizzarri
              Votes:
              0 Vote for this issue
              Watchers:
              8 Start watching this issue

                Created:
                Updated:
                Resolved: