3 Replies Latest reply: Oct 10, 2012 4:34 PM by Van Halbert RSS

    Using Byteman to debug Teiid

    Van Halbert Expert

      Starting a discussion on using Byteman to debug Teiid.   Once more comments / examples are gathered, an article can be written that can better serve as a How-To.


      Here are some of the questions that I'll attempt to answer:


      -  Why Byteman? 

      -  Are there examples?

      -  How do you setup the examples and run them?



      1. Why Byteman?  Its was fairly painless to setup and easy to inject new debug statements on the fly without having to restart the server
      2. Are there examples?  (see MonitorTranslator.btm attachment)
        RULE print Passed Command
        CLASS ^org.teiid.translator.ExecutionFactory
        HELPER org.teiid.byteman.BytemanHelperForTranslator
        METHOD createResultSetExecution
        AT ENTRY
        BIND  cmd:QueryExpression=$1
        IF TRUE
           DO printToString(cmd);  
        RULE trace Execution
        INTERFACE org.teiid.translator.Execution
        HELPER org.teiid.byteman.BytemanHelperForTranslator
        METHOD execute
        AT EXIT
        BIND executioner=$0;
        IF TRUE
           DO debug(executioner.getClass().getName() + " performed execute\n");
        RULE print Row Count
        INTERFACE ^org.teiid.translator.ResultSetExecution
        HELPER org.teiid.byteman.BytemanHelperForTranslator
        METHOD next
        AFTER INVOKE next
        IF TRUE
           DO printCount($!);  

        Notice the HELPER class, org.teiid.byteman.BytemanHelperForTranslator, that is being used.  I've written a helper class to assist, initially, with generically handling objects and printing out relevant information.   Attached you will find the source code for this class and the test.jar, and I'll cover installing it farther down.


      3. How to setup and run the examples


        -  Download latest byteman (2.1.0):   https://www.jboss.org/byteman/downloads

        -  Byteman has the option to install the agent using bminstall, but I found it easier to control (for me) to just change the run.conf by adding the following: 


        JAVA_OPTS="$JAVA_OPTS -Dorg.jboss.byteman.transform.all -Dorg.jboss.byteman.debug -javaagent:${BYTEMAN_HOME}/lib/byteman.jar=listener:true,boot:${BYTEMAN_HOME}/lib/byteman.jar" 


        Note:  initially, I would change -Dorg.jboss.byteman.debug to -Dorg.jboss.byteman.verbose   until you get the hang of it and your rules are fairly stable. 


        -  Compile org.teiid.byteman.BytemanHelperForTranslator and create a jar.  (see test.jar attachment that can be used with the rules above)

        -  deploy the jar by running:    bmsubmit.sh [ -b | -s ] <jar> 

                 where  [ -b | -s ] determine if you want the jar on the boot path or the system path.  I've been using boot path.

                           jar is the fullpath to the jar


        Note:  if you change and rebuild jar, the server must be restarted and the jar be redeployed.


        -  Create your rules file with the .btm extension  (see MonitorTranslator.btm attachment)

        -  deploy the rules by running:  bmsubmit.sh -l <rule file>

        -  to undeploy the rules, run:   bmsubmit.sh -u <rule file>


        You can keep deploying / undeploying and running your test without restarting server.   If you get errors on deployment of rules and you want to clean it up, run:  bmsubmit.sh -u  (which will uninstall all rules and start fresh) 


        Once your rules are deployed, run your test and you should see the output in the console.  



        10:26:24,316 INFO  [STDOUT] Installed rule using default helper : print Passed Command

        10:26:24,317 INFO  [STDOUT] rule.debug{print Passed Command} : vvvvvvvvvvvvvvvvvvvvvvvvvvv

        10:26:24,317 INFO  [STDOUT] rule.debug{print Passed Command} :  ToString org.teiid.language.Select: SELECT com.jboss.datagrid.hotrod.Team.Name FROM com.jboss.datagrid.hotrod.Team

        10:26:24,317 INFO  [STDOUT] rule.debug{print Passed Command} : ^^^^^^^^^^^^^^^^^^^^^^^^^^^

        10:26:24,351 INFO  [STDOUT] Installed rule using default helper : trace Execution

        10:26:24,352 INFO  [STDOUT] rule.debug{trace Execution} : org.teiid.translator.object.ObjectExecution performed execute

        10:26:24,358 INFO  [STDOUT] Installed rule using default helper : print Row Count

        10:26:24,358 INFO  [STDOUT] rule.debug{print Row Count} : vvvvvvvvvvvvvvvvvvvvvvvvvvv

        10:26:24,359 INFO  [STDOUT] rule.debug{print Row Count} :  Count java.util.ArrayList: 1

        10:26:24,359 INFO  [STDOUT] rule.debug{print Row Count} : ^^^^^^^^^^^^^^^^^^^^^^^^^^^

        • 1. Re: Using Byteman to debug Teiid
          Van Halbert Expert

          Have you ever run across a case where someone is seeing an issue (Teiid engine (non-translator) related) on their JBoss AS server and they want you to debug it.  However, you can't have access their machine nor have access to their jdbc data sources.  You must use your own server to debug the issue.   Here's a possible solution.   The following rules to use are:


          -  TranslatorJDBCSerializeData.btm :  will serialize the rows being returned by the translator to the file system.

          -  TranslatorJDBCDeserializeData.btm :  will deserialize (read) the data from the file system and return them as the rows being returned by the translator.

          -  Updated test.jar that contains 2 new helper classes:  TranslatorSerializeData.java and TranslatorDeserializeData.java


          On the server you can't have access to, have them install the TranslatorJDBCSerializeData.btm rule and run their query, then zip up the "jboss-as/bin/serialize_output" directory and send it to you.  On your server, unzip the file into the "bin" directory (e.g., structure will be jboss-as/bin/serialize_output ).   Then you install the TranslatorJDBCDeserializeData.btm rule and run the same query.  And with any luck you should see the same behavior the other person is seeing.  Now you can debug the issue.

          • 2. Re: Using Byteman to debug Teiid
            Steven Hawkins Master

            This looks to be saving a row per file.  Shouldn't it be a file per source query?  Creating potentially millions of files in a single directory can be an issue.

            • 3. Re: Using Byteman to debug Teiid
              Van Halbert Expert

              Its actaully saving one folder/file per row.    Where you could have lots of folders in one folder.  But your right, the saving of the results should be changed to accomodate large resultsets.