7 Replies Latest reply on Jun 4, 2011 3:35 AM by Sandeep Bisht

    Unable to connect the DB connection Master slave configuration

    Sandeep Bisht Newbie

      Hi All,

       

      i am unable to get Data base connection if i use Master slave configuration (if first socket or db connection down connection-url is down)

      If first is up and second one also up everything is fine.

      when first is goes down connection is pointing NullPointer Exception

      Where I am doing Wrong Please Help

      My *-ds.xml is

       

      ------------------------------------------------------------------------------------------------------------------------------------------------------------------

      <local-tx-datasource>

          <jndi-name>defaultds</jndi-name>

          <connection-url>jdbc:mysql://first/.. | jdbc:mysql://second/..</connection-url>

           <url-delimeter>|</url-delimeter>

          <driver-class>com.mysql.jdbc.Driver</driver-class>

          <user-name>blah</user-name>

          <password>blah</password>

           <!-- The minimum connections in a pool/sub-pool. Pools are lazily constructed on first use -->

            <min-pool-size>5</min-pool-size>

           <!-- The maximum connections in a pool/sub-pool -->

           <max-pool-size>0</max-pool-size>

         

          <metadata>

             <type-mapping>mySQL</type-mapping>

          </metadata>

      </local-tx-datasource>

      -----------------------------------------------------------------------------------------------------------------------------------------------------------------------

       

      Thanks in advance?

        • 1. Re: Unable to connect the DB connection Master slave configuration
          Wolfgang Knauf Master

          Hi,

           

          found this: http://blogs.sourceallies.com/2010/03/mysql-masterslave-configuration-with-ejb3-and-jpa/

           

          According to the java snippet in this article, the URL should be "jdbc:mysql:replication://master,slave1,slave2,slave3/databasename"

           

          Hope this helps (I don't have more knowledge about this, just asked google)

           

          Wolfgang

          • 2. Re: Unable to connect the DB connection Master slave configuration
            Sandeep Bisht Newbie

            above link Doesn't help me..Cause I am using JBoss 5.0.1 GA...and above link is for JBoss 4.2.1. The main question is that how to get second URL when first is down which is seprated by url-delimeter. i couldn't get second connection on my Java Bean for my web app.(when 1st connection is down).

             

             

             

            @ Wolfgang : any ways thanks

            • 3. Re: Unable to connect the DB connection Master slave configuration
              Wolfgang Knauf Master

              Hi,

               

              after reading a bit more, I think that we both were mixing two features ;-).

               

              Your config contains a failover configuration, where JBoss will pick another datasource, when the first one is broken: http://community.jboss.org/wiki/JBossJCADatabaseFailover

               

               

              My link was to a MySQL master/slave configuration, but as the comment in the wiki document suggests, the combination of load balancing and failover connections is a missing feature.

               

              But I also found this document: http://neilhan.blogspot.com/2006/11/spring-hibernate-and-mysql-replication.html - the last comment sounds as if load balancing can be activated by some property. But I don't know whether this applies to JBoss.

               

              Maybe it works to use a combination of both configurations: config a master/slave database with "jdbc:mysql:replication://master,slave1,slave2,slave3/databasename" URL and then add all possible combinations of host names as failover URLs:

              "jdbc:mysql:replication://master,slave1,slave2,slave3/databasename|jdbc:mysql:replication://slave1,master,slave2,slave3/databasename|jdbc:mysql:replication://slave2,master,slave1,slave3/databasename|..."  (so that each host in the list is the first one)?

               

              If all this does not help, I cannot provider further ideas.

               

              Best regards

               

              Wolfgang

              • 4. Re: Unable to connect the DB connection Master slave configuration
                Sandeep Bisht Newbie

                Hi again,

                 

                Now i got something

                <local-tx-datasource>

                    <jndi-name>defaultds</jndi-name>

                    <connection-url>jdbc:mysql://first , second/DBSchema?something=false</connection-url>

                     <driver-class>com.mysql.jdbc.Driver</driver-class>

                    <user-name>blah</user-name>

                    <password>blah</password>

                     <!-- The minimum connections in a pool/sub-pool. Pools are lazily constructed on first use -->

                      <min-pool-size>5</min-pool-size>

                     <!-- The maximum connections in a pool/sub-pool -->

                     <max-pool-size>0</max-pool-size>

                 

                    <metadata>

                       <type-mapping>mySQL</type-mapping>

                    </metadata>

                </local-tx-datasource>

                 

                It got connection but need to Restart the JBoss Application

                 

                Condition are

                1st

                 

                if first connection url is up and second is down

                 

                everything is fine now

                 

                2nd

                 

                if second connection url is up and first is down

                 

                got this error

                 

                com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:

                 

                ** BEGIN NESTED EXCEPTION **

                 

                java.io.EOFException

                 

                STACKTRACE:

                 

                java.io.EOFException

                        at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:1963)

                        at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2375)

                        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2874)

                        at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1623)

                        at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1715)

                        at com.mysql.jdbc.Connection.execSQL(Connection.java:3243)

                        at com.mysql.jdbc.Connection.execSQL(Connection.java:3172)

                        at com.mysql.jdbc.Statement.executeQuery(Statement.java:1197)

                        at org.jboss.resource.adapter.jdbc.WrappedStatement.executeQuery(WrappedStatement.java:226)

                        at org.xxxClass.commons.XXXX.XXX.XXX.XXXXX.fetchTitleLabels(JDBCAccessFactory.java:506)

                        at org.xxxClass.xxx.model.XXX.XXXTitleXX(RegistrationModel.java:70)

                        at org.xxxClass.xxx.bean.XXXX.getTitleLabels(Registration.java:338)

                        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

                        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

                        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

                        at java.lang.reflect.Method.invoke(Method.java:616)

                        at javax.el.BeanELResolver.getValue(BeanELResolver.java:62)

                        at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:54)

                        at com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:72)

                        at org.apache.el.parser.AstValue.getValue(AstValue.java:118)

                        at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)

                        at org.apache.jasper.el.JspValueExpression.getValue(JspValueExpression.java:101)

                        at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:190)

                        at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:178)

                        at javax.faces.component.UISelectItems.getValue(UISelectItems.java:129)

                        at com.sun.faces.renderkit.SelectItemsIterator.initializeItems(SelectItemsIterator.java:202)

                        at com.sun.faces.renderkit.SelectItemsIterator.hasNext(SelectItemsIterator.java:135)

                        at com.sun.faces.renderkit.html_basic.MenuRenderer.renderOptions(MenuRenderer.java:760)

                        at com.sun.faces.renderkit.html_basic.MenuRenderer.renderSelect(MenuRenderer.java:842)

                        at com.sun.faces.renderkit.html_basic.MenuRenderer.encodeEnd(MenuRenderer.java:296)

                        at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:878)

                        at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:295)

                        at com.sun.faces.renderkit.html_basic.GridRenderer.renderRow(GridRenderer.java:185)

                        at com.sun.faces.renderkit.html_basic.GridRenderer.encodeChildren(GridRenderer.java:129)

                        at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:848)

                        at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1613)

                        at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1616)

                        at org.richfaces.renderkit.html.LayoutRenderer.renderLayout(LayoutRenderer.java:65)

                        at org.richfaces.renderkit.html.LayoutRenderer.doEncodeChildren(LayoutRenderer.java:45)

                        at org.ajax4jsf.renderkit.RendererBase.encodeChildren(RendererBase.java:120)

                        at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:848)

                        at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:277)

                        at org.ajax4jsf.renderkit.RendererBase.renderChildren(RendererBase.java:258)

                        at org.richfaces.renderkit.html.PanelRenderer.doEncodeChildren(PanelRenderer.java:200)

                        at org.richfaces.renderkit.html.PanelRenderer.doEncodeChildren(PanelRenderer.java:195)

                        at org.ajax4jsf.renderkit.RendererBase.encodeChildren(RendererBase.java:120)

                        at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:848)

                        at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:277)

                        at org.ajax4jsf.renderkit.RendererBase.renderChildren(RendererBase.java:258)

                        at org.richfaces.renderkit.html.PanelRenderer.doEncodeChildren(PanelRenderer.java:200)

                        at org.richfaces.renderkit.html.PanelRenderer.doEncodeChildren(PanelRenderer.java:195)

                        at org.ajax4jsf.renderkit.RendererBase.encodeChildren(RendererBase.java:120)

                        at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:848)

                        at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:287)

                        at com.sun.faces.renderkit.html_basic.GridRenderer.renderRow(GridRenderer.java:185)

                        at com.sun.faces.renderkit.html_basic.GridRenderer.encodeChildren(GridRenderer.java:129)

                        at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:848)

                        at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1613)

                        at javax.faces.render.Renderer.encodeChildren(Renderer.java:168)

                        at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:848)

                        at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:277)

                        at org.ajax4jsf.renderkit.RendererBase.renderChildren(RendererBase.java:258)

                        at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:279)

                        at org.ajax4jsf.renderkit.RendererBase.renderChildren(RendererBase.java:258)

                        at org.richfaces.renderkit.html.PageRenderer.doEncodeChildren(PageRenderer.java:265)

                        at org.richfaces.renderkit.html.PageRenderer.doEncodeChildren(PageRenderer.java:254)

                        at org.ajax4jsf.renderkit.RendererBase.encodeChildren(RendererBase.java:120)

                        at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:848)

                        at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1613)

                        at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1616)

                        at com.sun.faces.application.view.JspViewHandlingStrategy.doRenderView(JspViewHandlingStrategy.java:420)

                        at com.sun.faces.application.view.JspViewHandlingStrategy.renderView(JspViewHandlingStrategy.java:209)

                        at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:126)

                        at org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:100)

                        at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:176)

                        at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:127)

                        at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)

                        at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)

                        at javax.faces.webapp.FacesServlet.service(FacesServlet.java:313)

                        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)

                        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

                        at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:206)

                        at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)

                        at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:388)

                        at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:515)

                        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)

                        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

                        at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)

                        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)

                        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

                        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)

                        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)

                        at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)

                        at org.jboss.web.tomcat.service.session.ClusteredSessionValve.invoke(ClusteredSessionValve.java:109)

                        at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)

                        at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)

                        at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)

                        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)

                        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)

                        at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)

                        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)

                        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)

                        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)

                        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:601)

                        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)

                        at java.lang.Thread.run(Thread.java:636)

                 

                 

                ** END NESTED EXCEPTION **

                 

                3rd step

                 

                When i restart the application with the second conditon again everything is fine....

                 

                 

                Please Help!

                 

                Message was edited by: Sandeep Bisht

                • 5. Re: Unable to connect the DB connection Master slave configuration
                  Wolfgang Knauf Master

                  Hi,

                   

                  I assume that my previous reply was sent while you were writing your own post?

                   

                  I saw in the web that you can configure a "connection checker". See e.g. the link in my first reply for a sample. Do you have this checker in your own config, too?

                   

                  Best regards

                   

                  Wolfgang

                  • 6. Re: Unable to connect the DB connection Master slave configuration
                    Sandeep Bisht Newbie

                    Hi wolfGang

                     

                     

                    The Problem has been solved..........

                     

                    Thanks for your valueble time.

                     

                     

                    Solution is not exactly as above u provided...but it was really Helpfull for me by some mean

                     

                     

                     

                    Thanks and Regards

                    Sandeep Bisht

                    • 7. Re: Unable to connect the DB connection Master slave configuration
                      Sandeep Bisht Newbie

                      Hi All,

                       

                      I got the Answer of my question. jboss is not pinging to Database so i add the following tag into my *-ds.xml

                       

                       

                      <local-tx-datasource>

                          <jndi-name>defaultds</jndi-name>

                          <connection-url>jdbc:mysql://first , second/DBSchema?something=false</connection-url>

                           <driver-class>com.mysql.jdbc.Driver</driver-class>

                          <user-name>blah</user-name>

                          <password>blah</password>

                           <!-- The minimum connections in a pool/sub-pool. Pools are lazily constructed on first use -->

                            <min-pool-size>5</min-pool-size>

                           <!-- The maximum connections in a pool/sub-pool -->

                           <max-pool-size>20</max-pool-size>

                            <autoReconnect>true</autoReconnect>

                           <failOverReadOnly>true</failOverReadOnly>

                           <idle-timeout-minutes>0</idle-timeout-minutes>

                           <valid-connection-checker-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLValidConnectionChecker</valid-connection-checker-class-name>

                         

                      <metadata>

                             <type-mapping>mySQL</type-mapping>

                          </metadata>

                        </local-tx-datasource>

                       

                      </datasources>

                       

                      These Darken tag really Help me out from the failOver condition thanks a lot wolfGang once again

                      1 of 1 people found this helpful