Debugging UCP Connection Pool using XA Datasource pointing to a RAC database

JAVA code fails with   loader constraint violation loading XAResource.class

            pdsXa = oracle.ucp.jdbc.PoolDataSourceFactory.getPoolXADataSource();  
              // PoolDataSource and UCP configuration
              //set the connection properties on the data source and pool properties
            String ONS_CONFIG = "nodes=hract21:6200,hract22:6200,hract23:6200";
            pdsXa.setONSConfiguration ( ONS_CONFIG);
            pdsXa.setFastConnectionFailoverEnabled( true);
            pdsXa.setUser("scott");
            pdsXa.setPassword("tiger");
            pdsXa.setURL("jdbc:oracle:thin:@ract2-scan.grid12c.example.com:1521/banka");
            pdsXa.setConnectionFactoryClassName("oracle.jdbc.xa.client.OracleXADataSource");
            pdsXa.setInitialPoolSize(5);
            pdsXa.setMinPoolSize(5);
            pdsXa.setMaxPoolSize(20);
            System.out.println("--> UCP Pool with FCF / OracleXADataSource sucessfuly initialized !");
            setPoolStats(getPoolStats () + StackTraceUtil.add_hmtl_pre_tag( "Jar File:" + clsInfo));
            setPoolStats(getPoolStats () + StackTraceUtil.add_hmtl_pre_tag( "Class Loader:" + loaderInfo));
            pdsXa.setConnectionPoolName(poolNameXA);
            XAConnection xaconn = pdsXa.getXAConnection();

Line XAConnection xaconn = pdsXa.getXAConnection(); throws following Exception 
  Runtime exceptiom in initPoolXA() : 
loader constraint violation: loader (instance of ) previously initiated loading for a 
   different type with name  "javax/transaction/xa/XAResource"

  java.lang.LinkageError: loader constraint violation: loader (instance of ) previously initiated loading for a 
     different type with name:  "javax/transaction/xa/XAResource"
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2615)
    at java.lang.Class.privateGetPublicMethods(Class.java:2733)
    at java.lang.Class.getMethods(Class.java:1472)
    at sun.misc.ProxyGenerator.generateClassFile(ProxyGenerator.java:426)
    at sun.misc.ProxyGenerator.generateProxyClass(ProxyGenerator.java:323)
    at java.lang.reflect.Proxy$ProxyClassFactory.apply(Proxy.java:672)
    at java.lang.reflect.Proxy$ProxyClassFactory.apply(Proxy.java:592)
    at java.lang.reflect.WeakCache$Factory.get(WeakCache.java:244)
    at java.lang.reflect.WeakCache.get(WeakCache.java:141)
    at java.lang.reflect.Proxy.getProxyClass0(Proxy.java:455)
    at java.lang.reflect.Proxy.newProxyInstance(Proxy.java:738)
    at oracle.ucp.jdbc.proxy.XAConnectionProxyFactory.createConnectionProxy(XAConnectionProxyFactory.java:79)
    at oracle.ucp.jdbc.PoolXADataSourceImpl.getXAConnection(PoolXADataSourceImpl.java:226)
    at oracle.ucp.jdbc.PoolXADataSourceImpl.getXAConnection(PoolXADataSourceImpl.java:149)
    at UcpPool.UcpPoolBean.initPoolXA(UcpPoolBean.java:584)

Problem  : Two components tries to load the same Java class

What JAR/Component has already loaded class javax/transaction/xa/XAResource ?

Adding following lines to the above code to understand what JAR has already 
loaded "javax/transaction/xa/XAResource"
   Class cls=Class.forName("javax.transaction.xa.XAResource");
   ClassLoader cLoader = cls.getClassLoader();
   loaderInfo = cLoader.toString();
   clsInfo = cls.getResource("XAResource.class").toString();

Output:
Jar File:jar:file:/usr/local/wildfly-8.2.0.Final/modules/system/layers/base/javax/transaction/api
/main/jboss-transaction-api_1.2_spec-1.0.0.Final.jar!/javax/transaction/xa/XAResource.class

Class Loader:ModuleClassLoader for Module "javax.transaction.api:main" from local module loader @43d9349c (finder:
local module finder @690d1090 (roots: /usr/local/wildfly-8.2.0.Final/modules,/usr/local/wildfly-8.2.0.Final/module

  • XAResource.class was loaded  from  jboss-transaction-api_1.2_spec-1.0.0.Final.jar
  • Question:  What Component tries to load “javax/transaction/xa/XAResource”

Debugging the JVM with -verbose:class

Add following parameter to JBOSS configuration and restart WildFLY server in Debug Mode
-Dappdynamics.bciengine.class.lookahead=!* -XX:+TraceLoaderConstraints -verbose:class
Review newly created WildFly Traces from Netbeans Console
Before UCP initialization :
[Setting class object in existing constraint for name: org/jboss/as/server/deployment/DeploymentPhaseContext and loader org/jboss/modules/ModuleClassLoader ]
[Loaded javax.transaction.xa.XAResource from jar:file:/usr/local/wildfly-8.2.0.Final/modules/system/layers/base/javax/transaction
/api/main/jboss-transaction-api_1.2_spec-1.0.0.Final.jar!/]
[Updating constraint for name javax/transaction/xa/XAResource, loader org/jboss/modules/ModuleClassLoader, by setting class object ]

--> XAResource.class was loaded jboss-transaction-api_1.2_spec-1.0.0.Final.jar

After creating a UCP XA Datasource:
[Loaded oracle.ucp.jdbc.ValidConnection from vfs:/usr/local/wildfly-8.2.0.Final/standalone/deployments/WF_UCPPool.war/WEB-INF/lib/ucp.jar]
[Loaded oracle.ucp.jdbc.oracle.Poolable from vfs:/usr/local/wildfly-8.2.0.Final/standalone/deployments/WF_UCPPool.war/WEB-INF/lib/ucp.jar]
[Loaded oracle.ucp.jdbc.proxy.JDBCConnectionProxyFactory from vfs:/usr/local/wildfly-8.2.0.Final/standalone/deployments/WF_UCPPool.war/WEB-INF/lib/ucp.jar]
[Loaded oracle.ucp.jdbc.proxy.XAConnectionProxyFactory from vfs:/usr/local/wildfly-8.2.0.Final/standalone/deployments/WF_UCPPool.war/WEB-INF/lib/ucp.jar]
[Loaded oracle.ucp.jdbc.proxy.JDBCConnectionProxyFactory$SwitchTable from vfs:/usr/local/wildfly-8.2.0.Final/standalone/deployments/WF_UCPPool.war/WEB-INF/lib/ucp.jar]
[Loaded oracle.jdbc.replay.ReplayableConnection from jar:file:/usr/local/wildfly-8.2.0.Final/modules/com/oracle/ojdbc/main/ojdbc7.jar!/]
[Extending constraint for name java/lang/reflect/InvocationHandler by adding loader[10]: org/jboss/modules/ModuleClassLoader  ]
[Loaded java.lang.reflect.Proxy$KeyX from /usr/java/jdk1.7.0_71/jre/lib/rt.jar]
[Loaded oracle.ucp.AbandonedConnectionTimeoutCallback from vfs:/usr/local/wildfly-8.2.0.Final/standalone/deployments/WF_UCPPool.war/WEB-INF/lib/ucp.jar]
[Loaded javax.transaction.xa.XAResource from /usr/java/jdk1.7.0_71/jre/lib/rt.jar]
[Constraint check failed for name javax/transaction/xa/XAResource, loader <bootloader>: the presented class object differs from that stored ]
[Extending constraint for name java/io/Writer by adding loader[6]: org/jboss/modules/ModuleClassLoader  ]
--> XAResource.class was loaded by UCP from rt.jar 

 

Problem Summary

  • WildFly loads XAResource.class from jboss-transaction-api_1.2_spec-1.0.0.Final.jar whereas UCP loads the class from rt.jar
  • This is the root causes  the above exception when UCP tries to load XAResource class a 2.nd time
  • Setting   -Dappdynamics.bciengine.class.lookahead=!*  doesn’t fix the problem
  • Installing the Oracle JDBC driver as a Wildfly module doesn’t fix the problem

Current Status – Not yet resolved !

  • Found no solution to fix this issue !
    –> If anybody has found a solution please comment this POST !

Reference

Leave a Reply

Your email address will not be published. Required fields are marked *