use of voldemort.client.SocketStoreClientFactory in project voldemort by voldemort.
the class ClientExample method avroStoreExample.
public static void avroStoreExample() {
System.out.println("==============Avro store example=================");
// In production environment, the StoreClient instantiation should be done using factory pattern
// through a Framework such as Spring
String bootstrapUrl = "tcp://localhost:6666";
StoreClientFactory factory = new SocketStoreClientFactory(new ClientConfig().setBootstrapUrls(bootstrapUrl));
StoreClient<GenericRecord, GenericRecord> client = factory.getStoreClient("avro-example");
// creating initial k-v pair
System.out.println("Creating initial Key and Value");
String keySchemaJson = "{ \"name\": \"key\", \"type\": \"record\", \"fields\": [{ \"name\": \"user_id\", \"type\": \"int\" }] }";
Schema keySchema = Schema.parse(keySchemaJson);
GenericRecord key = new GenericData.Record(keySchema);
key.put("user_id", 123);
String valueSchemaJson = "{\n" + " \"name\": \"value\",\n" + " \"type\": \"record\",\n" + " \"fields\": [{ \n" + " \"name\": \"user_id\",\n" + " \"type\": \"int\"\n" + " }, {\n" + " \"name\": \"gender\",\n" + " \"type\": \"string\"\n" + " }, {\n" + " \"name\": \"age\",\n" + " \"type\": \"int\",\n" + " \"optional\": true\n" + " }]\n" + " }";
Schema valueSchema = Schema.parse(valueSchemaJson);
GenericRecord value = new GenericData.Record(valueSchema);
value.put("user_id", 123);
value.put("gender", "male");
value.put("age", 23);
// put initial value
System.out.println("Putting Initial value");
client.put(key, value);
// get the value
System.out.println("Getting the value");
Versioned<GenericRecord> versioned = client.get(key);
System.out.println("Initial Versioned Object: " + String.valueOf(versioned));
System.out.println(" Initial Value: " + String.valueOf(versioned.getValue()));
// modify the value
System.out.println("Modifying the value");
GenericRecord modifiedRecord = versioned.getValue();
modifiedRecord.put("gender", "female");
modifiedRecord.put("age", 55);
versioned.setObject(modifiedRecord);
// update the value
System.out.println("Putting the new value");
client.put(key, versioned);
// get again and print
System.out.println("Getting the new value");
versioned = client.get(key);
System.out.println(" New Versioned Object: " + String.valueOf(versioned));
System.out.println(" New Value: " + String.valueOf(versioned.getValue()));
}
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);
}
}
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);
}
use of voldemort.client.SocketStoreClientFactory in project voldemort by voldemort.
the class SystemStoreTest method setUp.
@Before
public void setUp() throws Exception {
servers = new VoldemortServer[cluster.getNodeIds().size()];
int i = 0;
for (Integer nodeId : cluster.getNodeIds()) {
VoldemortConfig config = ServerTestUtils.createServerConfigWithDefs(true, nodeId, TestUtils.createTempDir().getAbsolutePath(), cluster, storeDefs, new Properties());
VoldemortServer server = ServerTestUtils.startVoldemortServer(socketStoreFactory, config);
servers[i++] = server;
}
socketUrl = servers[0].getIdentityNode().getSocketUrl().toString();
ClientConfig clientConfig = new ClientConfig().setMaxTotalConnections(4).setMaxConnectionsPerNode(4).setBootstrapUrls(socketUrl);
SocketStoreClientFactory socketFactory = new SocketStoreClientFactory(clientConfig);
bootStrapUrls = new String[1];
bootStrapUrls[0] = socketUrl;
clusterXml = ((AbstractStoreClientFactory) socketFactory).bootstrapMetadataWithRetries(MetadataStore.CLUSTER_KEY);
}
use of voldemort.client.SocketStoreClientFactory in project voldemort by voldemort.
the class ChainedInconsistencyResolverTest method setUp.
@Before
public void setUp() throws IOException {
boolean useNio = false;
int numServers = 2;
VoldemortServer[] servers = new VoldemortServer[numServers];
Cluster cluster = ServerTestUtils.startVoldemortCluster(numServers, servers, null, socketStoreFactory, useNio, null, STORES_XML, new Properties());
// Initialize versioned puts for basic test
v1 = getVersioned(0, 1, 1, 1, 1, 1);
v2 = getVersioned(0, 0, 1, 1, 1, 1);
// Initialize versioned puts for > 1 conflicts
conflict1 = getVersioned(0, 1, 1, 1, 1, 1, 1, 1, 1, 1);
conflict2 = getVersioned(0, 0, 1, 1, 1, 1, 1, 1, 1, 1);
conflict3 = getVersioned(0, 0, 0, 1, 1, 1, 1, 1, 1, 1);
conflict4 = getVersioned(0, 0, 0, 0, 1, 1, 1, 1, 1, 1);
conflict5 = getVersioned(0, 0, 0, 0, 0, 1, 1, 1, 1, 1);
conflict6 = getVersioned(0, 0, 0, 0, 0, 0, 1, 1, 1, 1);
Node node = cluster.getNodes().iterator().next();
String bootstrapUrl = "tcp://" + node.getHost() + ":" + node.getSocketPort();
StoreClientFactory storeClientFactory = new SocketStoreClientFactory(new ClientConfig().setBootstrapUrls(bootstrapUrl));
defaultStoreClient = storeClientFactory.getStoreClient("test");
socketStore = ServerTestUtils.getSocketStore(socketStoreFactory, "test", node.getSocketPort(), RequestFormatType.VOLDEMORT_V1);
}
Aggregations