use of voldemort.cluster.Zone in project voldemort by voldemort.
the class ClusterMapperTest method testClusterEquals.
public void testClusterEquals() {
List<Zone> zones2 = ServerTestUtils.getZones(2);
List<Zone> zones3 = ServerTestUtils.getZones(3);
Cluster cluster1 = ServerTestUtils.getLocalCluster(4, 10, 2);
Cluster cluster2 = new Cluster("cluster2", Lists.newArrayList(cluster1.getNodes()), zones3);
// Test different number of zones
assertFalse(cluster1.equals(cluster2));
// Test proximity size not same
List<Zone> modifiedZones2 = Lists.newArrayList();
modifiedZones2.add(zones2.get(0));
LinkedList<Integer> newProximityList = Lists.newLinkedList(zones2.get(1).getProximityList());
newProximityList.add(100);
modifiedZones2.add(new Zone(zones2.get(1).getId(), newProximityList));
cluster1 = new Cluster("cluster1", new ArrayList<Node>(), zones2);
cluster2 = new Cluster("cluster2", new ArrayList<Node>(), modifiedZones2);
assertFalse(cluster1.equals(cluster2));
// Test proximity list different order
List<Zone> modifiedZones3 = Lists.newArrayList();
for (int zoneId = 0; zoneId < 3; zoneId++) {
LinkedList<Integer> proximityList = Lists.newLinkedList(zones3.get(zoneId).getProximityList());
Collections.reverse(proximityList);
modifiedZones3.add(new Zone(zones3.get(zoneId).getId(), proximityList));
}
cluster1 = new Cluster("cluster1", new ArrayList<Node>(), zones3);
cluster2 = new Cluster("cluster2", new ArrayList<Node>(), modifiedZones3);
assertFalse(cluster1.equals(cluster2));
// Test nodes in different zones
cluster1 = ServerTestUtils.getLocalCluster(4, 10, 2);
List<Node> newNodes = Lists.newArrayList();
for (Node node : cluster1.getNodes()) {
newNodes.add(new Node(node.getId(), node.getHost(), node.getHttpPort(), node.getSocketPort(), node.getAdminPort(), 0, node.getPartitionIds()));
}
cluster2 = new Cluster("cluster2", newNodes, Lists.newArrayList(cluster1.getZones()));
assertFalse(cluster1.equals(cluster2));
// Test equality
cluster2 = new Cluster("cluster2", Lists.newArrayList(cluster1.getNodes()), Lists.newArrayList(cluster1.getZones()));
assertTrue(cluster1.equals(cluster2));
}
use of voldemort.cluster.Zone in project voldemort by voldemort.
the class AdminServiceBasicTest method testReplicationMappingWithZonePreference.
@Test
public void testReplicationMappingWithZonePreference() {
List<Zone> zones = ServerTestUtils.getZones(2);
List<Node> nodes = Lists.newArrayList();
nodes.add(new Node(0, "localhost", 1, 2, 3, 0, Lists.newArrayList(0, 4, 8)));
nodes.add(new Node(1, "localhost", 1, 2, 3, 0, Lists.newArrayList(1, 5, 9)));
nodes.add(new Node(2, "localhost", 1, 2, 3, 1, Lists.newArrayList(2, 6, 10)));
nodes.add(new Node(3, "localhost", 1, 2, 3, 1, Lists.newArrayList(3, 7, 11)));
// Test 0 - With rep-factor 1; zone 1
StoreDefinition storeDef = ServerTestUtils.getStoreDef("consistent", 1, 1, 1, 1, 1, RoutingStrategyType.CONSISTENT_STRATEGY);
Cluster newCluster = new Cluster("single_zone_cluster", nodes, zones);
try {
adminClient.replicaOps.getReplicationMapping(0, newCluster, storeDef, 1);
fail("Should have thrown an exception since rep-factor = 1");
} catch (VoldemortException e) {
}
// With rep-factor 1; zone 0
storeDef = ServerTestUtils.getStoreDef("consistent", 1, 1, 1, 1, 1, RoutingStrategyType.CONSISTENT_STRATEGY);
newCluster = new Cluster("single_zone_cluster", nodes, zones);
try {
adminClient.replicaOps.getReplicationMapping(0, newCluster, storeDef, 0);
fail("Should have thrown an exception since rep-factor = 1");
} catch (VoldemortException e) {
}
// Test 1 - With consistent routing strategy
storeDef = ServerTestUtils.getStoreDef("consistent", 4, 1, 1, 1, 1, RoutingStrategyType.CONSISTENT_STRATEGY);
// On node 0; zone id 1
Map<Integer, List<Integer>> replicationMapping = adminClient.replicaOps.getReplicationMapping(0, newCluster, storeDef, 1);
{
HashMap<Integer, List<Integer>> expectedMapping = Maps.newHashMap();
expectedMapping.put(2, Lists.newArrayList(0, 4, 8, 1, 5, 9, 2, 6, 10));
expectedMapping.put(3, Lists.newArrayList(3, 7, 11));
assertEquals(expectedMapping, replicationMapping);
}
// On node 0; zone id 0
replicationMapping = adminClient.replicaOps.getReplicationMapping(0, newCluster, storeDef, 0);
{
HashMap<Integer, List<Integer>> expectedMapping = Maps.newHashMap();
// partitionTuple.put(1, Lists.newArrayList(0, 4, 8));
// partitionTuple.put(2, Lists.newArrayList(3, 7, 11));
// partitionTuple.put(3, Lists.newArrayList(2, 6, 10));
expectedMapping.put(1, Lists.newArrayList(0, 4, 8, 1, 5, 9, 2, 6, 10, 3, 7, 11));
assertEquals(expectedMapping, replicationMapping);
}
// Test 2 - With zone routing strategy, and zone replication factor 1
HashMap<Integer, Integer> zoneReplicationFactors = Maps.newHashMap();
for (int zoneIds = 0; zoneIds < 2; zoneIds++) {
zoneReplicationFactors.put(zoneIds, 1);
}
storeDef = ServerTestUtils.getStoreDef("zone", 2, 1, 1, 1, 0, 0, zoneReplicationFactors, HintedHandoffStrategyType.PROXIMITY_STRATEGY, RoutingStrategyType.ZONE_STRATEGY);
newCluster = new Cluster("multi_zone_cluster", nodes, zones);
{
try {
replicationMapping = adminClient.replicaOps.getReplicationMapping(0, newCluster, storeDef, 0);
fail("Should have thrown an exception since zoneReplicationFactor is 1");
} catch (VoldemortException e) {
}
}
{
// On node 0, zone 1
replicationMapping = adminClient.replicaOps.getReplicationMapping(0, newCluster, storeDef, 1);
HashMap<Integer, List<Integer>> expectedMapping = Maps.newHashMap();
expectedMapping.put(2, Lists.newArrayList(0, 4, 8, 2, 6, 10));
expectedMapping.put(3, Lists.newArrayList(3, 7, 11));
assertEquals(expectedMapping, replicationMapping);
}
{
// On node 1, zone 1
replicationMapping = adminClient.replicaOps.getReplicationMapping(1, newCluster, storeDef, 1);
HashMap<Integer, List<Integer>> expectedMapping = Maps.newHashMap();
expectedMapping.put(2, Lists.newArrayList(1, 5, 9));
assertEquals(expectedMapping, replicationMapping);
}
}
use of voldemort.cluster.Zone in project voldemort by voldemort.
the class AdminServiceBasicTest method testReplicationMapping.
@Test
public void testReplicationMapping() {
List<Zone> zones = ServerTestUtils.getZones(2);
List<Node> nodes = Lists.newArrayList();
nodes.add(new Node(0, "localhost", 1, 2, 3, 0, Lists.newArrayList(0, 4, 8)));
nodes.add(new Node(1, "localhost", 1, 2, 3, 0, Lists.newArrayList(1, 5, 9)));
nodes.add(new Node(2, "localhost", 1, 2, 3, 1, Lists.newArrayList(2, 6, 10)));
nodes.add(new Node(3, "localhost", 1, 2, 3, 1, Lists.newArrayList(3, 7, 11)));
// Test 0 - With rep-factor 1
StoreDefinition storeDef = ServerTestUtils.getStoreDef("consistent", 1, 1, 1, 1, 1, RoutingStrategyType.CONSISTENT_STRATEGY);
Cluster newCluster = new Cluster("single_zone_cluster", nodes, zones);
try {
adminClient.replicaOps.getReplicationMapping(0, newCluster, storeDef);
fail("Should have thrown an exception since rep-factor = 1");
} catch (VoldemortException e) {
}
// Test 1 - With consistent routing strategy
storeDef = ServerTestUtils.getStoreDef("consistent", 2, 1, 1, 1, 1, RoutingStrategyType.CONSISTENT_STRATEGY);
// On node 0
Map<Integer, List<Integer>> replicationMapping = adminClient.replicaOps.getReplicationMapping(0, newCluster, storeDef);
{
HashMap<Integer, List<Integer>> expectedMapping = Maps.newHashMap();
expectedMapping.put(1, Lists.newArrayList(0, 4, 8));
expectedMapping.put(3, Lists.newArrayList(3, 7, 11));
assertEquals(expectedMapping, replicationMapping);
}
{
// On node 1
replicationMapping = adminClient.replicaOps.getReplicationMapping(1, newCluster, storeDef);
HashMap<Integer, List<Integer>> expectedMapping = Maps.newHashMap();
expectedMapping.put(0, Lists.newArrayList(0, 4, 8));
expectedMapping.put(2, Lists.newArrayList(1, 5, 9));
assertEquals(expectedMapping, replicationMapping);
}
{
// On node 2
replicationMapping = adminClient.replicaOps.getReplicationMapping(2, newCluster, storeDef);
HashMap<Integer, List<Integer>> expectedMapping = Maps.newHashMap();
expectedMapping.put(1, Lists.newArrayList(1, 5, 9));
expectedMapping.put(3, Lists.newArrayList(2, 6, 10));
assertEquals(expectedMapping, replicationMapping);
}
{
// On node 3
replicationMapping = adminClient.replicaOps.getReplicationMapping(3, newCluster, storeDef);
HashMap<Integer, List<Integer>> expectedMapping = Maps.newHashMap();
expectedMapping.put(0, Lists.newArrayList(3, 7, 11));
expectedMapping.put(2, Lists.newArrayList(2, 6, 10));
assertEquals(expectedMapping, replicationMapping);
}
// Test 2 - With zone routing strategy
HashMap<Integer, Integer> zoneReplicationFactors = Maps.newHashMap();
for (int zoneIds = 0; zoneIds < 2; zoneIds++) {
zoneReplicationFactors.put(zoneIds, 1);
}
storeDef = ServerTestUtils.getStoreDef("zone", 2, 1, 1, 1, 0, 0, zoneReplicationFactors, HintedHandoffStrategyType.PROXIMITY_STRATEGY, RoutingStrategyType.ZONE_STRATEGY);
newCluster = new Cluster("multi_zone_cluster", nodes, zones);
{
// On node 0
replicationMapping = adminClient.replicaOps.getReplicationMapping(0, newCluster, storeDef);
HashMap<Integer, List<Integer>> expectedMapping = Maps.newHashMap();
expectedMapping.put(2, Lists.newArrayList(0, 4, 8, 2, 6, 10));
expectedMapping.put(3, Lists.newArrayList(3, 7, 11));
assertEquals(expectedMapping, replicationMapping);
}
{
// On node 1
replicationMapping = adminClient.replicaOps.getReplicationMapping(1, newCluster, storeDef);
HashMap<Integer, List<Integer>> expectedMapping = Maps.newHashMap();
expectedMapping.put(2, Lists.newArrayList(1, 5, 9));
assertEquals(expectedMapping, replicationMapping);
}
{
// On node 2
replicationMapping = adminClient.replicaOps.getReplicationMapping(2, newCluster, storeDef);
HashMap<Integer, List<Integer>> expectedMapping = Maps.newHashMap();
expectedMapping.put(0, Lists.newArrayList(0, 4, 8, 2, 6, 10));
expectedMapping.put(1, Lists.newArrayList(1, 5, 9));
assertEquals(expectedMapping, replicationMapping);
}
{
// On node 3
replicationMapping = adminClient.replicaOps.getReplicationMapping(3, newCluster, storeDef);
HashMap<Integer, List<Integer>> expectedMapping = Maps.newHashMap();
expectedMapping.put(0, Lists.newArrayList(3, 7, 11));
assertEquals(expectedMapping, replicationMapping);
}
// Test 3 - Consistent with rep factor 3
storeDef = ServerTestUtils.getStoreDef("consistent", 3, 1, 1, 1, 1, RoutingStrategyType.CONSISTENT_STRATEGY);
newCluster = new Cluster("single_zone_cluster", nodes, zones);
{
replicationMapping = adminClient.replicaOps.getReplicationMapping(0, newCluster, storeDef);
HashMap<Integer, List<Integer>> expectedMapping = Maps.newHashMap();
expectedMapping.put(1, Lists.newArrayList(0, 4, 8));
expectedMapping.put(3, Lists.newArrayList(3, 7, 11));
expectedMapping.put(2, Lists.newArrayList(2, 6, 10));
assertEquals(expectedMapping, replicationMapping);
}
{
replicationMapping = adminClient.replicaOps.getReplicationMapping(1, newCluster, storeDef);
HashMap<Integer, List<Integer>> expectedMapping = Maps.newHashMap();
expectedMapping.put(0, Lists.newArrayList(0, 4, 8));
expectedMapping.put(3, Lists.newArrayList(3, 7, 11));
expectedMapping.put(2, Lists.newArrayList(1, 5, 9));
assertEquals(expectedMapping, replicationMapping);
}
{
replicationMapping = adminClient.replicaOps.getReplicationMapping(2, newCluster, storeDef);
HashMap<Integer, List<Integer>> expectedMapping = Maps.newHashMap();
expectedMapping.put(0, Lists.newArrayList(0, 4, 8));
expectedMapping.put(1, Lists.newArrayList(1, 5, 9));
expectedMapping.put(3, Lists.newArrayList(2, 6, 10));
assertEquals(expectedMapping, replicationMapping);
}
{
replicationMapping = adminClient.replicaOps.getReplicationMapping(3, newCluster, storeDef);
HashMap<Integer, List<Integer>> expectedMapping = Maps.newHashMap();
expectedMapping.put(0, Lists.newArrayList(3, 7, 11));
expectedMapping.put(1, Lists.newArrayList(1, 5, 9));
expectedMapping.put(2, Lists.newArrayList(2, 6, 10));
assertEquals(expectedMapping, replicationMapping);
}
zoneReplicationFactors = Maps.newHashMap();
for (int zoneIds = 0; zoneIds < 2; zoneIds++) {
zoneReplicationFactors.put(zoneIds, 2);
}
storeDef = ServerTestUtils.getStoreDef("zone", 1, 1, 1, 1, 0, 0, zoneReplicationFactors, HintedHandoffStrategyType.PROXIMITY_STRATEGY, RoutingStrategyType.ZONE_STRATEGY);
newCluster = new Cluster("multi_zone_cluster", nodes, zones);
{
replicationMapping = adminClient.replicaOps.getReplicationMapping(0, newCluster, storeDef);
HashMap<Integer, List<Integer>> expectedMapping = Maps.newHashMap();
expectedMapping.put(1, Lists.newArrayList(0, 4, 8, 1, 5, 9));
expectedMapping.put(2, Lists.newArrayList(2, 6, 10));
expectedMapping.put(3, Lists.newArrayList(3, 7, 11));
assertEquals(expectedMapping, replicationMapping);
}
{
replicationMapping = adminClient.replicaOps.getReplicationMapping(1, newCluster, storeDef);
HashMap<Integer, List<Integer>> expectedMapping = Maps.newHashMap();
expectedMapping.put(0, Lists.newArrayList(0, 4, 8));
expectedMapping.put(2, Lists.newArrayList(1, 5, 9, 2, 6, 10));
expectedMapping.put(3, Lists.newArrayList(3, 7, 11));
assertEquals(expectedMapping, replicationMapping);
}
{
replicationMapping = adminClient.replicaOps.getReplicationMapping(2, newCluster, storeDef);
HashMap<Integer, List<Integer>> expectedMapping = Maps.newHashMap();
expectedMapping.put(0, Lists.newArrayList(0, 4, 8));
expectedMapping.put(1, Lists.newArrayList(1, 5, 9));
expectedMapping.put(3, Lists.newArrayList(2, 6, 10, 3, 7, 11));
assertEquals(expectedMapping, replicationMapping);
}
{
replicationMapping = adminClient.replicaOps.getReplicationMapping(3, newCluster, storeDef);
HashMap<Integer, List<Integer>> expectedMapping = Maps.newHashMap();
expectedMapping.put(0, Lists.newArrayList(0, 4, 8, 3, 7, 11));
expectedMapping.put(1, Lists.newArrayList(1, 5, 9));
expectedMapping.put(2, Lists.newArrayList(2, 6, 10));
assertEquals(expectedMapping, replicationMapping);
}
}
use of voldemort.cluster.Zone in project voldemort by voldemort.
the class ServerTestUtils method getZonesFromZoneIds.
/**
* Returns a list of zones with their proximity list being in increasing
* order
*
* @param numberOfZones The number of zones to return
* @return List of zones
*/
public static List<Zone> getZonesFromZoneIds(int[] zoneIds) {
List<Zone> zones = Lists.newArrayList();
Set<Integer> zoneIdsSet = new HashSet<Integer>();
for (int i : zoneIds) {
zoneIdsSet.add(i);
}
Set<Integer> removeSet = new HashSet<Integer>();
for (int i = 0; i < zoneIds.length; i++) {
removeSet.add(zoneIds[i]);
zones.add(new Zone(zoneIds[i], Lists.newLinkedList(Sets.symmetricDifference(zoneIdsSet, removeSet))));
removeSet.clear();
}
return zones;
}
use of voldemort.cluster.Zone in project voldemort by voldemort.
the class ClusterTestUtils method getZ0Z2ClusterWithContiguousNodeIDs.
/**
* Construct 2 zones with zone IDs 0 and 2 respectively. The node ids are
* remapped to be contiguous though.
*/
public static Cluster getZ0Z2ClusterWithContiguousNodeIDs() {
// Hand construct zones 0 and 2
List<Zone> zones = Lists.newArrayList();
LinkedList<Integer> proximityList0 = Lists.newLinkedList();
proximityList0.add(2);
zones.add(new Zone(0, proximityList0));
LinkedList<Integer> proximityList2 = Lists.newLinkedList();
proximityList2.add(0);
zones.add(new Zone(2, proximityList2));
// Use getZEZCluster because zone 1 does not have any partitions in it!
Cluster cluster = getZEZCluster();
List<Node> nodeList = new ArrayList<Node>();
// Needed because node IDs must be contiguous?
int nodeId = 0;
for (Node node : cluster.getNodes()) {
// Do *not* add node from zone 1.
if (node.getZoneId() != 1) {
Node newNode = new Node(nodeId, node.getHost(), node.getHttpPort(), node.getSocketPort(), node.getAdminPort(), node.getZoneId(), node.getPartitionIds());
nodeList.add(newNode);
nodeId++;
}
}
Collections.sort(nodeList);
return new Cluster(cluster.getName(), nodeList, zones);
}
Aggregations