Search in sources :

Example 86 with Cluster

use of voldemort.cluster.Cluster in project voldemort by voldemort.

the class RoutedStoreTest method testGetAndPutTimeoutZZZ.

@Test
public void testGetAndPutTimeoutZZZ() throws Exception {
    int timeout = 50;
    // Set replication factors for a 3 zone cluster
    HashMap<Integer, Integer> zoneReplicationFactor = Maps.newHashMap();
    zoneReplicationFactor.put(0, 1);
    zoneReplicationFactor.put(1, 1);
    zoneReplicationFactor.put(2, 1);
    // Create a store with RF=3, Required reads = 3 and zone count reads = 2
    // This ensures that a GET operation requires a response from all 3
    // nodes (from the respective 3 zones)
    StoreDefinition definition = new StoreDefinitionBuilder().setName("test").setType("foo").setKeySerializer(new SerializerDefinition("test")).setValueSerializer(new SerializerDefinition("test")).setRoutingPolicy(RoutingTier.CLIENT).setRoutingStrategyType(RoutingStrategyType.ZONE_STRATEGY).setHintedHandoffStrategy(HintedHandoffStrategyType.PROXIMITY_STRATEGY).setReplicationFactor(3).setPreferredReads(3).setRequiredReads(3).setPreferredWrites(3).setRequiredWrites(3).setZoneCountReads(2).setZoneCountWrites(2).setZoneReplicationFactor(zoneReplicationFactor).build();
    Map<Integer, Store<ByteArray, byte[], byte[]>> stores = new HashMap<Integer, Store<ByteArray, byte[], byte[]>>();
    List<Node> nodes = new ArrayList<Node>();
    int totalDelay = 0;
    for (int i = 0; i < 3; i++) {
        int delay = 4 + i * timeout;
        totalDelay += delay;
        Store<ByteArray, byte[], byte[]> store = new SleepyStore<ByteArray, byte[], byte[]>(delay, new InMemoryStorageEngine<ByteArray, byte[], byte[]>("test"));
        stores.put(i, store);
        List<Integer> partitions = Arrays.asList(i);
        nodes.add(new Node(i, "none", 0, 0, 0, i, partitions));
    }
    setFailureDetector(stores);
    routedStoreThreadPool = Executors.newFixedThreadPool(3);
    RoutedStoreFactory routedStoreFactory = createFactory();
    List<Zone> zones = Lists.newArrayList();
    for (int i = 0; i < 3; i++) {
        LinkedList<Integer> zoneProximityList = Lists.newLinkedList();
        Set<Integer> zoneIds = Sets.newHashSet(0, 1, 2);
        zoneIds.remove(i);
        zoneProximityList.addAll(zoneIds);
        zones.add(new Zone(i, zoneProximityList));
    }
    RoutedStore routedStore = routedStoreFactory.create(new Cluster("test", nodes, zones), definition, stores, failureDetector, createConfig(timeout));
    long start = System.nanoTime();
    try {
        routedStore.get(new ByteArray("test".getBytes()), null);
        fail("Should have thrown");
    } catch (InsufficientOperationalNodesException e) {
        long elapsed = (System.nanoTime() - start) / Time.NS_PER_MS;
        assertTrue(elapsed + " < " + totalDelay, elapsed < totalDelay);
    }
    start = System.nanoTime();
    try {
        routedStore.put(new ByteArray("test".getBytes()), new Versioned<byte[]>(new byte[] { 1 }), null);
        fail("Should have thrown");
    } catch (InsufficientOperationalNodesException e) {
        long elapsed = (System.nanoTime() - start) / Time.NS_PER_MS;
        assertTrue(elapsed + " < " + totalDelay, elapsed < totalDelay);
    }
}
Also used : HashMap(java.util.HashMap) Node(voldemort.cluster.Node) ArrayList(java.util.ArrayList) Store(voldemort.store.Store) SleepyStore(voldemort.store.SleepyStore) StatTrackingStore(voldemort.store.stats.StatTrackingStore) InconsistencyResolvingStore(voldemort.store.versioned.InconsistencyResolvingStore) FailingStore(voldemort.store.FailingStore) FailingReadsStore(voldemort.store.FailingReadsStore) StoreDefinition(voldemort.store.StoreDefinition) ByteArray(voldemort.utils.ByteArray) StoreDefinitionBuilder(voldemort.store.StoreDefinitionBuilder) Zone(voldemort.cluster.Zone) VoldemortTestConstants.getNineNodeCluster(voldemort.VoldemortTestConstants.getNineNodeCluster) Cluster(voldemort.cluster.Cluster) SleepyStore(voldemort.store.SleepyStore) InsufficientOperationalNodesException(voldemort.store.InsufficientOperationalNodesException) SerializerDefinition(voldemort.serialization.SerializerDefinition) AbstractByteArrayStoreTest(voldemort.store.AbstractByteArrayStoreTest) Test(org.junit.Test)

Example 87 with Cluster

use of voldemort.cluster.Cluster in project voldemort by voldemort.

the class ConfigureNodesLocalHostTest method testConfigureNodesLocalHost.

/*
     * Checks to see that the local host is obtained as the first node in the
     * list returned by ConfigureNodesLocalHost
     */
@Test
public void testConfigureNodesLocalHost() throws Exception {
    List<Node> nodes = getTestNodes();
    Cluster cluster = new Cluster("test-route-all-local-pref-cluster", nodes);
    FailureDetector failureDetector = new ThresholdFailureDetector(new FailureDetectorConfig().setCluster(cluster));
    RoutingStrategy routingStrategy = new RouteToAllLocalPrefStrategy(cluster.getNodesShuffled());
    BasicPipelineData<byte[]> pipelineData = new BasicPipelineData<byte[]>();
    ConfigureNodesLocalHost<byte[], BasicPipelineData<byte[]>> action = new ConfigureNodesLocalHost<byte[], BasicPipelineData<byte[]>>(pipelineData, Event.COMPLETED, failureDetector, 1, routingStrategy, aKey);
    Pipeline pipeline = new Pipeline(Operation.GET, 10000, TimeUnit.MILLISECONDS);
    pipeline.addEventAction(Event.STARTED, action);
    pipeline.addEvent(Event.STARTED);
    pipeline.execute();
    if (pipelineData.getFatalError() != null)
        throw pipelineData.getFatalError();
    assertEquals(cluster.getNodes().size(), pipelineData.getNodes().size());
    assertEquals(cluster.getNodesShuffled().size(), pipelineData.getNodes().size());
    assertEquals(pipelineData.getNodes().get(0).getHost(), currentHost);
}
Also used : ThresholdFailureDetector(voldemort.cluster.failuredetector.ThresholdFailureDetector) Node(voldemort.cluster.Node) Cluster(voldemort.cluster.Cluster) Pipeline(voldemort.store.routed.Pipeline) BasicPipelineData(voldemort.store.routed.BasicPipelineData) ThresholdFailureDetector(voldemort.cluster.failuredetector.ThresholdFailureDetector) FailureDetector(voldemort.cluster.failuredetector.FailureDetector) FailureDetectorConfig(voldemort.cluster.failuredetector.FailureDetectorConfig) RoutingStrategy(voldemort.routing.RoutingStrategy) RouteToAllLocalPrefStrategy(voldemort.routing.RouteToAllLocalPrefStrategy) Test(org.junit.Test)

Example 88 with Cluster

use of voldemort.cluster.Cluster in project voldemort by voldemort.

the class MetaOperationsTest method testMetaGet.

@Test
public void testMetaGet() throws Exception {
    Integer nodeId = 0;
    String tempDir = System.getProperty("java.io.tmpdir") + "temp" + System.currentTimeMillis();
    // get metadata and write to files
    AdminCommand.executeCommand(new String[] { "meta", "get", MetadataStore.CLUSTER_KEY + "," + MetadataStore.STORES_KEY, "-u", bsURL, "-n", nodeId.toString(), "-d", tempDir });
    // load metadata files
    String clusterFile = tempDir + "/" + MetadataStore.CLUSTER_KEY + "_" + nodeId;
    String storesFile = tempDir + "/" + MetadataStore.STORES_KEY + "_" + nodeId;
    assertTrue(Utils.isReadableFile(clusterFile));
    assertTrue(Utils.isReadableFile(storesFile));
    ClusterMapper clusterMapper = new ClusterMapper();
    StoreDefinitionsMapper storeDefsMapper = new StoreDefinitionsMapper();
    Cluster newCluster = clusterMapper.readCluster(new File(clusterFile));
    List<StoreDefinition> newStores = storeDefsMapper.readStoreList(new File(storesFile));
    // compare metadata objects
    assertTrue(newCluster.equals(cluster));
    assertTrue(newStores.size() == stores.size());
    for (StoreDefinition store : stores) {
        assertTrue(newStores.contains(store));
    }
}
Also used : StoreDefinition(voldemort.store.StoreDefinition) StoreDefinitionsMapper(voldemort.xml.StoreDefinitionsMapper) Cluster(voldemort.cluster.Cluster) ClusterMapper(voldemort.xml.ClusterMapper) File(java.io.File) Test(org.junit.Test)

Example 89 with Cluster

use of voldemort.cluster.Cluster in project voldemort by voldemort.

the class RepartitionerTest method verifyBalanceZoneAndNode.

/**
     * Verify balancing of partitions among zones, and within each zone, among
     * nodes.
     * 
     * @param currentCluster
     * @param currentStores
     * @param interimCluster
     * @param finalStores
     */
public void verifyBalanceZoneAndNode(Cluster currentCluster, List<StoreDefinition> currentStores, Cluster interimCluster, List<StoreDefinition> finalStores) {
    // Confirm current cluster is imbalanced on all fronts:
    assertFalse(verifyNodesBalancedInEachZone(currentCluster));
    assertFalse(verifyZonesBalanced(currentCluster));
    // Repartition to balance partition IDs among zones and among nodes
    // within zone.
    boolean disableNodeBalancing = false;
    boolean disableZoneBalancing = false;
    Cluster repartitionedCluster = Repartitioner.repartition(currentCluster, currentStores, interimCluster, finalStores, null, 1, disableNodeBalancing, disableZoneBalancing, false, 0, 0, Collections.<Integer>emptyList(), false, 0, 0, 0, Collections.<Integer>emptyList(), 0);
    assertTrue(verifyNodesBalancedInEachZone(repartitionedCluster));
    assertTrue(verifyZonesBalanced(repartitionedCluster));
}
Also used : Cluster(voldemort.cluster.Cluster)

Example 90 with Cluster

use of voldemort.cluster.Cluster in project voldemort by voldemort.

the class RepartitionerTest method verifyRandomSwapsImproveBalance.

/**
     * Verify that random swaps improve balance.
     * 
     * @param currentCluster
     * @param currentStores
     */
public void verifyRandomSwapsImproveBalance(Cluster currentCluster, List<StoreDefinition> currentStores) {
    // Confirm current cluster is imbalanced on all fronts:
    assertFalse(verifyNodesBalancedInEachZone(currentCluster));
    assertFalse(verifyZonesBalanced(currentCluster));
    PartitionBalance currentPb = new PartitionBalance(currentCluster, currentStores);
    // Disable basic balancing among zones & nodes
    boolean disableNodeBalancing = true;
    boolean disableZoneBalancing = true;
    // Do some random swaps!
    boolean enableRandomSwaps = true;
    int swapAttempts = 100;
    int swapSuccesses = 1;
    Cluster repartitionedCluster = Repartitioner.repartition(currentCluster, currentStores, currentCluster, currentStores, null, 1, disableNodeBalancing, disableZoneBalancing, enableRandomSwaps, swapAttempts, swapSuccesses, Collections.<Integer>emptyList(), false, 0, 0, 0, Collections.<Integer>emptyList(), 0);
    // Confirm repartitioned cluster is still imbalanced on all fronts
    assertFalse(verifyNodesBalancedInEachZone(repartitionedCluster));
    assertFalse(verifyZonesBalanced(repartitionedCluster));
    // Confirm overall balance has been improved
    PartitionBalance repartitionedPb = new PartitionBalance(repartitionedCluster, currentStores);
    assertTrue(repartitionedPb.getUtility() < currentPb.getUtility());
}
Also used : Cluster(voldemort.cluster.Cluster)

Aggregations

Cluster (voldemort.cluster.Cluster)197 Test (org.junit.Test)74 StoreDefinition (voldemort.store.StoreDefinition)74 Node (voldemort.cluster.Node)72 ArrayList (java.util.ArrayList)51 HashMap (java.util.HashMap)47 ByteArray (voldemort.utils.ByteArray)33 AdminClient (voldemort.client.protocol.admin.AdminClient)26 ClusterTestUtils (voldemort.ClusterTestUtils)25 VoldemortException (voldemort.VoldemortException)24 List (java.util.List)23 ClusterMapper (voldemort.xml.ClusterMapper)23 File (java.io.File)20 StoreDefinitionsMapper (voldemort.xml.StoreDefinitionsMapper)18 Zone (voldemort.cluster.Zone)17 Versioned (voldemort.versioning.Versioned)17 Properties (java.util.Properties)16 IOException (java.io.IOException)15 VoldemortServer (voldemort.server.VoldemortServer)15 RoutingStrategyFactory (voldemort.routing.RoutingStrategyFactory)14