Search in sources :

Example 11 with Zone

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));
}
Also used : Zone(voldemort.cluster.Zone) Node(voldemort.cluster.Node) ArrayList(java.util.ArrayList) Cluster(voldemort.cluster.Cluster)

Example 12 with Zone

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);
    }
}
Also used : HashMap(java.util.HashMap) Zone(voldemort.cluster.Zone) Node(voldemort.cluster.Node) Cluster(voldemort.cluster.Cluster) VoldemortException(voldemort.VoldemortException) StoreDefinition(voldemort.store.StoreDefinition) List(java.util.List) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 13 with Zone

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);
    }
}
Also used : HashMap(java.util.HashMap) Zone(voldemort.cluster.Zone) Node(voldemort.cluster.Node) Cluster(voldemort.cluster.Cluster) VoldemortException(voldemort.VoldemortException) StoreDefinition(voldemort.store.StoreDefinition) List(java.util.List) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 14 with Zone

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;
}
Also used : Zone(voldemort.cluster.Zone) HashSet(java.util.HashSet)

Example 15 with Zone

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);
}
Also used : Zone(voldemort.cluster.Zone) Node(voldemort.cluster.Node) ArrayList(java.util.ArrayList) Cluster(voldemort.cluster.Cluster)

Aggregations

Zone (voldemort.cluster.Zone)23 Cluster (voldemort.cluster.Cluster)17 Node (voldemort.cluster.Node)17 ArrayList (java.util.ArrayList)13 VoldemortException (voldemort.VoldemortException)7 StoreDefinition (voldemort.store.StoreDefinition)7 HashMap (java.util.HashMap)6 List (java.util.List)6 Test (org.junit.Test)6 HashSet (java.util.HashSet)3 ByteArray (voldemort.utils.ByteArray)3 StringReader (java.io.StringReader)2 Document (org.jdom.Document)2 Element (org.jdom.Element)2 VoldemortTestConstants.getNineNodeCluster (voldemort.VoldemortTestConstants.getNineNodeCluster)2 SerializerDefinition (voldemort.serialization.SerializerDefinition)2 AbstractByteArrayStoreTest (voldemort.store.AbstractByteArrayStoreTest)2 FailingReadsStore (voldemort.store.FailingReadsStore)2 FailingStore (voldemort.store.FailingStore)2 InsufficientOperationalNodesException (voldemort.store.InsufficientOperationalNodesException)2