Search in sources :

Example 16 with RoutingStrategyFactory

use of voldemort.routing.RoutingStrategyFactory in project voldemort by voldemort.

the class ConsistencyCheckTest method testOnePartitionEndToEndBasedOnVersion.

@Test
public void testOnePartitionEndToEndBasedOnVersion() throws Exception {
    long now = System.currentTimeMillis();
    // setup four nodes with one store and one partition
    final SocketStoreFactory socketStoreFactory = new ClientRequestExecutorPool(2, 10000, 100000, 32 * 1024);
    VoldemortServer[] servers = new VoldemortServer[4];
    int[][] partitionMap = { { 0 }, { 1 }, { 2 }, { 3 } };
    Cluster cluster = ServerTestUtils.startVoldemortCluster(4, servers, partitionMap, socketStoreFactory, true, null, STORES_XML, new Properties());
    Node node = cluster.getNodeById(0);
    String bootstrapUrl = "tcp://" + node.getHost() + ":" + node.getSocketPort();
    AdminClient adminClient = new AdminClient(bootstrapUrl);
    byte[] value = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
    byte[] value2 = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
    // make versions
    VectorClock vc1 = new VectorClock();
    VectorClock vc2 = new VectorClock();
    VectorClock vc3 = new VectorClock();
    // [0:1]
    vc1.incrementVersion(0, now);
    // [1:1]
    vc2.incrementVersion(1, now - 5000);
    // [0:1], over a day old
    vc3.incrementVersion(0, now - 89000000);
    ArrayList<Pair<ByteArray, Versioned<byte[]>>> n0store = new ArrayList<Pair<ByteArray, Versioned<byte[]>>>();
    ArrayList<Pair<ByteArray, Versioned<byte[]>>> n1store = new ArrayList<Pair<ByteArray, Versioned<byte[]>>>();
    ArrayList<Pair<ByteArray, Versioned<byte[]>>> n2store = new ArrayList<Pair<ByteArray, Versioned<byte[]>>>();
    ArrayList<Pair<ByteArray, Versioned<byte[]>>> n3store = new ArrayList<Pair<ByteArray, Versioned<byte[]>>>();
    ArrayList<ByteArray> keysHashedToPar0 = new ArrayList<ByteArray>();
    // find store
    Versioned<List<StoreDefinition>> storeDefinitions = adminClient.metadataMgmtOps.getRemoteStoreDefList(0);
    List<StoreDefinition> StoreDefinitions = storeDefinitions.getValue();
    StoreDefinition storeDefinition = null;
    for (StoreDefinition def : StoreDefinitions) {
        if (def.getName().equals(STORE_NAME)) {
            storeDefinition = def;
            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;
        }
    }
    ByteArray k6 = keysHashedToPar0.get(6);
    ByteArray k5 = keysHashedToPar0.get(5);
    ByteArray k4 = keysHashedToPar0.get(4);
    ByteArray k3 = keysHashedToPar0.get(3);
    ByteArray k2 = keysHashedToPar0.get(2);
    ByteArray k1 = keysHashedToPar0.get(1);
    ByteArray k0 = keysHashedToPar0.get(0);
    // insert K6 into node 0,1,2
    Versioned<byte[]> v6 = new Versioned<byte[]>(value, vc1);
    n0store.add(Pair.create(k6, v6));
    n1store.add(Pair.create(k6, v6));
    n2store.add(Pair.create(k6, v6));
    // insert K6(conflicting value and version) into node 0,1,2,3
    Versioned<byte[]> v6ConflictEarly = new Versioned<byte[]>(value2, vc2);
    n0store.add(Pair.create(k6, v6ConflictEarly));
    n1store.add(Pair.create(k6, v6ConflictEarly));
    n2store.add(Pair.create(k6, v6ConflictEarly));
    n3store.add(Pair.create(k6, v6ConflictEarly));
    // insert K4,K5 into four nodes
    Versioned<byte[]> v5 = new Versioned<byte[]>(value, vc1);
    Versioned<byte[]> v4 = new Versioned<byte[]>(value, vc1);
    n0store.add(Pair.create(k5, v5));
    n1store.add(Pair.create(k5, v5));
    n2store.add(Pair.create(k5, v5));
    n3store.add(Pair.create(k5, v5));
    n0store.add(Pair.create(k4, v4));
    n1store.add(Pair.create(k4, v4));
    n2store.add(Pair.create(k4, v4));
    n3store.add(Pair.create(k4, v4));
    // insert K3 into node 0,1,2
    Versioned<byte[]> v3 = new Versioned<byte[]>(value, vc2);
    n0store.add(Pair.create(k3, v3));
    n1store.add(Pair.create(k3, v3));
    n2store.add(Pair.create(k3, v3));
    // insert K3(conflicting but latest version) into node 0,1,2,3
    Versioned<byte[]> v3ConflictLate = new Versioned<byte[]>(value, vc1);
    n0store.add(Pair.create(k3, v3ConflictLate));
    n1store.add(Pair.create(k3, v3ConflictLate));
    n2store.add(Pair.create(k3, v3ConflictLate));
    n3store.add(Pair.create(k3, v3ConflictLate));
    // insert K2 into node 0,1
    Versioned<byte[]> v2 = new Versioned<byte[]>(value, vc1);
    n0store.add(Pair.create(k2, v2));
    n1store.add(Pair.create(k2, v2));
    // insert K1 into node 0
    Versioned<byte[]> v1 = new Versioned<byte[]>(value, vc1);
    n0store.add(Pair.create(k1, v1));
    // insert K0(out of retention) into node 0,1,2
    Versioned<byte[]> v0 = new Versioned<byte[]>(value, vc3);
    n0store.add(Pair.create(k0, v0));
    n1store.add(Pair.create(k0, v0));
    n2store.add(Pair.create(k0, v0));
    // stream to store
    adminClient.streamingOps.updateEntries(0, STORE_NAME, n0store.iterator(), null);
    adminClient.streamingOps.updateEntries(1, STORE_NAME, n1store.iterator(), null);
    adminClient.streamingOps.updateEntries(2, STORE_NAME, n2store.iterator(), null);
    adminClient.streamingOps.updateEntries(3, STORE_NAME, n3store.iterator(), null);
    // should have FULL:2(K4,K5), LATEST_CONSISTENT:1(K3),
    // INCONSISTENT:2(K6,K2), ignored(K1,K0)
    List<String> urls = new ArrayList<String>();
    urls.add(bootstrapUrl);
    ConsistencyCheck.ComparisonType[] comparisonTypes = ConsistencyCheck.ComparisonType.values();
    for (ConsistencyCheck.ComparisonType type : comparisonTypes) {
        StringWriter sw = new StringWriter();
        ConsistencyCheck checker = new ConsistencyCheck(urls, STORE_NAME, 0, sw, type);
        Reporter reporter = null;
        checker.connect();
        reporter = checker.execute();
        assertEquals(7 - 2, reporter.numTotalKeys);
        assertEquals(3, reporter.numGoodKeys);
    }
    for (VoldemortServer vs : servers) {
        vs.stop();
    }
}
Also used : Versioned(voldemort.versioning.Versioned) RoutingStrategyFactory(voldemort.routing.RoutingStrategyFactory) ClusterNode(voldemort.utils.ConsistencyCheck.ClusterNode) Node(voldemort.cluster.Node) ArrayList(java.util.ArrayList) VoldemortServer(voldemort.server.VoldemortServer) Properties(java.util.Properties) StringWriter(java.io.StringWriter) StoreDefinition(voldemort.store.StoreDefinition) RoutingStrategy(voldemort.routing.RoutingStrategy) ArrayList(java.util.ArrayList) List(java.util.List) VectorClock(voldemort.versioning.VectorClock) Reporter(voldemort.utils.ConsistencyCheck.Reporter) Cluster(voldemort.cluster.Cluster) SocketStoreFactory(voldemort.store.socket.SocketStoreFactory) ClientRequestExecutorPool(voldemort.store.socket.clientrequest.ClientRequestExecutorPool) AdminClient(voldemort.client.protocol.admin.AdminClient) Test(org.junit.Test)

Example 17 with RoutingStrategyFactory

use of voldemort.routing.RoutingStrategyFactory in project voldemort by voldemort.

the class HintedHandoffSendHintTest method setUp.

@Before
public void setUp() throws Exception {
    if (logger.isDebugEnabled()) {
        logger.debug("Test Started: replication[" + REPLICATION_FACTOR + "], preferredW[" + P_WRITES + "], requiredW[" + R_WRITES + "]");
    }
    cluster = getNineNodeCluster();
    storeDef = getStoreDef();
    // create voldemort servers
    for (Integer nodeId = 0; nodeId < NUM_NODES_TOTAL; nodeId++) {
        SocketStoreFactory socketStoreFactory;
        socketStoreFactory = new ClientRequestExecutorPool(2, 10000, 100000, 1024);
        List<StoreDefinition> stores = new ArrayList<StoreDefinition>();
        stores.add(storeDef);
        VoldemortConfig config = ServerTestUtils.createServerConfigWithDefs(true, nodeId, TestUtils.createTempDir().getAbsolutePath(), cluster, stores, new Properties());
        config.setNioAdminConnectorSelectors(1);
        config.setNioConnectorSelectors(2);
        VoldemortServer vs = ServerTestUtils.startVoldemortServer(socketStoreFactory, config);
        VoldemortService vsrv = vs.getService(ServiceType.STORAGE);
        StorageService ss = (StorageService) vsrv;
        voldemortServers.put(nodeId, vs);
        slopStorageEngines.put(nodeId, ss.getStoreRepository().getSlopStore());
        slopStores.put(nodeId, SerializingStore.wrap(ss.getStoreRepository().getSlopStore(), new ByteArraySerializer(), new SlopSerializer(), new IdentitySerializer()));
        // wrap original store with force fail store
        Store<ByteArray, byte[], byte[]> store = ss.getStoreRepository().removeLocalStore(STORE_NAME);
        UnreachableStoreException exception = new UnreachableStoreException("Force failed");
        ForceFailStore<ByteArray, byte[], byte[]> forceFailStore = new ForceFailStore<ByteArray, byte[], byte[]>(store, exception);
        forceFailStores.put(nodeId, forceFailStore);
        ss.getStoreRepository().addLocalStore(forceFailStore);
    }
    strategy = new RoutingStrategyFactory().updateRoutingStrategy(storeDef, cluster);
    // create client socket stores and slop stores
    SocketStoreClientFactoryForTest clientSocketStoreFactory = new SocketStoreClientFactoryForTest(STORE_NAME, SLOP_STORE_NAME);
    Serializer<ByteArray> slopKeySerializer = new ByteArraySerializer();
    Serializer<Slop> slopValueSerializer = new SlopSerializer();
    Map<Integer, Store<ByteArray, byte[], byte[]>> testStores = subStores;
    Map<Integer, Store<ByteArray, Slop, byte[]>> slopStores = new HashMap<Integer, Store<ByteArray, Slop, byte[]>>();
    for (Node node : cluster.getNodes()) {
        // test store
        SocketStore socketTestStore = clientSocketStoreFactory.getSocketTestStoreByNode(node);
        socketTestStores.put(node.getId(), socketTestStore);
        testStores.put(node.getId(), socketTestStore);
        // slop store
        SocketStore socketSlopStore = clientSocketStoreFactory.getSocketSlopStoreByNode(node);
        Store<ByteArray, Slop, byte[]> slopStore = SerializingStore.wrap(socketSlopStore, slopKeySerializer, slopValueSerializer, new IdentitySerializer());
        socketSlopStores.put(node.getId(), socketSlopStore);
        slopStores.put(node.getId(), slopStore);
    }
    // set failure detector
    if (failureDetector != null)
        failureDetector.destroy();
    FailureDetectorConfig failureDetectorConfig = new FailureDetectorConfig();
    failureDetectorConfig.setImplementationClassName(failureDetectorCls.getName());
    failureDetectorConfig.setThreshold(50);
    failureDetectorConfig.setCluster(cluster);
    failureDetectorConfig.setConnectionVerifier(MutableStoreConnectionVerifier.create(subStores));
    failureDetector = FailureDetectorUtils.create(failureDetectorConfig, false);
    // make routedStore
    RoutedStoreFactory factory = new RoutedStoreFactory();
    routedStore = factory.create(cluster, storeDef, testStores, socketTestStores, slopStores, socketSlopStores, failureDetector, new RoutedStoreConfig().setTimeoutConfig(new TimeoutConfig(1500L, false)));
    // generate the keys
    for (int i = 0; i < 5; i++) {
        Set<Integer> nodesCovered = Sets.newHashSet();
        while (nodesCovered.size() < NUM_NODES_TOTAL) {
            ByteArray randomKey = new ByteArray(TestUtils.randomBytes(KEY_LENGTH));
            byte[] randomValue = TestUtils.randomBytes(VALUE_LENGTH);
            if (randomKey.length() > 0 && randomValue.length > 0) {
                if (!keyList.contains(randomKey)) {
                    for (Node node : strategy.routeRequest(randomKey.get())) {
                        keysToNodes.put(randomKey, node.getId());
                        nodesCovered.add(node.getId());
                    }
                    logger.info("Inserting key [" + randomKey + "] to key list as id:" + keyList.size());
                    keyList.add(randomKey);
                    keyValues.put(randomKey, new ByteArray(randomValue));
                }
            }
        }
    }
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) RoutingStrategyFactory(voldemort.routing.RoutingStrategyFactory) Node(voldemort.cluster.Node) ArrayList(java.util.ArrayList) SocketStore(voldemort.store.socket.SocketStore) Store(voldemort.store.Store) SerializingStore(voldemort.store.serialized.SerializingStore) ForceFailStore(voldemort.store.ForceFailStore) NonblockingStore(voldemort.store.nonblockingstore.NonblockingStore) Properties(java.util.Properties) VoldemortServer(voldemort.server.VoldemortServer) ByteArraySerializer(voldemort.serialization.ByteArraySerializer) VoldemortConfig(voldemort.server.VoldemortConfig) StorageService(voldemort.server.storage.StorageService) VoldemortService(voldemort.common.service.VoldemortService) StoreDefinition(voldemort.store.StoreDefinition) ByteArray(voldemort.utils.ByteArray) IdentitySerializer(voldemort.serialization.IdentitySerializer) UnreachableStoreException(voldemort.store.UnreachableStoreException) ForceFailStore(voldemort.store.ForceFailStore) TimeoutConfig(voldemort.client.TimeoutConfig) SocketStoreFactory(voldemort.store.socket.SocketStoreFactory) SocketStore(voldemort.store.socket.SocketStore) ClientRequestExecutorPool(voldemort.store.socket.clientrequest.ClientRequestExecutorPool) FailureDetectorConfig(voldemort.cluster.failuredetector.FailureDetectorConfig) SlopSerializer(voldemort.serialization.SlopSerializer) Slop(voldemort.store.slop.Slop) Before(org.junit.Before)

Example 18 with RoutingStrategyFactory

use of voldemort.routing.RoutingStrategyFactory in project voldemort by voldemort.

the class TestUtils method makeSingleNodeRoutingStrategy.

/**
     * Provides a routing strategy for local tests to work with
     * 
     * @return
     */
public static RoutingStrategy makeSingleNodeRoutingStrategy() {
    Cluster cluster = VoldemortTestConstants.getOneNodeCluster();
    StoreDefinitionsMapper mapper = new StoreDefinitionsMapper();
    List<StoreDefinition> storeDefs = mapper.readStoreList(new StringReader(VoldemortTestConstants.getSingleStoreDefinitionsXml()));
    return new RoutingStrategyFactory().updateRoutingStrategy(storeDefs.get(0), cluster);
}
Also used : RoutingStrategyFactory(voldemort.routing.RoutingStrategyFactory) StoreDefinition(voldemort.store.StoreDefinition) StoreDefinitionsMapper(voldemort.xml.StoreDefinitionsMapper) StringReader(java.io.StringReader) Cluster(voldemort.cluster.Cluster)

Example 19 with RoutingStrategyFactory

use of voldemort.routing.RoutingStrategyFactory in project voldemort by voldemort.

the class StreamingClientTest method verifyKeysExist.

/*
     * Checks if each node has the keys it is reponsible for returns false
     * otherwise
     */
public boolean verifyKeysExist(int nodeIdToVerifyOn) {
    RoutingStrategyFactory factory = new RoutingStrategyFactory();
    RoutingStrategy storeRoutingStrategy = factory.updateRoutingStrategy(storeDef, adminClient.getAdminClientCluster());
    HashMap<Integer, ArrayList<String>> expectedNodeIdToKeys;
    expectedNodeIdToKeys = new HashMap();
    Collection<Node> nodesInCluster = adminClient.getAdminClientCluster().getNodes();
    for (Node node : nodesInCluster) {
        ArrayList<String> keysForNode = new ArrayList();
        expectedNodeIdToKeys.put(node.getId(), keysForNode);
    }
    for (int i = 0; i < NUM_KEYS_1; i++) {
        String key = i + "";
        String value = key;
        List<Node> nodeList = storeRoutingStrategy.routeRequest(key.getBytes());
        for (Node node : nodeList) {
            ArrayList<String> keysForNode = expectedNodeIdToKeys.get(node.getId());
            keysForNode.add(key);
        }
    }
    ArrayList<String> fetchedKeysForNode = new ArrayList();
    for (Node node : nodesInCluster) {
        List<Integer> partitionIdList = Lists.newArrayList();
        partitionIdList.addAll(node.getPartitionIds());
        Iterator<ByteArray> keyIteratorRef = null;
        keyIteratorRef = adminClient.bulkFetchOps.fetchKeys(node.getId(), TEST_STORE_NAME, partitionIdList, null, false);
        final SerializerDefinition serializerDef = storeDef.getKeySerializer();
        final SerializerFactory serializerFactory = new DefaultSerializerFactory();
        @SuppressWarnings("unchecked") final Serializer<Object> serializer = (Serializer<Object>) serializerFactory.getSerializer(serializerDef);
        final CompressionStrategy keysCompressionStrategy;
        if (serializerDef != null && serializerDef.hasCompression()) {
            keysCompressionStrategy = new CompressionStrategyFactory().get(serializerDef.getCompression());
        } else {
            keysCompressionStrategy = null;
        }
        final Iterator<ByteArray> keyIterator = keyIteratorRef;
        while (keyIterator.hasNext()) {
            byte[] keyBytes = keyIterator.next().get();
            try {
                Object keyObject = serializer.toObject((null == keysCompressionStrategy) ? keyBytes : keysCompressionStrategy.inflate(keyBytes));
                fetchedKeysForNode.add((String) keyObject);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    ArrayList<String> keysForNode = expectedNodeIdToKeys.get(nodeIdToVerifyOn);
    if (!fetchedKeysForNode.containsAll(keysForNode))
        return false;
    else
        return true;
}
Also used : HashMap(java.util.HashMap) RoutingStrategyFactory(voldemort.routing.RoutingStrategyFactory) Node(voldemort.cluster.Node) ArrayList(java.util.ArrayList) CompressionStrategy(voldemort.store.compress.CompressionStrategy) CompressionStrategyFactory(voldemort.store.compress.CompressionStrategyFactory) RoutingStrategy(voldemort.routing.RoutingStrategy) ByteArray(voldemort.utils.ByteArray) Serializer(voldemort.serialization.Serializer) DefaultSerializerFactory(voldemort.serialization.DefaultSerializerFactory) SerializerFactory(voldemort.serialization.SerializerFactory) IOException(java.io.IOException) DefaultSerializerFactory(voldemort.serialization.DefaultSerializerFactory) SerializerDefinition(voldemort.serialization.SerializerDefinition)

Example 20 with RoutingStrategyFactory

use of voldemort.routing.RoutingStrategyFactory in project voldemort by voldemort.

the class AdminServiceBasicTest method testFetchAndUpdateRW.

/**
     * Tests the basic RW fetch and update
     */
@Test
public void testFetchAndUpdateRW() {
    HashMap<ByteArray, byte[]> entrySet = ServerTestUtils.createRandomKeyValuePairs(TEST_STREAM_KEYS_SIZE);
    List<Integer> primaryMoved = Arrays.asList(0, 2);
    List<Integer> secondaryMoved = Arrays.asList(1, 4);
    List<Integer> combinedLists = Arrays.asList(0, 1, 2, 4);
    Cluster targetCluster = UpdateClusterUtils.createUpdatedCluster(cluster, 1, primaryMoved);
    HashMap<ByteArray, byte[]> keysMovedWith0AsSecondary = Maps.newHashMap();
    // insert it into server-0 store
    RoutingStrategy strategy = new RoutingStrategyFactory().updateRoutingStrategy(StoreDefinitionUtils.getStoreDefinitionWithName(storeDefs, "test-recovery-data"), cluster);
    Store<ByteArray, byte[], byte[]> store0 = getStore(0, "test-recovery-data");
    Store<ByteArray, byte[], byte[]> store1 = getStore(1, "test-recovery-data");
    for (Entry<ByteArray, byte[]> entry : entrySet.entrySet()) {
        store0.put(entry.getKey(), new Versioned<byte[]>(entry.getValue()), null);
        List<Integer> partitions = strategy.getPartitionList(entry.getKey().get());
        if (primaryMoved.contains(partitions.get(0)) || (secondaryMoved.contains(partitions.get(0)) && cluster.getNodeById(0).getPartitionIds().contains(partitions.get(1)))) {
            keysMovedWith0AsSecondary.put(entry.getKey(), entry.getValue());
        }
    }
    // Assert that server1 is empty.
    for (Entry<ByteArray, byte[]> entry : entrySet.entrySet()) assertEquals("server1 should be empty at start.", 0, store1.get(entry.getKey(), null).size());
    // Set some other metadata, so as to pick the right up later
    getServer(0).getMetadataStore().put(MetadataStore.CLUSTER_KEY, targetCluster);
    // Migrate the partition
    AdminClient client = getAdminClient();
    int id = client.storeMntOps.migratePartitions(0, 1, "test-recovery-data", combinedLists, null, cluster);
    client.rpcOps.waitForCompletion(1, id, 120, TimeUnit.SECONDS);
    // Check the values
    for (Entry<ByteArray, byte[]> entry : keysMovedWith0AsSecondary.entrySet()) {
        assertEquals("server1 store should contain fetchAndupdated partitions.", 1, store1.get(entry.getKey(), null).size());
        assertEquals("entry value should match", new String(entry.getValue()), new String(store1.get(entry.getKey(), null).get(0).getValue()));
    }
}
Also used : RoutingStrategyFactory(voldemort.routing.RoutingStrategyFactory) Cluster(voldemort.cluster.Cluster) RoutingStrategy(voldemort.routing.RoutingStrategy) ByteArray(voldemort.utils.ByteArray) AdminClient(voldemort.client.protocol.admin.AdminClient) Test(org.junit.Test)

Aggregations

RoutingStrategyFactory (voldemort.routing.RoutingStrategyFactory)32 RoutingStrategy (voldemort.routing.RoutingStrategy)23 ByteArray (voldemort.utils.ByteArray)20 StoreDefinition (voldemort.store.StoreDefinition)19 Node (voldemort.cluster.Node)15 Cluster (voldemort.cluster.Cluster)14 File (java.io.File)9 Test (org.junit.Test)9 VoldemortException (voldemort.VoldemortException)9 Versioned (voldemort.versioning.Versioned)9 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)8 Pair (voldemort.utils.Pair)7 StoreDefinitionsMapper (voldemort.xml.StoreDefinitionsMapper)6 IOException (java.io.IOException)5 SerializerDefinition (voldemort.serialization.SerializerDefinition)5 VoldemortServer (voldemort.server.VoldemortServer)5 AdminClient (voldemort.client.protocol.admin.AdminClient)4 DefaultSerializerFactory (voldemort.serialization.DefaultSerializerFactory)4 Serializer (voldemort.serialization.Serializer)4