eplicationConfig repConfig = new ReplicationConfig(); repConfig.setGroupName("PlanetaryRepGroup"); repConfig.setNodeName("Mercury"); repConfig.setNodeHostPort("mercury.acme.com:5001"); // This is the first node, so its helper is itself repConfig.setHelperHosts("mercury.acme.com:5001"); ReplicatedEnvironment repEnv = new ReplicatedEnvironment(envHome, repConfig, envConfig);
To create a new node when there are other existing group members, set a helper address which points to an existing node in the group. A simple way to bring up a new group is to "chain" the new nodes by having the helpers reference a previously created node.
EnvironmentConfig envConfig = new EnvironmentConfig(); envConfig.setAllowCreate(true); envConfig.setTransactional(true); // Identify the node ReplicationConfig repConfig = new ReplicationConfig("PlanetaryRepGroup", "Jupiter", "jupiter.acme.com:5002"); // Use the node at mercury.acme.com:5001 as a helper to find the rest // of the group. repConfig.setHelperHosts("mercury.acme.com:5001"); ReplicatedEnvironment repEnv = new ReplicatedEnvironment(envHome, repConfig, envConfig);
In these examples, node Mercury was configured as its own helper, and becomes the first master. The next nodes were configured to use Mercury as their helper, and became replicas. It is also possible to start these in reverse order, bringing mercury up last. In that case, the earlier nodes will block until a helper is awake and can service their requests for group metadata.
Creating a ReplicatedEnvironment for an existing environment requires less configuration. The call to {@code EnvironmentConfig.setAllowCreate()} is eliminated to guardagainst the unintentional creation of a new environment. Also, there is no need to set a helper host address, because the environment exists and has access to the shared, persistent membership information.
EnvironmentConfig envConfig = new EnvironmentConfig(); envConfig.setTransactional(true); ReplicationConfig repConfig = new ReplicationConfig("PlanetaryRepGroup", "Mercury", "mercury.acme.com:5001"); ReplicatedEnvironment repEnv = new ReplicatedEnvironment(envHome, repConfig, envConfig);
{@literal See} {@link com.sleepycat.je.rep.util.ReplicationGroupAdmin ReplicationGroupAdmin} for information on how to remove nodes from thereplication group.
ReplicatedEnvironment properties can be set via the the {@literal /}je.properties file, just like {@link Environment}properties. They follow the same property value precedence rules. A replicated environment directory can only be accessed by a read write ReplicatedEnvironment handle or a read only {@link Environment} handle. Inthe current release, there is an additional restriction that a read only {@link Environment} is only permitted when the directory is not alsoaccessed from a different process by a read/write ReplicatedEnvironment. If a read/write ReplicatedEnvironment and a read only {@link Environment} fromtwo different processes concurrently access an environment directory, there is the small possibility that the read only {@link Environment} may seesee exceptions thrown about an inconsistent log if the ReplicatedEnvironment executes certain kinds of failover. There is no problem if the {@link Environment} and ReplicatedEnvironment are in the same process, or are notconcurrent.
JE HA prohibits opening a replicated environment directory with a read/write {@link Environment} handle, because from the group's perspective,unreplicated updates to a single node would cause data inconsistency. To use an existing, non-replicated environment to bootstrap a replication group, use {@link com.sleepycat.je.rep.util.DbEnableReplication} to do a onetime conversion of the directory.
All other database objects, such as {@link com.sleepycat.je.Database} or{@link com.sleepycat.je.Cursor} (when using the Base API) or {@link com.sleepycat.persist.EntityStore} or {@link com.sleepycat.persist.PrimaryIndex} (when using the Direct PersistenceLayer) should be created, used and closed before calling {@link ReplicatedEnvironment#close}.
@see Environment
@see Replication First Steps
@since 4.0