Search in sources :

Example 1 with SocketStoreClientFactory

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

the class ZoneCountWriteTest method setup.

@Before
public void setup() throws IOException {
    storeDef = storeDefs.get(0);
    Integer zoneCountWrite = 1;
    // override
    storeDef = new StoreDefinition(storeDef.getName(), storeDef.getType(), storeDef.getDescription(), storeDef.getKeySerializer(), storeDef.getValueSerializer(), storeDef.getTransformsSerializer(), storeDef.getRoutingPolicy(), storeDef.getRoutingStrategyType(), storeDef.getReplicationFactor(), storeDef.getPreferredReads(), storeDef.getRequiredReads(), storeDef.getPreferredWrites(), storeDef.getRequiredWrites(), storeDef.getViewTargetStoreName(), storeDef.getValueTransformation(), storeDef.getZoneReplicationFactor(), storeDef.getZoneCountReads(), zoneCountWrite, storeDef.getRetentionDays(), storeDef.getRetentionScanThrottleRate(), storeDef.getRetentionFrequencyDays(), storeDef.getSerializerFactory(), storeDef.getHintedHandoffStrategyType(), storeDef.getHintPrefListSize(), storeDef.getOwners(), storeDef.getMemoryFootprintMB());
    storeDefs.set(0, storeDef);
    SocketStoreClientFactory socketStoreClientFactory = new SocketStoreClientFactory(clientConfig);
    for (Integer nodeId : cluster.getNodeIds()) {
        SocketStoreFactory socketStoreFactory = new ClientRequestExecutorPool(2, 10000, 100000, 1024);
        VoldemortConfig config = ServerTestUtils.createServerConfigWithDefs(true, nodeId, TestUtils.createTempDir().getAbsolutePath(), cluster, storeDefs, new Properties());
        VoldemortServer vs = ServerTestUtils.startVoldemortServer(socketStoreFactory, config, cluster);
        vservers.put(nodeId, vs);
    }
    client = socketStoreClientFactory.getRawStore(storeDef.getName(), null);
}
Also used : ClientRequestExecutorPool(voldemort.store.socket.clientrequest.ClientRequestExecutorPool) SocketStoreClientFactory(voldemort.client.SocketStoreClientFactory) StoreDefinition(voldemort.store.StoreDefinition) SocketStoreFactory(voldemort.store.socket.SocketStoreFactory) Properties(java.util.Properties) VoldemortServer(voldemort.server.VoldemortServer) VoldemortConfig(voldemort.server.VoldemortConfig) Before(org.junit.Before)

Example 2 with SocketStoreClientFactory

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

the class RebootstrappingStoreTest method setUp.

@Before
public void setUp() throws Exception {
    SocketStoreFactory socketStoreFactory = new ClientRequestExecutorPool(2, 10000, 100000, 32 * 1024);
    int numServers = 2;
    VoldemortServer[] voldemortServers = new VoldemortServer[numServers];
    int[][] partitionMap = { { 0, 1 }, {} };
    cluster = ServerTestUtils.startVoldemortCluster(numServers, voldemortServers, partitionMap, socketStoreFactory, false, null, STORES_XML, new Properties());
    servers = Lists.newArrayList();
    for (int i = 0; i < numServers; ++i) {
        servers.add(voldemortServers[i]);
    }
    String bootstrapUrl = cluster.getNodeById(0).getSocketUrl().toString();
    storeClient = new SocketStoreClientFactory(new ClientConfig().setBootstrapUrls(bootstrapUrl)).getStoreClient(STORE_NAME);
    Map<String, String> entries = Maps.newHashMap();
    entries.put("a", "1");
    entries.put("b", "2");
    for (Map.Entry<String, String> entry : entries.entrySet()) storeClient.put(entry.getKey(), entry.getValue());
}
Also used : SocketStoreFactory(voldemort.store.socket.SocketStoreFactory) VoldemortServer(voldemort.server.VoldemortServer) Properties(java.util.Properties) ClientRequestExecutorPool(voldemort.store.socket.clientrequest.ClientRequestExecutorPool) SocketStoreClientFactory(voldemort.client.SocketStoreClientFactory) ClientConfig(voldemort.client.ClientConfig) Map(java.util.Map) Before(org.junit.Before)

Example 3 with SocketStoreClientFactory

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

the class RedirectingStoreTest method setUp.

@Before
public void setUp() throws IOException, InterruptedException {
    currentCluster = ServerTestUtils.getLocalCluster(3, new int[][] { { 0, 1 }, { 2, 3 }, {} });
    targetCluster = UpdateClusterUtils.createUpdatedCluster(currentCluster, 2, Arrays.asList(0));
    this.primaryPartitionsMoved = Lists.newArrayList(0);
    this.secondaryPartitionsMoved = Lists.newArrayList(2, 3);
    this.storeDef = new StoreDefinitionBuilder().setName("test").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();
    File tempStoreXml = new File(TestUtils.createTempDir(), "stores.xml");
    FileUtils.writeStringToFile(tempStoreXml, new StoreDefinitionsMapper().writeStoreList(Lists.newArrayList(storeDef)));
    this.servers = new VoldemortServer[3];
    for (int nodeId = 0; nodeId < 3; nodeId++) {
        this.servers[nodeId] = startServer(nodeId, tempStoreXml.getAbsolutePath(), currentCluster);
    }
    // Start another node for only this unit test
    HashMap<ByteArray, byte[]> entrySet = ServerTestUtils.createRandomKeyValuePairs(100);
    SocketStoreClientFactory factory = new SocketStoreClientFactory(new ClientConfig().setBootstrapUrls(Lists.newArrayList("tcp://" + currentCluster.getNodeById(0).getHost() + ":" + currentCluster.getNodeById(0).getSocketPort())));
    StoreClient<Object, Object> storeClient = factory.getStoreClient("test");
    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());
        }
    }
    // Sleep a while for the queries to go through...
    // Hope the 'God of perfect timing' is on our side
    Thread.sleep(500);
    // steal a few primary key-value pairs for testing proxy put logic
    int cnt = 0;
    for (Entry<ByteArray, byte[]> entry : primaryEntriesMoved.entrySet()) {
        if (cnt > 3)
            break;
        this.proxyPutTestPrimaryEntries.put(entry.getKey(), entry.getValue());
        cnt++;
    }
    for (ByteArray key : this.proxyPutTestPrimaryEntries.keySet()) {
        this.primaryEntriesMoved.remove(key);
    }
    assertTrue("Not enough primary entries", primaryEntriesMoved.size() > 1);
    // steal a few secondary key-value pairs for testing proxy put logic
    cnt = 0;
    for (Entry<ByteArray, byte[]> entry : secondaryEntriesMoved.entrySet()) {
        if (cnt > 3)
            break;
        this.proxyPutTestSecondaryEntries.put(entry.getKey(), entry.getValue());
        cnt++;
    }
    for (ByteArray key : this.proxyPutTestSecondaryEntries.keySet()) {
        this.secondaryEntriesMoved.remove(key);
    }
    assertTrue("Not enough secondary entries", primaryEntriesMoved.size() > 1);
    RebalanceBatchPlan RebalanceBatchPlan = new RebalanceBatchPlan(currentCluster, targetCluster, Lists.newArrayList(storeDef));
    List<RebalanceTaskInfo> plans = Lists.newArrayList(RebalanceBatchPlan.getBatchPlan());
    // Set into rebalancing state
    for (RebalanceTaskInfo partitionPlan : plans) {
        servers[partitionPlan.getStealerId()].getMetadataStore().put(MetadataStore.SERVER_STATE_KEY, MetadataStore.VoldemortState.REBALANCING_MASTER_SERVER);
        servers[partitionPlan.getStealerId()].getMetadataStore().put(MetadataStore.REBALANCING_STEAL_INFO, new RebalancerState(Lists.newArrayList(partitionPlan)));
        servers[partitionPlan.getStealerId()].getMetadataStore().put(MetadataStore.REBALANCING_SOURCE_CLUSTER_XML, currentCluster);
        // update original storedefs
        servers[partitionPlan.getStealerId()].getMetadataStore().put(MetadataStore.REBALANCING_SOURCE_STORES_XML, Lists.newArrayList(storeDef));
    }
    // Update the cluster metadata on all three nodes
    for (VoldemortServer server : servers) {
        server.getMetadataStore().put(MetadataStore.CLUSTER_KEY, targetCluster);
    }
}
Also used : StoreDefinitionBuilder(voldemort.store.StoreDefinitionBuilder) RoutingStrategyFactory(voldemort.routing.RoutingStrategyFactory) StoreDefinitionsMapper(voldemort.xml.StoreDefinitionsMapper) VoldemortServer(voldemort.server.VoldemortServer) RebalanceBatchPlan(voldemort.client.rebalance.RebalanceBatchPlan) SocketStoreClientFactory(voldemort.client.SocketStoreClientFactory) RoutingStrategy(voldemort.routing.RoutingStrategy) ByteArray(voldemort.utils.ByteArray) RebalancerState(voldemort.server.rebalance.RebalancerState) ClientConfig(voldemort.client.ClientConfig) File(java.io.File) SerializerDefinition(voldemort.serialization.SerializerDefinition) RebalanceTaskInfo(voldemort.client.rebalance.RebalanceTaskInfo) Before(org.junit.Before)

Example 4 with SocketStoreClientFactory

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

the class CoordinatorProxyService method initializeFatClient.

/**
 * Initialize the fat client for the given store.
 *
 * 1. Updates the coordinatorMetadata 2.Gets the new store configs from the
 * config file 3.Creates a new @SocketStoreClientFactory 4. Subsequently
 * caches the @StoreClient obtained from the factory.
 *
 * This is synchronized because if Coordinator Admin is already doing some
 * change we want the AsyncMetadataVersionManager to wait.
 *
 * @param storeName
 */
private synchronized void initializeFatClient(String storeName, Properties storeClientProps) {
    // updates the coordinator metadata with recent stores and cluster xml
    updateCoordinatorMetadataWithLatestState();
    logger.info("Creating a Fat client for store: " + storeName);
    SocketStoreClientFactory fatClientFactory = getFatClientFactory(this.coordinatorConfig.getBootstrapURLs(), storeClientProps);
    if (this.fatClientMap == null) {
        this.fatClientMap = new HashMap<String, DynamicTimeoutStoreClient<ByteArray, byte[]>>();
    }
    DynamicTimeoutStoreClient<ByteArray, byte[]> fatClient = new DynamicTimeoutStoreClient<ByteArray, byte[]>(storeName, fatClientFactory, 1, this.coordinatorMetadata.getStoreDefs(), this.coordinatorMetadata.getClusterXmlStr());
    this.fatClientMap.put(storeName, fatClient);
}
Also used : SocketStoreClientFactory(voldemort.client.SocketStoreClientFactory) ByteArray(voldemort.utils.ByteArray)

Example 5 with SocketStoreClientFactory

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

the class CoordinatorProxyService method getFatClientFactory.

/**
 * Create a @SocketStoreClientFactory from the given configPops
 *
 * @param bootstrapURLs
 * @param configProps
 * @return
 */
private SocketStoreClientFactory getFatClientFactory(String[] bootstrapURLs, Properties configProps) {
    ClientConfig fatClientConfig = new ClientConfig(configProps);
    logger.info("Using config: " + fatClientConfig);
    fatClientConfig.setBootstrapUrls(bootstrapURLs).setEnableCompressionLayer(false).setEnableSerializationLayer(false).enableDefaultClient(true).setEnableLazy(false);
    return new SocketStoreClientFactory(fatClientConfig);
}
Also used : SocketStoreClientFactory(voldemort.client.SocketStoreClientFactory) ClientConfig(voldemort.client.ClientConfig)

Aggregations

SocketStoreClientFactory (voldemort.client.SocketStoreClientFactory)40 ClientConfig (voldemort.client.ClientConfig)37 IOException (java.io.IOException)14 VoldemortServer (voldemort.server.VoldemortServer)14 ByteArray (voldemort.utils.ByteArray)13 Properties (java.util.Properties)12 Before (org.junit.Before)12 Test (org.junit.Test)12 ArrayList (java.util.ArrayList)9 StoreClientFactory (voldemort.client.StoreClientFactory)9 Cluster (voldemort.cluster.Cluster)8 HashMap (java.util.HashMap)7 ExecutorService (java.util.concurrent.ExecutorService)7 Node (voldemort.cluster.Node)7 List (java.util.List)6 CountDownLatch (java.util.concurrent.CountDownLatch)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 ClusterTestUtils (voldemort.ClusterTestUtils)6 DefaultStoreClient (voldemort.client.DefaultStoreClient)6 InvalidMetadataException (voldemort.store.InvalidMetadataException)6