Oskar Zinger <oska...@yahoo.com> writes:

> I'm using Derby Replication in my product and trying to figure out
> what is the best approach for "stopping" the database before starting
> replication (before copying the database from Master to Slave).
>
> I'm currently using "shutdown" approach... as described in the
> following Derby 10.8 documentation (it says to make sure the database
> is shutdown cleanly):
> http://db.apache.org/derby/docs/10.8/adminguide/cadminreplicstartrun.html
>
> If you look at the Derby replication write-up - it tells you to
> "freeze the DB" using command "call SYSCS_UTIL.SYSCS_FREEZE_DATABASE
> (), here is the write-up I'm referring to:
> http://wiki.apache.org/db-derby/ReplicationWriteup
>
> These two seem to be conflicting... and therefore the question: what
> is the best practice to "stopping the db" before the start of
> replication?

The current recommendation is to use shutdown, as freezing the database
does not work correctly if there are uncommitted transactions at the
time the database is frozen, and that might lead to strange errors or
even silent corruption of the slave
(https://issues.apache.org/jira/browse/DERBY-3896).

I've added a note to the wiki page saying that the manuals should be
used for up to date information.

> Also, when you think about it, when you shutdown the DB before copying
> the database and starting replication, what if there is a thread
> running in JVM that will reboot the database before you get a chance
> to copy the database, and when you finally start replication - then
> the databases will be again out of sync. This did not actually happen
> to me in practice, but I think theoretically it is possible.

Yes, that's possible. Initializing Derby replication could surely need
some work to make it simpler and more user-friendly. In its current
state, unfortunately, it's up to the application logic to make sure the
initialization process is not disturbed by other threads.

There are some ideas for improvements in the issue tracker, but they
haven't had much traction so far. For example:

https://issues.apache.org/jira/browse/DERBY-4197 - Simplify initialization of 
replication
https://issues.apache.org/jira/browse/DERBY-4447 - Add internal block mechanism 
to reject new database connections

-- 
Knut Anders

Reply via email to