Search in sources :

Example 1 with InMemoryStorageEngine

use of voldemort.store.memory.InMemoryStorageEngine in project voldemort by voldemort.

the class MetadataStore method createInMemoryMetadataStore.

public static MetadataStore createInMemoryMetadataStore(Store<String, String, String> innerStore, int nodeId) {
    StorageEngine<String, String, String> storesRepo = new InMemoryStorageEngine<String, String, String>("stores-repo");
    List<Versioned<String>> versionedStoreList = innerStore.get(STORES_KEY, "");
    if (versionedStoreList != null && versionedStoreList.size() > 0) {
        String stores = versionedStoreList.get(0).getValue();
        StoreDefinitionsMapper mapper = new StoreDefinitionsMapper();
        List<StoreDefinition> storeDefinitions = mapper.readStoreList(new StringReader(stores));
        for (StoreDefinition storeDef : storeDefinitions) {
            Versioned<String> versionedStoreValue = new Versioned<String>(mapper.writeStore(storeDef));
            storesRepo.put(storeDef.getName(), versionedStoreValue, null);
        }
    }
    MetadataStore store = new MetadataStore(innerStore, storesRepo);
    store.initNodeId(nodeId);
    return store;
}
Also used : InMemoryStorageEngine(voldemort.store.memory.InMemoryStorageEngine) Versioned(voldemort.versioning.Versioned) StoreDefinition(voldemort.store.StoreDefinition) StoreDefinitionsMapper(voldemort.xml.StoreDefinitionsMapper) StringReader(java.io.StringReader)

Example 2 with InMemoryStorageEngine

use of voldemort.store.memory.InMemoryStorageEngine in project voldemort by voldemort.

the class RoutedStoreParallelismTest method main.

public static void main(String[] args) throws Throwable {
    OptionParser parser = new OptionParser();
    parser.accepts("num-keys", "The number of keys to submit for retrieval  Default = " + DEFAULT_NUM_KEYS).withRequiredArg().ofType(Integer.class);
    parser.accepts("max-connections", "The maximum number of connections (sockets) per node; same value as client configuration parameter \"" + ClientConfig.MAX_CONNECTIONS_PER_NODE_PROPERTY + "\"  Default = " + DEFAULT_MAX_CONNECTIONS).withRequiredArg().ofType(Integer.class);
    parser.accepts("max-threads", "The maximum number of threads used by the threaded RoutedStore implementation; same value as client configuration parameter \"" + ClientConfig.MAX_THREADS_PROPERTY + "\"  Default = " + DEFAULT_MAX_THREADS).withRequiredArg().ofType(Integer.class);
    parser.accepts("num-nodes", "The number of nodes  Default = " + DEFAULT_NUM_NODES).withRequiredArg().ofType(Integer.class);
    parser.accepts("num-slow-nodes", "The number of nodes that exhibit delay Default = " + DEFAULT_NUM_SLOW_NODES).withRequiredArg().ofType(Integer.class);
    parser.accepts("delay", "The millisecond delay shown by slow nodes Default = " + DEFAULT_DELAY).withRequiredArg().ofType(Integer.class);
    parser.accepts("num-clients", "The number of threads to make requests concurrently  Default = " + DEFAULT_NUM_CLIENTS).withRequiredArg().ofType(Integer.class);
    parser.accepts("routed-store-type", "Type of routed store, either \"" + THREAD_POOL_ROUTED_STORE + "\" or \"" + PIPELINE_ROUTED_STORE + "\"  Default = " + DEFAULT_ROUTED_STORE_TYPE).withRequiredArg();
    parser.accepts("help", "This help");
    OptionSet options = parser.parse(args);
    if (options.has("help")) {
        printUsage(System.out, parser);
    }
    final int numKeys = CmdUtils.valueOf(options, "num-keys", DEFAULT_NUM_KEYS);
    int maxConnectionsPerNode = CmdUtils.valueOf(options, "max-connections", DEFAULT_MAX_CONNECTIONS);
    int maxThreads = CmdUtils.valueOf(options, "max-threads", DEFAULT_MAX_THREADS);
    int numNodes = CmdUtils.valueOf(options, "num-nodes", DEFAULT_NUM_NODES);
    int numSlowNodes = CmdUtils.valueOf(options, "num-slow-nodes", DEFAULT_NUM_SLOW_NODES);
    int delay = CmdUtils.valueOf(options, "delay", DEFAULT_DELAY);
    int numClients = CmdUtils.valueOf(options, "num-clients", DEFAULT_NUM_CLIENTS);
    System.err.println("num-keys : " + numKeys);
    System.err.println("max-connections : " + maxConnectionsPerNode);
    System.err.println("max-threads : " + maxThreads);
    System.err.println("num-nodes : " + numNodes);
    System.err.println("num-slow-nodes : " + numSlowNodes);
    System.err.println("delay : " + delay);
    System.err.println("num-clients : " + numClients);
    ClientConfig clientConfig = new ClientConfig().setMaxConnectionsPerNode(maxConnectionsPerNode).setMaxThreads(maxThreads);
    String storeDefinitionFile = "test/common/voldemort/config/single-store.xml";
    StoreDefinition storeDefinition = new StoreDefinitionsMapper().readStoreList(new File(storeDefinitionFile)).get(0);
    SocketStoreFactory socketStoreFactory = new ClientRequestExecutorPool(clientConfig.getSelectors(), clientConfig.getMaxConnectionsPerNode(), clientConfig.getConnectionTimeout(TimeUnit.MILLISECONDS), clientConfig.getSocketTimeout(TimeUnit.MILLISECONDS), clientConfig.getSocketBufferSize(), clientConfig.getSocketKeepAlive());
    VoldemortServer[] servers = new VoldemortServer[numNodes];
    int[][] partitionMap = new int[numNodes][1];
    for (int i = 0; i < numNodes; i++) {
        partitionMap[i][0] = i;
    }
    Cluster cluster = ServerTestUtils.startVoldemortCluster(numNodes, servers, partitionMap, socketStoreFactory, true, null, storeDefinitionFile, new Properties());
    Map<Integer, VoldemortServer> serverMap = new HashMap<Integer, VoldemortServer>();
    for (int i = 0; i < cluster.getNumberOfNodes(); i++) {
        serverMap.put(i, servers[i]);
        Store<ByteArray, byte[], byte[]> store = new InMemoryStorageEngine<ByteArray, byte[], byte[]>("test-sleepy");
        if (i < numSlowNodes)
            store = new SleepyStore<ByteArray, byte[], byte[]>(delay, store);
        StoreRepository storeRepository = servers[i].getStoreRepository();
        storeRepository.addLocalStore(store);
    }
    Map<Integer, Store<ByteArray, byte[], byte[]>> stores = new HashMap<Integer, Store<ByteArray, byte[], byte[]>>();
    for (Node node : cluster.getNodes()) {
        Store<ByteArray, byte[], byte[]> socketStore = ServerTestUtils.getSocketStore(socketStoreFactory, "test-sleepy", node.getSocketPort(), clientConfig.getRequestFormatType());
        stores.put(node.getId(), socketStore);
    }
    FailureDetectorConfig failureDetectorConfig = new FailureDetectorConfig().setImplementationClassName(BannagePeriodFailureDetector.class.getName()).setCluster(cluster).setConnectionVerifier(MutableStoreConnectionVerifier.create(stores));
    FailureDetector failureDetector = FailureDetectorUtils.create(failureDetectorConfig, false);
    ExecutorService routedStoreThreadPool = Executors.newFixedThreadPool(clientConfig.getMaxThreads());
    RoutedStoreFactory routedStoreFactory = new RoutedStoreFactory(routedStoreThreadPool);
    RoutedStoreConfig routedStoreConfig = new RoutedStoreConfig(clientConfig);
    final RoutedStore routedStore = routedStoreFactory.create(cluster, storeDefinition, stores, failureDetector, routedStoreConfig);
    ExecutorService runner = Executors.newFixedThreadPool(numClients);
    long start = System.nanoTime();
    try {
        for (int i = 0; i < numClients; i++) {
            runner.submit(new Runnable() {

                public void run() {
                    for (int i = 0; i < numKeys; i++) {
                        ByteArray key = new ByteArray(("test-key-" + i).getBytes());
                        try {
                            routedStore.get(key, null);
                        } catch (VoldemortException e) {
                        //
                        }
                    }
                }
            });
        }
        runner.shutdown();
        runner.awaitTermination(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
        long time = (System.nanoTime() - start) / Time.NS_PER_MS;
        System.err.println("Time: " + time + " ms.");
    } finally {
        runner.shutdown();
    }
    if (failureDetector != null)
        failureDetector.destroy();
    for (VoldemortServer server : serverMap.values()) server.stop();
    if (routedStoreThreadPool != null)
        routedStoreThreadPool.shutdown();
    System.exit(0);
}
Also used : HashMap(java.util.HashMap) Node(voldemort.cluster.Node) RoutedStoreFactory(voldemort.store.routed.RoutedStoreFactory) RoutedStore(voldemort.store.routed.RoutedStore) Store(voldemort.store.Store) SleepyStore(voldemort.store.SleepyStore) StoreRepository(voldemort.server.StoreRepository) VoldemortServer(voldemort.server.VoldemortServer) Properties(java.util.Properties) OptionParser(joptsimple.OptionParser) VoldemortException(voldemort.VoldemortException) InMemoryStorageEngine(voldemort.store.memory.InMemoryStorageEngine) StoreDefinition(voldemort.store.StoreDefinition) BannagePeriodFailureDetector(voldemort.cluster.failuredetector.BannagePeriodFailureDetector) FailureDetector(voldemort.cluster.failuredetector.FailureDetector) ByteArray(voldemort.utils.ByteArray) ClientConfig(voldemort.client.ClientConfig) BannagePeriodFailureDetector(voldemort.cluster.failuredetector.BannagePeriodFailureDetector) StoreDefinitionsMapper(voldemort.xml.StoreDefinitionsMapper) Cluster(voldemort.cluster.Cluster) SocketStoreFactory(voldemort.store.socket.SocketStoreFactory) SleepyStore(voldemort.store.SleepyStore) RoutedStore(voldemort.store.routed.RoutedStore) ClientRequestExecutorPool(voldemort.store.socket.clientrequest.ClientRequestExecutorPool) RoutedStoreConfig(voldemort.store.routed.RoutedStoreConfig) FailureDetectorConfig(voldemort.cluster.failuredetector.FailureDetectorConfig) ExecutorService(java.util.concurrent.ExecutorService) OptionSet(joptsimple.OptionSet) File(java.io.File)

Example 3 with InMemoryStorageEngine

use of voldemort.store.memory.InMemoryStorageEngine in project voldemort by voldemort.

the class RebalanceMetadataConsistencyTest method setUp.

@Before
public void setUp() {
    currentCluster = ServerTestUtils.getLocalCluster(3, new int[][] { { 0 }, { 1, 3 }, { 2 } });
    finalCluster = ServerTestUtils.getLocalCluster(3, new int[][] { { 0 }, { 1 }, { 2 }, { 3 } });
    rwStoreDefWithReplication = new StoreDefinitionBuilder().setName(testStoreNameRW).setType(BdbStorageConfiguration.TYPE_NAME).setKeySerializer(new SerializerDefinition("string")).setValueSerializer(new SerializerDefinition("string")).setRoutingPolicy(RoutingTier.CLIENT).setRoutingStrategyType(RoutingStrategyType.CONSISTENT_STRATEGY).setReplicationFactor(2).setPreferredReads(1).setRequiredReads(1).setPreferredWrites(1).setRequiredWrites(1).build();
    Store<String, String, String> innerStore = new InMemoryStorageEngine<String, String, String>("inner-store");
    innerStore.put(MetadataStore.CLUSTER_KEY, new Versioned<String>(new ClusterMapper().writeCluster(currentCluster)), null);
    innerStore.put(MetadataStore.STORES_KEY, new Versioned<String>(new StoreDefinitionsMapper().writeStoreList(Lists.newArrayList(rwStoreDefWithReplication))), null);
    rwStoreDefWithReplication2 = new StoreDefinitionBuilder().setName(testStoreNameRW2).setType(BdbStorageConfiguration.TYPE_NAME).setKeySerializer(new SerializerDefinition("string")).setValueSerializer(new SerializerDefinition("string")).setRoutingPolicy(RoutingTier.CLIENT).setRoutingStrategyType(RoutingStrategyType.CONSISTENT_STRATEGY).setReplicationFactor(2).setPreferredReads(1).setRequiredReads(1).setPreferredWrites(1).setRequiredWrites(1).build();
    metadataStore = MetadataStore.createInMemoryMetadataStore(innerStore, 0);
    rebalancer = new Rebalancer(null, metadataStore, null, null);
}
Also used : StoreDefinitionBuilder(voldemort.store.StoreDefinitionBuilder) Rebalancer(voldemort.server.rebalance.Rebalancer) InMemoryStorageEngine(voldemort.store.memory.InMemoryStorageEngine) StoreDefinitionsMapper(voldemort.xml.StoreDefinitionsMapper) ClusterMapper(voldemort.xml.ClusterMapper) SerializerDefinition(voldemort.serialization.SerializerDefinition) Before(org.junit.Before)

Example 4 with InMemoryStorageEngine

use of voldemort.store.memory.InMemoryStorageEngine in project voldemort by voldemort.

the class ServerTestUtils method getStores.

public static StoreRepository getStores(String storeName, String clusterXml, String storesXml) {
    StoreRepository repository = new StoreRepository();
    Store<ByteArray, byte[], byte[]> store = new InMemoryStorageEngine<ByteArray, byte[], byte[]>(storeName);
    repository.addLocalStore(store);
    repository.addRoutedStore(store);
    // create new metadata store.
    MetadataStore metadata = createMetadataStore(new ClusterMapper().readCluster(new StringReader(clusterXml)), new StoreDefinitionsMapper().readStoreList(new StringReader(storesXml)));
    repository.addLocalStore(metadata);
    return repository;
}
Also used : MetadataStore(voldemort.store.metadata.MetadataStore) InMemoryStorageEngine(voldemort.store.memory.InMemoryStorageEngine) StringReader(java.io.StringReader) StoreDefinitionsMapper(voldemort.xml.StoreDefinitionsMapper) ByteArray(voldemort.utils.ByteArray) StoreRepository(voldemort.server.StoreRepository) ClusterMapper(voldemort.xml.ClusterMapper)

Example 5 with InMemoryStorageEngine

use of voldemort.store.memory.InMemoryStorageEngine in project voldemort by voldemort.

the class ServerTestUtils method createMetadataStore.

public static MetadataStore createMetadataStore(Cluster cluster, List<StoreDefinition> storeDefs) {
    Store<String, String, String> innerStore = new InMemoryStorageEngine<String, String, String>("inner-store");
    innerStore.put(MetadataStore.CLUSTER_KEY, new Versioned<String>(new ClusterMapper().writeCluster(cluster)), null);
    innerStore.put(MetadataStore.STORES_KEY, new Versioned<String>(new StoreDefinitionsMapper().writeStoreList(storeDefs)), null);
    return MetadataStore.createInMemoryMetadataStore(innerStore, 0);
}
Also used : InMemoryStorageEngine(voldemort.store.memory.InMemoryStorageEngine) StoreDefinitionsMapper(voldemort.xml.StoreDefinitionsMapper) ClusterMapper(voldemort.xml.ClusterMapper)

Aggregations

InMemoryStorageEngine (voldemort.store.memory.InMemoryStorageEngine)23 ByteArray (voldemort.utils.ByteArray)16 Store (voldemort.store.Store)12 StoreDefinition (voldemort.store.StoreDefinition)10 Node (voldemort.cluster.Node)9 SleepyStore (voldemort.store.SleepyStore)9 InconsistencyResolvingStore (voldemort.store.versioned.InconsistencyResolvingStore)9 StatTrackingStore (voldemort.store.stats.StatTrackingStore)8 Test (org.junit.Test)7 FailingReadsStore (voldemort.store.FailingReadsStore)7 FailingStore (voldemort.store.FailingStore)7 StoreRepository (voldemort.server.StoreRepository)6 Versioned (voldemort.versioning.Versioned)6 StoreDefinitionsMapper (voldemort.xml.StoreDefinitionsMapper)6 Cluster (voldemort.cluster.Cluster)4 AbstractByteArrayStoreTest (voldemort.store.AbstractByteArrayStoreTest)4 ClusterMapper (voldemort.xml.ClusterMapper)4 StringReader (java.io.StringReader)3 Before (org.junit.Before)3 File (java.io.File)2