Starting and running replication
Derby Server and Administration Guide
79
using a network connection. The slave then writes these log records to its local log and
redoes them.
If the master fails, the slave completes the recovery by redoing the log that has not
already been processed. The state of the slave after this recovery is close to the state
the master had when it crashed. However, some of the last transactions performed on
the master may not have been sent to the slave and may therefore not be reflected.
When the slave has completed the recovery work, it is transformed into a normal Derby
instance that is ready to process transactions. For more details, see
.
Several Derby properties allow you to specify the size of the replication log buffers
and the intervals between log shipments, as well as whether replication messages are
logged. See the Derby Reference Manual for details.
You can perform replication on a database that runs in either embedded mode or
Network Server mode.
Starting and running replication
Each replicated database is replicated from a master to a slave version of that database.
Initially there is no replication; a master database must be created before it can be
replicated. The database may, of course, be empty when replication starts. On the other
hand, replication does not need to be specified immediately after the database is created;
it can be initiated at any time after the database is created.
Before you start replication, you must shut down the master database and then copy the
database to the slave location. Follow these steps to start replication:
1. Make sure that the database on the master system is shut down cleanly.
2. Copy the database to the slave location.
3. Start slave replication mode on the Derby instance that is acting as the slave for
the database. To start slave replication, use the startSlave=true attribute and,
optionally, the slaveHost=hostname and slavePort=portValue attributes. For
example, for a database named
wombat
, you might use the following connection
URL:
jdbc:derby:wombat;startSlave=true
4. Start master replication mode on the Derby instance that is acting as the master for
the database. To start replication, connect to the database on the master system
using the startMaster=true attribute in conjunction with the slaveHost=hostname
attribute (and, optionally, the slavePort=portValue attribute). For example, you might
use the following connection URL:
jdbc:derby:wombat;startMaster=true;slaveHost=myremotesystem
A successful use of the startMaster=true attribute will also start the database.
See the Derby Reference Manual for details about these attributes.
After replication has been started, the slave is ready to receive logged operations from
the master. The master can now continue to process transactions. From this point on, the
master forwards all logged operations to the slave in chunks. The slave repeats these
operations by applying the contents of the Derby transaction log, but does not process
any other operations. Attempts to connect to the slave database are refused. In case of
failure, the slave can recover to the state the master was in at the time the last chunk of
the transaction log was sent.