Search in sources :

Example 6 with TimeoutConfig

use of voldemort.client.TimeoutConfig in project voldemort by voldemort.

the class GetallNodeReachTest method makeStore.

private void makeStore() {
    subStores = Maps.newHashMap();
    for (Node n : cluster.getNodes()) {
        Store<ByteArray, byte[], byte[]> subStore = new InMemoryStorageEngine<ByteArray, byte[], byte[]>("test");
        subStores.put(n.getId(), subStore);
    }
    RoutedStoreFactory routedStoreFactory = new RoutedStoreFactory(Executors.newFixedThreadPool(2));
    store = routedStoreFactory.create(cluster, storeDef, subStores, new NoopFailureDetector(), new RoutedStoreConfig().setTimeoutConfig(new TimeoutConfig(1000L)));
}
Also used : TimeoutConfig(voldemort.client.TimeoutConfig) InMemoryStorageEngine(voldemort.store.memory.InMemoryStorageEngine) NoopFailureDetector(voldemort.cluster.failuredetector.NoopFailureDetector) Node(voldemort.cluster.Node) ByteArray(voldemort.utils.ByteArray)

Example 7 with TimeoutConfig

use of voldemort.client.TimeoutConfig 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 8 with TimeoutConfig

use of voldemort.client.TimeoutConfig in project voldemort by voldemort.

the class ReadRepairerTest method testMissingKeysAreAddedToNodeWhenDoingReadRepair.

/**
     * See Issue 150: Missing keys are not added to node when performing
     * read-repair
     */
@Test
public void testMissingKeysAreAddedToNodeWhenDoingReadRepair() throws Exception {
    ByteArray key = TestUtils.toByteArray("key");
    byte[] value = "foo".getBytes();
    Cluster cluster = VoldemortTestConstants.getThreeNodeCluster();
    StoreDefinition storeDef = ServerTestUtils.getStoreDef("test", 3, 3, 3, 2, 2, RoutingStrategyType.CONSISTENT_STRATEGY);
    Map<Integer, Store<ByteArray, byte[], byte[]>> subStores = Maps.newHashMap();
    for (int a = 0; a < 3; a++) {
        int id = Iterables.get(cluster.getNodes(), a).getId();
        InMemoryStorageEngine<ByteArray, byte[], byte[]> subStore = new InMemoryStorageEngine<ByteArray, byte[], byte[]>("test");
        subStores.put(id, subStore);
    }
    FailureDetectorConfig failureDetectorConfig = new FailureDetectorConfig().setImplementationClassName(failureDetectorClass.getName()).setBannagePeriod(1000).setCluster(cluster).setConnectionVerifier(create(subStores)).setTime(time);
    failureDetector = create(failureDetectorConfig, false);
    routedStoreThreadPool = Executors.newFixedThreadPool(1);
    RoutedStoreFactory routedStoreFactory = new RoutedStoreFactory(routedStoreThreadPool);
    RoutedStore store = routedStoreFactory.create(cluster, storeDef, subStores, failureDetector, new RoutedStoreConfig().setTimeoutConfig(new TimeoutConfig(1000L, false)));
    recordException(failureDetector, Iterables.get(cluster.getNodes(), 0));
    store.put(key, new Versioned<byte[]>(value), null);
    recordSuccess(failureDetector, Iterables.get(cluster.getNodes(), 0));
    time.sleep(2000);
    assertEquals(2, store.get(key, null).size());
    // Last get should have repaired the missing key from node 0 so all
    // stores should now return a value
    assertEquals(3, store.get(key, null).size());
    ByteArray anotherKey = TestUtils.toByteArray("anotherKey");
    // Try again, now use getAll to read repair
    recordException(failureDetector, Iterables.get(cluster.getNodes(), 0));
    store.put(anotherKey, new Versioned<byte[]>(value), null);
    recordSuccess(failureDetector, Iterables.get(cluster.getNodes(), 0));
    assertEquals(2, store.getAll(Arrays.asList(anotherKey), null).get(anotherKey).size());
    assertEquals(3, store.get(anotherKey, null).size());
}
Also used : TimeoutConfig(voldemort.client.TimeoutConfig) Cluster(voldemort.cluster.Cluster) Store(voldemort.store.Store) InMemoryStorageEngine(voldemort.store.memory.InMemoryStorageEngine) StoreDefinition(voldemort.store.StoreDefinition) FailureDetectorConfig(voldemort.cluster.failuredetector.FailureDetectorConfig) ByteArray(voldemort.utils.ByteArray) Test(org.junit.Test)

Example 9 with TimeoutConfig

use of voldemort.client.TimeoutConfig in project voldemort by voldemort.

the class RoutedStoreTest method testOperationSpecificTimeouts.

@Test
public void testOperationSpecificTimeouts() throws Exception {
    StoreDefinition definition = new StoreDefinitionBuilder().setName("test").setType("foo").setKeySerializer(new SerializerDefinition("test")).setValueSerializer(new SerializerDefinition("test")).setRoutingPolicy(RoutingTier.CLIENT).setRoutingStrategyType(RoutingStrategyType.CONSISTENT_STRATEGY).setReplicationFactor(3).setPreferredReads(3).setRequiredReads(3).setPreferredWrites(3).setRequiredWrites(3).build();
    Map<Integer, Store<ByteArray, byte[], byte[]>> stores = new HashMap<Integer, Store<ByteArray, byte[], byte[]>>();
    List<Node> nodes = new ArrayList<Node>();
    for (int i = 0; i < 3; i++) {
        Store<ByteArray, byte[], byte[]> store = new SleepyStore<ByteArray, byte[], byte[]>(200, 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, partitions));
    }
    setFailureDetector(stores);
    routedStoreThreadPool = Executors.newFixedThreadPool(3);
    // with a 500ms general timeout and a 100ms get timeout, only get should
    // fail
    TimeoutConfig timeoutConfig = new TimeoutConfig(1500, false);
    timeoutConfig.setOperationTimeout(VoldemortOpCode.GET_OP_CODE, 100);
    RoutedStoreFactory routedStoreFactory = createFactory();
    RoutedStore routedStore = routedStoreFactory.create(new Cluster("test", nodes), definition, stores, failureDetector, createConfig(timeoutConfig));
    try {
        routedStore.put(new ByteArray("test".getBytes()), new Versioned<byte[]>(new byte[] { 1 }), null);
    } catch (InsufficientOperationalNodesException e) {
        fail("Should not have failed");
    }
    try {
        routedStore.get(new ByteArray("test".getBytes()), null);
        fail("Should have thrown");
    } catch (InsufficientOperationalNodesException e) {
    }
}
Also used : StoreDefinitionBuilder(voldemort.store.StoreDefinitionBuilder) TimeoutConfig(voldemort.client.TimeoutConfig) 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) VoldemortTestConstants.getNineNodeCluster(voldemort.VoldemortTestConstants.getNineNodeCluster) Cluster(voldemort.cluster.Cluster) SleepyStore(voldemort.store.SleepyStore) StoreDefinition(voldemort.store.StoreDefinition) InsufficientOperationalNodesException(voldemort.store.InsufficientOperationalNodesException) ByteArray(voldemort.utils.ByteArray) SerializerDefinition(voldemort.serialization.SerializerDefinition) AbstractByteArrayStoreTest(voldemort.store.AbstractByteArrayStoreTest) Test(org.junit.Test)

Aggregations

TimeoutConfig (voldemort.client.TimeoutConfig)9 ByteArray (voldemort.utils.ByteArray)6 Node (voldemort.cluster.Node)5 Store (voldemort.store.Store)5 StoreDefinition (voldemort.store.StoreDefinition)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 Test (org.junit.Test)4 Cluster (voldemort.cluster.Cluster)4 List (java.util.List)3 VoldemortTestConstants.getNineNodeCluster (voldemort.VoldemortTestConstants.getNineNodeCluster)3 SerializerDefinition (voldemort.serialization.SerializerDefinition)3 AbstractByteArrayStoreTest (voldemort.store.AbstractByteArrayStoreTest)3 FailingReadsStore (voldemort.store.FailingReadsStore)3 FailingStore (voldemort.store.FailingStore)3 InsufficientOperationalNodesException (voldemort.store.InsufficientOperationalNodesException)3 SleepyStore (voldemort.store.SleepyStore)3 StoreDefinitionBuilder (voldemort.store.StoreDefinitionBuilder)3 UnreachableStoreException (voldemort.store.UnreachableStoreException)3 StatTrackingStore (voldemort.store.stats.StatTrackingStore)3