Re: Shutting down a database that is already shut down

2010-08-02 Thread Kristian Waagan
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


backing up the DB

2010-08-02 Thread vadali

Hello,

I have a few tables (with FK), that i need to save and restore. 
My original plan was to save the entire directory of the database on one
machine, then reload it on another machine.

The problem is that i might want to only save a portion of that db (say only
lines in tables that are newer then a certain date - i do keep the date for
each line).

whats my best method? 

I thought about manually coping all the interesting lines from one db to
another one (lets name it backupdb), but that could be slow.. 
another option i thought, would be to copy the entire db to backupdb, then
removing all the lines i dont need, but when i tried that, the size of the
backupdb directory was even larger then the original...

Do you have any better options?

best regards,
vadali
-- 
View this message in context: 
http://old.nabble.com/backing-up-the-DB-tp29324036p29324036.html
Sent from the Apache Derby Users mailing list archive at Nabble.com.



Re: backing up the DB

2010-08-02 Thread Kristian Waagan
On Mon, Aug 02, 2010 at 04:00:41AM -0700, vadali wrote:
> 
> Hello,
> 
> I have a few tables (with FK), that i need to save and restore. 
> My original plan was to save the entire directory of the database on one
> machine, then reload it on another machine.
> 
> The problem is that i might want to only save a portion of that db (say only
> lines in tables that are newer then a certain date - i do keep the date for
> each line).
> 

Hi Vadali,

What are your requirements for uptime on the primary db?
Do you have to use online backup, or can you block update transactions
for a while?

> whats my best method? 
> 
> I thought about manually coping all the interesting lines from one db to
> another one (lets name it backupdb), but that could be slow.. 
> another option i thought, would be to copy the entire db to backupdb, then
> removing all the lines i dont need, but when i tried that, the size of the
> backupdb directory was even larger then the original...

This is probably because Derby isn't releasing unused space to the OS
before it is told to do so. You should run the compress routines on the
tables from which you deleted a large number of rows.
The extra space may be log records, which will be deleted after a checkpoint / 
clean shutdown.

> 
> Do you have any better options?

Seems to me you have to decide if you want to filter the data up front
or after you have created the backup.
In the former case you could write your own "database copy" using SQL to
filter the data (or maybe write a VTI), in the latter case you would
have to account for the time spent deleting unwanted data and then
compressing the tables to save space.

It might also help people to come up with better answers if you tell us
roughly how large you expect your database to be.


Regards,
-- 
Kristian

> 
> best regards,
> vadali
> -- 
> View this message in context: 
> http://old.nabble.com/backing-up-the-DB-tp29324036p29324036.html
> Sent from the Apache Derby Users mailing list archive at Nabble.com.
> 


Re: backing up the DB

2010-08-02 Thread vadali

Hi Kristian, Thank you for your reply

The db can be off when i back it up. I am unfamiliar with any compress
routines.. any pointers would be helpful. 

I dont really mind how the filtering is done (up front or on the backup
copy), i just dont want it to be too long. 

my main goal is to burn the directory onto a cd or dvd, but since it can
easily exceed the size of a single media, i tar it, slice it to multiple
files of fixed sizes, and burn each on a different media (quite a lengthly
process..), where later i could reattach the files, untar it, load up a db
onto this folder, and query all i want :)

I am not so sure what a VTI is, or how to write such a script that will do a
sort of a database copy..

sorry for my noobity, i am not mainly a db programmer.. 

the db can reach a few gb's of space over a certain duration of time, but
usually the user will want to burn much less (say only the data from the
previous day..). 

i hope i gave all the information you ment,
thank you for your help,
Vadali


-- 
View this message in context: 
http://old.nabble.com/backing-up-the-DB-tp29324036p29325754.html
Sent from the Apache Derby Users mailing list archive at Nabble.com.



Re: Shutting down a database that is already shut down

2010-08-02 Thread David Van Couvering
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  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


Socket Closed Exception when pinging NetworkServerControl

2010-08-02 Thread Pavel Bortnovskiy
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 imag