Package voldemort.routing

Examples of voldemort.routing.RoutingStrategy


    @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.getNodes());
        BasicPipelineData<byte[]> pipelineData = new BasicPipelineData<byte[]>();
        ConfigureNodesLocalHost<byte[], BasicPipelineData<byte[]>> action = new ConfigureNodesLocalHost<byte[], BasicPipelineData<byte[]>>(pipelineData,
                                                                                                                                           Event.COMPLETED,
                                                                                                                                           failureDetector,
                                                                                                                                           1,
View Full Code Here


                                                                        storeDef,
                                                                        subStores,
                                                                        failureDetector,
                                                                        createConfig(OPERATION_TIMEOUT));

        RoutingStrategy routingStrategy = new RoutingStrategyFactory().updateRoutingStrategy(storeDef,
                                                                                             cluster);

        List<Node> nodesRoutedTo = routingStrategy.routeRequest("test".getBytes());
        long start = System.nanoTime(), elapsed;
        try {
            s1.put(new ByteArray("test".getBytes()), versioned, null);
        } finally {
            elapsed = (System.nanoTime() - start) / Time.NS_PER_MS;
View Full Code Here

     */

    public static Map<Integer, Set<Pair<Integer, Integer>>> getNodeIdToAllPartitions(final Cluster cluster,
                                                                                     final StoreDefinition storeDef,
                                                                                     boolean includePrimary) {
        final RoutingStrategy routingStrategy = new RoutingStrategyFactory().updateRoutingStrategy(storeDef,
                                                                                                   cluster);

        final Map<Integer, Set<Pair<Integer, Integer>>> nodeIdToReplicas = new HashMap<Integer, Set<Pair<Integer, Integer>>>();
        final Map<Integer, Integer> partitionToNodeIdMap = cluster.getPartitionIdToNodeIdMap();

        // Map initialization.
        for(Node node: cluster.getNodes()) {
            nodeIdToReplicas.put(node.getId(), new HashSet<Pair<Integer, Integer>>());
        }

        // Track how many zones actually have partitions (and so replica types)
        // in them.
        int zonesWithPartitions = 0;
        for(Integer zoneId: cluster.getZoneIds()) {
            if(cluster.getNumberOfPartitionsInZone(zoneId) > 0) {
                zonesWithPartitions++;
            }
        }

        // Loops through all nodes
        for(Node node: cluster.getNodes()) {

            // Gets the partitions that this node was configured with.
            for(Integer primary: node.getPartitionIds()) {

                // Gets the list of replicating partitions.
                List<Integer> replicaPartitionList = routingStrategy.getReplicatingPartitionList(primary);

                if((replicaPartitionList.size() % zonesWithPartitions != 0)
                   || ((replicaPartitionList.size() / zonesWithPartitions) != (storeDef.getReplicationFactor() / cluster.getNumberOfZones()))) {

                    // For zone expansion & shrinking, this warning is expected
View Full Code Here

        File file = new File(args[0]);
        int repFactor = Integer.parseInt(args[1]);
        int maxVal = Integer.parseInt(args[2]);
        ClusterMapper mapper = new ClusterMapper();
        Cluster cluster = mapper.readCluster(file);
        RoutingStrategy strategy = new ConsistentRoutingStrategy(cluster, repFactor);
        JsonTypeSerializer serializer = new JsonTypeSerializer(JsonTypeDefinition.INT32);
        Map<Integer, Integer> counts = new HashMap<Integer, Integer>();

        for(int i = 0; i < maxVal; i++) {
            for(Node node: strategy.routeRequest(serializer.toBytes(i))) {
                int newCount = 1;
                if(counts.get(node.getId()) != null) {
                    newCount = counts.get(node.getId()) + 1;
                }
                counts.put(node.getId(), newCount);
View Full Code Here

                break;
            }
        }
        assertNotNull("No such store found: " + STORE_NAME, storeDefinition);

        RoutingStrategy router = new RoutingStrategyFactory().updateRoutingStrategy(storeDefinition,
                                                                                    cluster);
        while(keysHashedToPar0.size() < 7) {
            // generate random key
            Map<ByteArray, byte[]> map = ServerTestUtils.createRandomKeyValuePairs(1);
            ByteArray key = map.keySet().iterator().next();
            key.get()[0] = (byte) keysHashedToPar0.size();
            Integer masterPartition = router.getMasterPartition(key.get());
            if(masterPartition == 0) {
                keysHashedToPar0.add(key);
            } else {
                continue;
            }
View Full Code Here

        assertEquals(consistentStore.getName(), "cstore");
        assertEquals(zoneStore.getName(), "zstore");

        Cluster cluster = VoldemortTestConstants.getEightNodeClusterWithZones();
        RoutingStrategy cStrategy = new RoutingStrategyFactory().updateRoutingStrategy(consistentStore,
                                                                                       cluster);
        RoutingStrategy zStrategy = new RoutingStrategyFactory().updateRoutingStrategy(zoneStore,
                                                                                       cluster);
        BdbStorageEngine cPrefixedBdbStore = (BdbStorageEngine) bdbStorage.getStore(consistentStore,
                                                                                    cStrategy);
        BdbStorageEngine zPrefixedBdbStore = (BdbStorageEngine) bdbStorage.getStore(zoneStore,
                                                                                    zStrategy);
        HashMap<ByteArray, byte[]> kvpairs = ServerTestUtils.createRandomKeyValuePairs(10000);
        for(ByteArray key: kvpairs.keySet()) {
            assertEquals(cStrategy.getPartitionList(key.get()).get(0),
                         zStrategy.getPartitionList(key.get()).get(0));

            cPrefixedBdbStore.put(key, new Versioned<byte[]>(kvpairs.get(key)), null);
            zPrefixedBdbStore.put(key, new Versioned<byte[]>(kvpairs.get(key)), null);
        }
View Full Code Here

    @Test
    public void testPartitionScan() {

        StoreDefinition storedef = TestUtils.makeStoreDefinition("storeA");
        RoutingStrategy strategy = TestUtils.makeSingleNodeRoutingStrategy();
        BdbStorageEngine prefixedBdbStore = (BdbStorageEngine) bdbStorage.getStore(storedef,
                                                                                   strategy);
        try {
            // insert a bunch of records
            HashMap<Integer, Set<String>> partitionToKeysMap = new HashMap<Integer, Set<String>>();
            for(int i = 0; i < 10000; i++) {
                String key = "key" + i;
                byte[] bkey = key.getBytes();

                int partition = strategy.getPartitionList(bkey).get(0);
                if(!partitionToKeysMap.containsKey(partition))
                    partitionToKeysMap.put(partition, new HashSet<String>());
                partitionToKeysMap.get(partition).add(key);

                prefixedBdbStore.put(new ByteArray(bkey),
                                     new Versioned<byte[]>(("value" + i).getBytes()),
                                     null);
            }

            // check if they are properly retrieved by that partition id
            for(int p = 0; p < strategy.getNumReplicas(); p++) {

                // verify keys
                Set<String> keys = getKeys(prefixedBdbStore.keys(p));
                assertEquals(partitionToKeysMap.get(p).size(), keys.size());
                assertEquals(partitionToKeysMap.get(p), keys);
View Full Code Here

        this.primaryEntriesMoved = Maps.newHashMap();
        this.secondaryEntriesMoved = Maps.newHashMap();
        this.proxyPutTestPrimaryEntries = Maps.newHashMap();
        this.proxyPutTestSecondaryEntries = Maps.newHashMap();

        RoutingStrategy strategy = new
                RoutingStrategyFactory().updateRoutingStrategy(storeDef,
                                                               currentCluster);
        for(Entry<ByteArray, byte[]> entry: entrySet.entrySet()) {
            storeClient.put(new String(entry.getKey().get()), new
                            String(entry.getValue()));
            List<Integer> pList = strategy.getPartitionList(entry.getKey().get());
            if(primaryPartitionsMoved.contains(pList.get(0))) {
                primaryEntriesMoved.put(entry.getKey(), entry.getValue());
            } else if(secondaryPartitionsMoved.contains(pList.get(0))) {
                secondaryEntriesMoved.put(entry.getKey(), entry.getValue());
            }
View Full Code Here

                                                               .setPreferredReads(1)
                                                               .setRequiredReads(1)
                                                               .setPreferredWrites(1)
                                                               .setRequiredWrites(1)
                                                               .build();
        RoutingStrategy router = new RoutingStrategyFactory().updateRoutingStrategy(storeDef,
                                                                                    cluster);

        // build store files in outputDir
        File outputDir = TestUtils.createTempDir(baseDir);
        JsonStoreBuilder storeBuilder = new JsonStoreBuilder(reader,
View Full Code Here

    private boolean isKeyPartition(ByteArray key,
                                   int nodeId,
                                   String storeName,
                                   List<Integer> deletePartitionsList) {
        RoutingStrategy routing = getVoldemortServer(nodeId).getMetadataStore()
                                                            .getRoutingStrategy(storeName);
        for(int partition: routing.getPartitionList(key.get())) {
            if(deletePartitionsList.contains(partition)) {
                return true;
            }
        }
        return false;
View Full Code Here

TOP

Related Classes of voldemort.routing.RoutingStrategy

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.