1 Reply Latest reply on May 19, 2013 4:16 PM by Sham HC

    DataSourcePool reset to null after CQ Cluster Failover

    burnray Level 1

      I setup 2 cq instances and cluster them. In my global.jsp file which is included at the beginning of my page, a DataSourcePool object  is created, for the sake of getting RDBMS connection from JDBC connection pool in OSGI console:

       

          // get DataSourcePool

          DataSourcePool dataSourcePool = sling.getService(DataSourcePool.class);

          if(null == DBUtils.getDataSourcePool())

          {

                    DBUtils.setDataSourcePool(dataSourcePool);

          }

       

      Here comes codes in DBUtils:

       

      public class DBUtils

      {

        private static DataSourcePool DSP_SERVICE;

                private static final Logger log = LoggerFactory.getLogger(DBUtils.class);

       

                private static final String _DATA_SROUCE_STRING = "datasourceName";

       

        public static Connection getDBConnection() throws DataSourceNotFoundException,

               SQLException

       

                {

                          log.info("DBUtils");

                          Connection connection;

                          try

                          {

                                    DataSource ds = null;

                                    if (DSP_SERVICE !=null)

                                    {

                                              log.info("DSP_SERVICE is not null");

                                    }

                                    else

                                    {

                              log.info("DSP_SERVICE is null");

                                    }

                                    ds = (DataSource) DSP_SERVICE

                                            .getDataSource(_DATA_SROUCE_STRING);

                                    connection = ds.getConnection();

                          }

                          catch (Exception e)

                          {

                                    log.error("DBUtils", e);          

                          }

                          return connection;

                }

       

                public static DataSourcePool getDataSourcePool()

                {

                          return DSP_SERVICE;

                }

       

                public static void setDataSourcePool(DataSourcePool dsp)

                {

                          DSP_SERVICE = dsp;

                }

      }

       

      Everything works fine if CQ cluster failover doesn't happen. The case is, when CQ cluster failover, exception is caught and after debugging I found the DSP_SERVICE is null:

      1. User browse the page, the global.jsp is executed when page is rendering, DSP_SERVICE value is set (which is not null at this point);

      2. After the page rendered, CQ Master is down, the orignal CQ slave will become master and continue provide service to requests.

      3. Then user trigger an event on the page (clicking a form submit button), which will call DBUtils.getDBConnection().

      4. Exception is caught, DSP_SERVICE is null. Error on page.

      5. User refresh the page, the global.jsp is executed again and DSP_SERVICE gets it value. All things go fine.

       

      For system persistency I have to make the CQ cluster failover transparent to user. Is it a cq cluster bug or there is something i miss? Would you provide solution or ideas to solve this problem?