If you are creating a replication group where there will be higher latency network connections between some nodes and the rest of the replication group, typically because the nodes are located in distant geographical regions, then it may be useful to create those distant nodes nodes as Secondary nodes. Secondary nodes are nodes that only serve as read-only Replicas. They cannot become Masters, participate in elections, or provide acknowledgements for commit operations. Secondary nodes can be used to provide a distant location with quick access to read-only data, although the data may be somewhat out of date due to replication delays over the high latency link. By using Secondary nodes for the nodes at a distance, the Electable nodes will be able to perform elections and provide acknowledgments without experiencing network delays associated with higher latency connections to the Secondary nodes.
Here is an example of how to create a Secondary node that can join an existing group of Electable nodes:
EnvironmentConfig envConfig = new EnvironmentConfig(); envConfig.setAllowCreate(true); envConfig.setTransactional(true); // Identify the secondary node ReplicationConfig electableRepConfig = new ReplicationConfig("PlanetaryRepGroup", "Mars", "mars.example.com:500"); // Configure the node to be a secondary node repConfig.setNodeType(NodeType.SECONDARY); // Specify one of the electable nodes as a helper repConfig.setHelperHosts("jupiter.example.com:5002"); ReplicatedEnvironment repEnv = new ReplicatedEnvironment(envHome, repConfig, envConfig);
Note that, if you have created an environment with NodeType.SECONDARY, it is possible to convert the node from a Secondary node to an Electable node by restarting the environment with NodeType.ELECTABLE. Once an environment has been used as an Electable node, though, it is not possible to convert to be a Secondary node.