use of voldemort.cluster.Cluster in project voldemort by voldemort.
the class RoutedStoreTest method testGetAndPutTimeoutZZZ.
@Test
public void testGetAndPutTimeoutZZZ() throws Exception {
int timeout = 50;
// Set replication factors for a 3 zone cluster
HashMap<Integer, Integer> zoneReplicationFactor = Maps.newHashMap();
zoneReplicationFactor.put(0, 1);
zoneReplicationFactor.put(1, 1);
zoneReplicationFactor.put(2, 1);
// Create a store with RF=3, Required reads = 3 and zone count reads = 2
// This ensures that a GET operation requires a response from all 3
// nodes (from the respective 3 zones)
StoreDefinition definition = new StoreDefinitionBuilder().setName("test").setType("foo").setKeySerializer(new SerializerDefinition("test")).setValueSerializer(new SerializerDefinition("test")).setRoutingPolicy(RoutingTier.CLIENT).setRoutingStrategyType(RoutingStrategyType.ZONE_STRATEGY).setHintedHandoffStrategy(HintedHandoffStrategyType.PROXIMITY_STRATEGY).setReplicationFactor(3).setPreferredReads(3).setRequiredReads(3).setPreferredWrites(3).setRequiredWrites(3).setZoneCountReads(2).setZoneCountWrites(2).setZoneReplicationFactor(zoneReplicationFactor).build();
Map<Integer, Store<ByteArray, byte[], byte[]>> stores = new HashMap<Integer, Store<ByteArray, byte[], byte[]>>();
List<Node> nodes = new ArrayList<Node>();
int totalDelay = 0;
for (int i = 0; i < 3; i++) {
int delay = 4 + i * timeout;
totalDelay += delay;
Store<ByteArray, byte[], byte[]> store = new SleepyStore<ByteArray, byte[], byte[]>(delay, 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, i, partitions));
}
setFailureDetector(stores);
routedStoreThreadPool = Executors.newFixedThreadPool(3);
RoutedStoreFactory routedStoreFactory = createFactory();
List<Zone> zones = Lists.newArrayList();
for (int i = 0; i < 3; i++) {
LinkedList<Integer> zoneProximityList = Lists.newLinkedList();
Set<Integer> zoneIds = Sets.newHashSet(0, 1, 2);
zoneIds.remove(i);
zoneProximityList.addAll(zoneIds);
zones.add(new Zone(i, zoneProximityList));
}
RoutedStore routedStore = routedStoreFactory.create(new Cluster("test", nodes, zones), definition, stores, failureDetector, createConfig(timeout));
long start = System.nanoTime();
try {
routedStore.get(new ByteArray("test".getBytes()), null);
fail("Should have thrown");
} catch (InsufficientOperationalNodesException e) {
long elapsed = (System.nanoTime() - start) / Time.NS_PER_MS;
assertTrue(elapsed + " < " + totalDelay, elapsed < totalDelay);
}
start = System.nanoTime();
try {
routedStore.put(new ByteArray("test".getBytes()), new Versioned<byte[]>(new byte[] { 1 }), null);
fail("Should have thrown");
} catch (InsufficientOperationalNodesException e) {
long elapsed = (System.nanoTime() - start) / Time.NS_PER_MS;
assertTrue(elapsed + " < " + totalDelay, elapsed < totalDelay);
}
}
use of voldemort.cluster.Cluster in project voldemort by voldemort.
the class ConfigureNodesLocalHostTest method testConfigureNodesLocalHost.
/*
* Checks to see that the local host is obtained as the first node in the
* list returned by ConfigureNodesLocalHost
*/
@Test
public void testConfigureNodesLocalHost() throws Exception {
List<Node> nodes = getTestNodes();
Cluster cluster = new Cluster("test-route-all-local-pref-cluster", nodes);
FailureDetector failureDetector = new ThresholdFailureDetector(new FailureDetectorConfig().setCluster(cluster));
RoutingStrategy routingStrategy = new RouteToAllLocalPrefStrategy(cluster.getNodesShuffled());
BasicPipelineData<byte[]> pipelineData = new BasicPipelineData<byte[]>();
ConfigureNodesLocalHost<byte[], BasicPipelineData<byte[]>> action = new ConfigureNodesLocalHost<byte[], BasicPipelineData<byte[]>>(pipelineData, Event.COMPLETED, failureDetector, 1, routingStrategy, aKey);
Pipeline pipeline = new Pipeline(Operation.GET, 10000, TimeUnit.MILLISECONDS);
pipeline.addEventAction(Event.STARTED, action);
pipeline.addEvent(Event.STARTED);
pipeline.execute();
if (pipelineData.getFatalError() != null)
throw pipelineData.getFatalError();
assertEquals(cluster.getNodes().size(), pipelineData.getNodes().size());
assertEquals(cluster.getNodesShuffled().size(), pipelineData.getNodes().size());
assertEquals(pipelineData.getNodes().get(0).getHost(), currentHost);
}
use of voldemort.cluster.Cluster in project voldemort by voldemort.
the class MetaOperationsTest method testMetaGet.
@Test
public void testMetaGet() throws Exception {
Integer nodeId = 0;
String tempDir = System.getProperty("java.io.tmpdir") + "temp" + System.currentTimeMillis();
// get metadata and write to files
AdminCommand.executeCommand(new String[] { "meta", "get", MetadataStore.CLUSTER_KEY + "," + MetadataStore.STORES_KEY, "-u", bsURL, "-n", nodeId.toString(), "-d", tempDir });
// load metadata files
String clusterFile = tempDir + "/" + MetadataStore.CLUSTER_KEY + "_" + nodeId;
String storesFile = tempDir + "/" + MetadataStore.STORES_KEY + "_" + nodeId;
assertTrue(Utils.isReadableFile(clusterFile));
assertTrue(Utils.isReadableFile(storesFile));
ClusterMapper clusterMapper = new ClusterMapper();
StoreDefinitionsMapper storeDefsMapper = new StoreDefinitionsMapper();
Cluster newCluster = clusterMapper.readCluster(new File(clusterFile));
List<StoreDefinition> newStores = storeDefsMapper.readStoreList(new File(storesFile));
// compare metadata objects
assertTrue(newCluster.equals(cluster));
assertTrue(newStores.size() == stores.size());
for (StoreDefinition store : stores) {
assertTrue(newStores.contains(store));
}
}
use of voldemort.cluster.Cluster in project voldemort by voldemort.
the class RepartitionerTest method verifyBalanceZoneAndNode.
/**
* Verify balancing of partitions among zones, and within each zone, among
* nodes.
*
* @param currentCluster
* @param currentStores
* @param interimCluster
* @param finalStores
*/
public void verifyBalanceZoneAndNode(Cluster currentCluster, List<StoreDefinition> currentStores, Cluster interimCluster, List<StoreDefinition> finalStores) {
// Confirm current cluster is imbalanced on all fronts:
assertFalse(verifyNodesBalancedInEachZone(currentCluster));
assertFalse(verifyZonesBalanced(currentCluster));
// Repartition to balance partition IDs among zones and among nodes
// within zone.
boolean disableNodeBalancing = false;
boolean disableZoneBalancing = false;
Cluster repartitionedCluster = Repartitioner.repartition(currentCluster, currentStores, interimCluster, finalStores, null, 1, disableNodeBalancing, disableZoneBalancing, false, 0, 0, Collections.<Integer>emptyList(), false, 0, 0, 0, Collections.<Integer>emptyList(), 0);
assertTrue(verifyNodesBalancedInEachZone(repartitionedCluster));
assertTrue(verifyZonesBalanced(repartitionedCluster));
}
use of voldemort.cluster.Cluster in project voldemort by voldemort.
the class RepartitionerTest method verifyRandomSwapsImproveBalance.
/**
* Verify that random swaps improve balance.
*
* @param currentCluster
* @param currentStores
*/
public void verifyRandomSwapsImproveBalance(Cluster currentCluster, List<StoreDefinition> currentStores) {
// Confirm current cluster is imbalanced on all fronts:
assertFalse(verifyNodesBalancedInEachZone(currentCluster));
assertFalse(verifyZonesBalanced(currentCluster));
PartitionBalance currentPb = new PartitionBalance(currentCluster, currentStores);
// Disable basic balancing among zones & nodes
boolean disableNodeBalancing = true;
boolean disableZoneBalancing = true;
// Do some random swaps!
boolean enableRandomSwaps = true;
int swapAttempts = 100;
int swapSuccesses = 1;
Cluster repartitionedCluster = Repartitioner.repartition(currentCluster, currentStores, currentCluster, currentStores, null, 1, disableNodeBalancing, disableZoneBalancing, enableRandomSwaps, swapAttempts, swapSuccesses, Collections.<Integer>emptyList(), false, 0, 0, 0, Collections.<Integer>emptyList(), 0);
// Confirm repartitioned cluster is still imbalanced on all fronts
assertFalse(verifyNodesBalancedInEachZone(repartitionedCluster));
assertFalse(verifyZonesBalanced(repartitionedCluster));
// Confirm overall balance has been improved
PartitionBalance repartitionedPb = new PartitionBalance(repartitionedCluster, currentStores);
assertTrue(repartitionedPb.getUtility() < currentPb.getUtility());
}
Aggregations