use of voldemort.store.StoreDefinitionBuilder in project voldemort by voldemort.
the class StoreSwapperTest method constructStoresXml.
protected String constructStoresXml() throws IOException {
StoreDefinition storeDef = new StoreDefinitionBuilder().setName(STORE_NAME).setType(ReadOnlyStorageConfiguration.TYPE_NAME).setKeySerializer(serializerDef).setValueSerializer(serializerDef).setRoutingPolicy(RoutingTier.SERVER).setRoutingStrategyType(RoutingStrategyType.CONSISTENT_STRATEGY).setReplicationFactor(2).setPreferredReads(1).setRequiredReads(1).setPreferredWrites(1).setRequiredWrites(1).build();
File storesXml = new File(TestUtils.createTempDir(), "stores.xml");
StoreDefinitionsMapper storeDefMapper = new StoreDefinitionsMapper();
FileWriter writer = new FileWriter(storesXml);
writer.write(storeDefMapper.writeStoreList(Lists.newArrayList(storeDef)));
writer.close();
return storesXml.getAbsolutePath();
}
use of voldemort.store.StoreDefinitionBuilder 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.store.StoreDefinitionBuilder in project voldemort by voldemort.
the class GetallNodeReachTest method testGetall_211_zoneCountRead_1.
@Test
public void testGetall_211_zoneCountRead_1() throws Exception {
cluster = getFourNodeClusterWithZones();
HashMap<Integer, Integer> zoneReplicationFactor = new HashMap<Integer, Integer>();
zoneReplicationFactor.put(0, 2);
zoneReplicationFactor.put(1, 1);
zoneReplicationFactor.put(2, 1);
/*
* First n nodes on the preference list will be one node from each
* remote n zones, where n=zoneCountReads, therefore preferred read
* should be set > n if want to include local zone node results in
* parallel request
*/
storeDef = new StoreDefinitionBuilder().setName("test").setType(InMemoryStorageConfiguration.TYPE_NAME).setRoutingPolicy(RoutingTier.CLIENT).setRoutingStrategyType(RoutingStrategyType.ZONE_STRATEGY).setReplicationFactor(4).setZoneReplicationFactor(zoneReplicationFactor).setKeySerializer(new SerializerDefinition("string")).setValueSerializer(new SerializerDefinition("string")).setPreferredReads(2).setRequiredReads(1).setPreferredWrites(1).setRequiredWrites(1).setZoneCountReads(1).setZoneCountWrites(0).build();
makeStore();
Versioned<byte[]> v = Versioned.value("v".getBytes());
subStores.get(0).put(TestUtils.toByteArray("k001"), v, null);
subStores.get(0).put(TestUtils.toByteArray("k011"), v, null);
subStores.get(0).put(TestUtils.toByteArray("k101"), v, null);
subStores.get(0).put(TestUtils.toByteArray("k111"), v, null);
subStores.get(1).put(TestUtils.toByteArray("k010"), v, null);
subStores.get(1).put(TestUtils.toByteArray("k011"), v, null);
subStores.get(1).put(TestUtils.toByteArray("k110"), v, null);
subStores.get(1).put(TestUtils.toByteArray("k111"), v, null);
subStores.get(2).put(TestUtils.toByteArray("k100"), v, null);
subStores.get(2).put(TestUtils.toByteArray("k101"), v, null);
subStores.get(2).put(TestUtils.toByteArray("k110"), v, null);
subStores.get(2).put(TestUtils.toByteArray("k111"), v, null);
/* test multiple keys getall */
List<ByteArray> keys = new ArrayList<ByteArray>();
keys.add(TestUtils.toByteArray("k000"));
keys.add(TestUtils.toByteArray("k001"));
keys.add(TestUtils.toByteArray("k010"));
keys.add(TestUtils.toByteArray("k011"));
keys.add(TestUtils.toByteArray("k100"));
keys.add(TestUtils.toByteArray("k101"));
keys.add(TestUtils.toByteArray("k110"));
keys.add(TestUtils.toByteArray("k111"));
Map<ByteArray, List<Versioned<byte[]>>> result = store.getAll(keys, null);
assertFalse(result.containsKey(TestUtils.toByteArray("not_included")));
/* client will first try all the nodes in local zone */
assertFalse(result.containsKey(TestUtils.toByteArray("k000")));
assertEquals(1, result.get(TestUtils.toByteArray("k011")).size());
assertFalse(result.containsKey(TestUtils.toByteArray("not_included")));
assertFalse(result.containsKey(TestUtils.toByteArray("k000")));
assertEquals(1, result.get(TestUtils.toByteArray("k011")).size());
assertEquals(1, result.get(TestUtils.toByteArray("k100")).size());
assertEquals(2, result.get(TestUtils.toByteArray("k111")).size());
}
use of voldemort.store.StoreDefinitionBuilder in project voldemort by voldemort.
the class GetallNodeReachTest method testGetall_211.
@Test
public void testGetall_211() throws Exception {
cluster = getFourNodeClusterWithZones();
HashMap<Integer, Integer> zoneReplicationFactor = new HashMap<Integer, Integer>();
zoneReplicationFactor.put(0, 2);
zoneReplicationFactor.put(1, 1);
zoneReplicationFactor.put(2, 1);
storeDef = new StoreDefinitionBuilder().setName("test").setType(InMemoryStorageConfiguration.TYPE_NAME).setRoutingPolicy(RoutingTier.CLIENT).setRoutingStrategyType(RoutingStrategyType.ZONE_STRATEGY).setReplicationFactor(4).setZoneReplicationFactor(zoneReplicationFactor).setKeySerializer(new SerializerDefinition("string")).setValueSerializer(new SerializerDefinition("string")).setPreferredReads(1).setRequiredReads(1).setPreferredWrites(1).setRequiredWrites(1).setZoneCountReads(0).setZoneCountWrites(0).build();
makeStore();
Versioned<byte[]> v = Versioned.value("v".getBytes());
// k### indicates existence of itself in different nodes
// k**1 means this key exists at least on node 0
// k*1* means this key exists at least on node 1
// k0** means this key does not exist on node 2
subStores.get(0).put(TestUtils.toByteArray("k001"), v, null);
subStores.get(0).put(TestUtils.toByteArray("k011"), v, null);
subStores.get(0).put(TestUtils.toByteArray("k101"), v, null);
subStores.get(0).put(TestUtils.toByteArray("k111"), v, null);
subStores.get(1).put(TestUtils.toByteArray("k010"), v, null);
subStores.get(1).put(TestUtils.toByteArray("k011"), v, null);
subStores.get(1).put(TestUtils.toByteArray("k110"), v, null);
subStores.get(1).put(TestUtils.toByteArray("k111"), v, null);
subStores.get(2).put(TestUtils.toByteArray("k100"), v, null);
subStores.get(2).put(TestUtils.toByteArray("k101"), v, null);
subStores.get(2).put(TestUtils.toByteArray("k110"), v, null);
subStores.get(2).put(TestUtils.toByteArray("k111"), v, null);
/* test multiple keys getall */
List<ByteArray> keys = new ArrayList<ByteArray>();
keys.add(TestUtils.toByteArray("k000"));
keys.add(TestUtils.toByteArray("k001"));
keys.add(TestUtils.toByteArray("k010"));
keys.add(TestUtils.toByteArray("k011"));
keys.add(TestUtils.toByteArray("k100"));
keys.add(TestUtils.toByteArray("k101"));
keys.add(TestUtils.toByteArray("k110"));
keys.add(TestUtils.toByteArray("k111"));
Map<ByteArray, List<Versioned<byte[]>>> result = store.getAll(keys, null);
assertFalse(result.containsKey(TestUtils.toByteArray("not_included")));
assertFalse(result.containsKey(TestUtils.toByteArray("k000")));
assertEquals(1, result.get(TestUtils.toByteArray("k011")).size());
assertFalse(result.containsKey(TestUtils.toByteArray("k100")));
assertEquals(1, result.get(TestUtils.toByteArray("k111")).size());
}
use of voldemort.store.StoreDefinitionBuilder in project voldemort by voldemort.
the class GetallNodeReachTest method testGetallTouchOneZone.
@Test
public void testGetallTouchOneZone() throws Exception {
cluster = getFourNodeClusterWithZones();
HashMap<Integer, Integer> zoneReplicationFactor = new HashMap<Integer, Integer>();
zoneReplicationFactor.put(0, 2);
zoneReplicationFactor.put(1, 1);
zoneReplicationFactor.put(2, 1);
storeDef = new StoreDefinitionBuilder().setName("test").setType(InMemoryStorageConfiguration.TYPE_NAME).setRoutingPolicy(RoutingTier.CLIENT).setRoutingStrategyType(RoutingStrategyType.ZONE_STRATEGY).setReplicationFactor(4).setZoneReplicationFactor(zoneReplicationFactor).setKeySerializer(new SerializerDefinition("string")).setValueSerializer(new SerializerDefinition("string")).setPreferredReads(2).setRequiredReads(1).setPreferredWrites(1).setRequiredWrites(1).setZoneCountReads(0).setZoneCountWrites(0).build();
makeStore();
Versioned<byte[]> v = Versioned.value("v".getBytes());
subStores.get(0).put(TestUtils.toByteArray("k011_zone0_only"), v, null);
subStores.get(1).put(TestUtils.toByteArray("k011_zone0_only"), v, null);
subStores.get(2).put(TestUtils.toByteArray("k100_zone1_only"), v, null);
/* test single key getall */
List<ByteArray> keys011 = new ArrayList<ByteArray>();
keys011.add(TestUtils.toByteArray("k011_zone0_only"));
List<ByteArray> keys100 = new ArrayList<ByteArray>();
keys100.add(TestUtils.toByteArray("k100_zone1_only"));
assertEquals(2, store.getAll(keys011, null).get(TestUtils.toByteArray("k011_zone0_only")).size());
assertFalse(store.getAll(keys100, null).containsKey(TestUtils.toByteArray("k100_zone1_only")));
/* test multiple keys getall */
List<ByteArray> keys = new ArrayList<ByteArray>();
keys.add(TestUtils.toByteArray("k011_zone0_only"));
keys.add(TestUtils.toByteArray("k100_zone1_only"));
Map<ByteArray, List<Versioned<byte[]>>> result = store.getAll(keys, null);
assertEquals(2, result.get(TestUtils.toByteArray("k011_zone0_only")).size());
assertFalse(result.containsKey(TestUtils.toByteArray("k100_zone1_only")));
}
Aggregations