You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-user@db.apache.org by Kristian Waagan <kr...@oracle.com> on 2010/08/02 09:51:10 UTC

Re: Shutting down a database that is already shut down

On Fri, Jul 30, 2010 at 02:30:34PM -0700, David Van Couvering wrote:
> Do I have to worry about ensuring that a database is running before I try to
> shut it down, or is it OK to get a connection with URL ";shutdown=true" on a
> database that's not booted.
> 
> If I were to do that, does it boot the database and then shut it down again, or
> does it do nothing?

Hi David,

Derby won't boot the database, but you will get a database not found
exception. The exception may also be written to derby.log, which casues
the file to grow a lot faster if you issue a lot of shutdown requests
for non-booted databases.

You get the exception because the getConnection call must either
return a valid connection or throw an exception. Since we haven't shut
down the database (it wasn't booted), we cannot throw an exception
saying we did so. Getting database not found seems a bit odd too, but
maybe Derby currently has to boot a database to confirm that it exists?


Regards,
-- 
Kristian

> 
> Thanks,
> 
> David
> 
> --
> David W. Van Couvering
> 
> http://www.linkedin.com/in/davidvc
> http://davidvancouvering.blogspot.com
> http://twitter.com/dcouvering

Socket Closed Exception when pinging NetworkServerControl

Posted by Pavel Bortnovskiy <PB...@Jefferies.com>.
Hello:

I am getting intermittent (rare, but causing fatal shutdown) exceptions 
when pinging NetworkServerControl:

2010-08-02 15:31:25,491 [ApacheDerbyServer] INFO 
components.DerbyServerComponent  - 2010-08-02 19:31:25.491 GMT : Error on 
client socket:Socket closed
2010-08-02 15:31:25,492 [ApacheDerbyServer] INFO 
components.DerbyServerComponent  - 2010-08-02 19:31:25.492 GMT : Socket 
closed
2010-08-02 15:31:25,492 [ApacheDerbyServer] INFO 
components.DerbyServerComponent  - java.net.SocketException: Socket closed
2010-08-02 15:31:25,492 [ApacheDerbyServer] INFO 
components.DerbyServerComponent  -    at 
java.net.SocketInputStream.socketRead0(Native Method)
2010-08-02 15:31:25,493 [ApacheDerbyServer] INFO 
components.DerbyServerComponent  -    at 
java.net.SocketInputStream.read(SocketInputStream.java:129)
2010-08-02 15:31:25,493 [ApacheDerbyServer] INFO 
components.DerbyServerComponent  -    at 
java.net.SocketInputStream.read(SocketInputStream.java:90)
2010-08-02 15:31:25,493 [ApacheDerbyServer] INFO 
components.DerbyServerComponent  -    at 
org.apache.derby.impl.drda.NetworkServerControlImpl.fillReplyBuffer(Unknown 
Source)
2010-08-02 15:31:25,494 [ApacheDerbyServer] INFO 
components.DerbyServerComponent  -    at 
org.apache.derby.impl.drda.NetworkServerControlImpl.readResult(Unknown 
Source)
2010-08-02 15:31:25,494 [ApacheDerbyServer] INFO 
components.DerbyServerComponent  -    at 
org.apache.derby.impl.drda.NetworkServerControlImpl.pingWithNoOpen(Unknown 
Source)
2010-08-02 15:31:25,494 [ApacheDerbyServer] INFO 
components.DerbyServerComponent  -    at 
org.apache.derby.impl.drda.NetworkServerControlImpl.ping(Unknown Source)
2010-08-02 15:31:25,495 [ApacheDerbyServer] INFO 
components.DerbyServerComponent  -    at 
org.apache.derby.drda.NetworkServerControl.ping(Unknown Source)
2010-08-02 15:31:25,495 [ApacheDerbyServer] INFO 
components.DerbyServerComponent  -    at 
com.jefco.fi.geni.components.DerbyServerComponent.run(DerbyServerComponent.java:142)
2010-08-02 15:31:25,495 [ApacheDerbyServer] INFO 
components.DerbyServerComponent  -    at 
java.lang.Thread.run(Thread.java:619)
2010-08-02 15:31:25,496 [ApacheDerbyServer] ERROR 
components.DerbyServerComponent  - Error while pinging 
NetworkServerControl:
java.net.SocketException: Socket closed
        at java.net.SocketInputStream.socketRead0(Native Method)
        at java.net.SocketInputStream.read(SocketInputStream.java:129)
        at java.net.SocketInputStream.read(SocketInputStream.java:90)
        at 
org.apache.derby.impl.drda.NetworkServerControlImpl.fillReplyBuffer(Unknown 
Source)
        at 
org.apache.derby.impl.drda.NetworkServerControlImpl.readResult(Unknown 
Source)
        at 
org.apache.derby.impl.drda.NetworkServerControlImpl.pingWithNoOpen(Unknown 
Source)
        at 
org.apache.derby.impl.drda.NetworkServerControlImpl.ping(Unknown Source)
        at org.apache.derby.drda.NetworkServerControl.ping(Unknown Source)

My code pings the NSC in two places - there is one thread which implements 
run() method like this:

final public void run() {
        final Thread currentThread = Thread.currentThread();

        try {
            m_server = new NetworkServerControl(m_host, m_port);
            m_server.start(new PrintWriter(new LoggingOutputStream(logger, 
Level.INFO), true));

            try {
                while (m_thread == currentThread) {
                    try {
                        Thread.sleep(m_sleep);

                        if (logger.isTraceEnabled()) {
                            logger.trace("Pinging NetworkServerControl on 
[" + m_host + ":" + m_port + "]");
                        }

--->                        m_server.ping();   <--- Exception Thrown
                    } catch (InterruptedException e) {
                        logger.info(toString() + " sleep has been 
interrupted");
                    }
                }
            } catch (Exception e) {
                logger.error("Error while pinging NetworkServerControl:", 
e);
            }

            logger.info("Stopping NetworkServerControl on [" + m_host + 
":" + m_port + "]");
            m_server.shutdown();
        } catch (Exception e) {
            logger.error("Error while starting/stopping 
NetworkServerControl:", e);
        }
    }

And another "validating" thread calls this method at regular intervals:

    final public String isRuntimeValid() {
        final StringBuilder builder = new StringBuilder();
        builder.append(super.isRuntimeValid());

        if (m_server == null) builder.append("\n\t").append("Server is 
null");
        if (m_thread == null) builder.append("\n\t").append("Thread is 
null");

        try {
            m_server.ping();
        } catch (Exception e) {
            builder.append("\n\t").append("Server cannot be pinged");
        }

        return builder.toString();
    }

Can there be any problem if those two are called at around the same time? 
This is probably the only scenario which could, I imagine, cause a 
problem...
Would anyone have any other thoughts or suspicions?

Much appreciated,

Pavel.




Jefferies archives and monitors outgoing and incoming e-mail. The contents of this email, including any attachments, are confidential to the ordinary user of the email address to which it was addressed. If you are not the addressee of this email you may not copy, forward, disclose or otherwise use it or any part of it in any form whatsoever. This email may be produced at the request of regulators or in connection with civil litigation. Jefferies accepts no liability for any errors or omissions arising as a result of transmission. Use by other than intended recipients is prohibited.  In the United Kingdom, Jefferies operates as Jefferies International Limited; registered in England: no. 1978621; registered office: Vintners Place, 68 Upper Thames Street, London EC4V 3BJ.  Jefferies International Limited is authorised and regulated by the Financial Services Authority.

Re: Shutting down a database that is already shut down

Posted by David Van Couvering <da...@vancouvering.com>.
OK, thanks.  I'll work to ensure that I only shut down a database that is
currently up, just to keep my life simple and the log empty of kruft.

David

On Mon, Aug 2, 2010 at 12:51 AM, Kristian Waagan <kristian.waagan@oracle.com
> wrote:

> On Fri, Jul 30, 2010 at 02:30:34PM -0700, David Van Couvering wrote:
> > Do I have to worry about ensuring that a database is running before I try
> to
> > shut it down, or is it OK to get a connection with URL ";shutdown=true"
> on a
> > database that's not booted.
> >
> > If I were to do that, does it boot the database and then shut it down
> again, or
> > does it do nothing?
>
> Hi David,
>
> Derby won't boot the database, but you will get a database not found
> exception. The exception may also be written to derby.log, which casues
> the file to grow a lot faster if you issue a lot of shutdown requests
> for non-booted databases.
>
> You get the exception because the getConnection call must either
> return a valid connection or throw an exception. Since we haven't shut
> down the database (it wasn't booted), we cannot throw an exception
> saying we did so. Getting database not found seems a bit odd too, but
> maybe Derby currently has to boot a database to confirm that it exists?
>
>
> Regards,
> --
> Kristian
>
> >
> > Thanks,
> >
> > David
> >
> > --
> > David W. Van Couvering
> >
> > http://www.linkedin.com/in/davidvc
> > http://davidvancouvering.blogspot.com
> > http://twitter.com/dcouvering
>



-- 
David W. Van Couvering

http://www.linkedin.com/in/davidvc
http://davidvancouvering.blogspot.com
http://twitter.com/dcouvering