|
UsageReplicationForJava
How to use the replication plugin for BabuDB for Java.
Featured BabuDB replicationIntroductionThis guide refers to the replication plugin that will become available with the next major release (TBA 0.5.0). Since the replication mechanism has been separated from the core BabuDB functionalities also its usability has been enhanced. For your application it now does not matter anymore if it uses a single instance of BabuDB or a system of multiple instances that are replicated among each other in background. It will always be accessed through the same well documented interface that can be found within the package org.xtreemfs.babudb.api. The replication itself has no user-application accessible interface at all. FeaturesUsing the replication plugin for BabuDB will provide the following features:
Preconditions necessary to use replication
QuickstartThis guide describes how to setup an example with two BabuDB instances running at the same host. The more common way to setup replicated BabuDB instances will involve multiple hosts, but in case of a quickstart-scenario this will do. A sample application based on this quickstart can be found here. Preparations
ConfigurationFirst of all we need to configure the replication plugin by creating one configuration file for each BabuDB instance taking part in our setup. For the two instance of our example these will be pluginConfig0.properties with the following content: plugin.jar = myPluginPath/Replication-1.0.0_0.5.0.jar # paths to libraries this plugin depends on babudb.repl.dependency.0 = myPluginPath/lib/PBRPC.jar babudb.repl.dependency.1 = myPluginPath/lib/Flease.jar babudb.repl.dependency.2 = myPluginPath/extLib/protobuf-java-2.3.0.jar # DB backup directory - needed for the initial loading of the BabuDB from the # master in replication context babudb.repl.backupDir = /tmp/backup0 # number of servers that at least have to be up to date babudb.repl.sync.n = 2 # it is possible to set the local address and port of this server explicitly. if not it will be # chosen from the list of participants added right hereafter (default). babudb.repl.localhost = localhost babudb.repl.localport = 35666 # participants of the replication including the local address babudb.repl.participant.0 = localhost babudb.repl.participant.0.port = 35666 babudb.repl.participant.1 = localhost babudb.repl.participant.1.port = 35667 and pluginConfig1.properties with similar content: plugin.jar = myPluginPath/Replication-1.0.0_0.5.0.jar # paths to libraries this plugin depends on babudb.repl.dependency.0 = myPluginPath/lib/PBRPC.jar babudb.repl.dependency.1 = myPluginPath/lib/Flease.jar babudb.repl.dependency.2 = myPluginPath/extLib/protobuf-java-2.3.0.jar # DB backup directory - needed for the initial loading of the BabuDB from the # master in replication context babudb.repl.backupDir = /tmp/backup1 # number of servers that at least have to be up to date babudb.repl.sync.n = 2 # it is possible to set the local address and port of this server explicitly. if not it will be # chosen from the list of participants added right hereafter (default). babudb.repl.localhost = localhost babudb.repl.localport = 35667 # participants of the replication including the local address babudb.repl.participant.0 = localhost babudb.repl.participant.0.port = 35666 babudb.repl.participant.1 = localhost babudb.repl.participant.1.port = 35667 Both files have to be saved to myBabuDBPath. StartupNow we need to extend the configuration of the single BabuDB instances with the reference to the plugin's configuration and fire them up. This will be part of the initialization of our application program: ConfigBuilder builder0 = new ConfigBuilder();
builder0.setDataPath("/tmp/babudb0", "/tmp/babudb0/log").setLogAppendSyncMode(SyncMode.SYNC_WRITE);
builder0.addPlugin("myBabuDBPath/pluginConfig0.properties");
BabuDBConfig config0 = builder0.build();
ConfigBuilder builder1 = new ConfigBuilder();
builder1.setDataPath("/tmp/babudb1", "/tmp/babudb1/log").setLogAppendSyncMode(SyncMode.SYNC_WRITE);
builder1.addPlugin("myBabuDBPath/pluginConfig1.properties");
BabuDBConfig config1 = builder1.build();
BabuDB babuDB0 = BabuDBFactory.createBabuDB(config0);
BabuDB babuDB1 = BabuDBFactory.createBabuDB(config1);The data stored at any of both instance will be replicated to the other one, while you may treat both of them as if they were single instances, like described at UsageExampleJava. Technical detailsThe following details should not bother you, if you only want to use the replication plugin but they will if you want to optimize your setup or develop depending plugins. The replication mechanism underlies a master-slave related replication model. Databases are replicated by the granularity of single operations. Any operation performed by the user will cause a log entry to be written to the pending on-disk log file. These log entries are serialized and send to the slaves via Google's protocol buffer RPC architecture. Mutual exclusion for the master is garanted by Flease a quorum-based algorithm, that was developed within the XtreemFS research. The user specifies behavior of the replication by deciding how many of the total amount n of hosts participating at replication setup have at least to be up-to-date. Invariants
For even more technical details visit BabuDBReplicationForJava. |