use of voldemort.versioning.Version in project voldemort by voldemort.
the class RoutedStoreTest method testReadRepairWithFailuresZZZ.
/**
* Test to ensure that read repair happens correctly across zones in case of
* inconsistent writes in a 3 zone cluster.
*
* @throws Exception
*/
@Test
public void testReadRepairWithFailuresZZZ() throws Exception {
cluster = VoldemortTestConstants.getSixNodeClusterWith3Zones();
HashMap<Integer, Integer> zoneReplicationFactor = Maps.newHashMap();
zoneReplicationFactor.put(0, cluster.getNumberOfNodesInZone(0));
zoneReplicationFactor.put(1, cluster.getNumberOfNodesInZone(0));
zoneReplicationFactor.put(2, cluster.getNumberOfNodesInZone(0));
// PR = RR = 6
// PW = RW = 4
// Zone Reads = # Zones - 1
// Zone Writes = 1
// Threads = 1
RoutedStore routedStore = getStore(cluster, 6, 4, cluster.getNumberOfZones() - 1, 1, 1, zoneReplicationFactor);
Store<ByteArray, byte[], byte[]> store = new InconsistencyResolvingStore<ByteArray, byte[], byte[]>(routedStore, new VectorClockInconsistencyResolver<byte[]>());
BaseStoreRoutingPlan routingPlan = new BaseStoreRoutingPlan(cluster, this.storeDef);
List<Integer> replicatingNodes = routingPlan.getReplicationNodeList(aKey.get());
try {
// Do the initial put with all nodes up
store.put(aKey, new Versioned<byte[]>(aValue), null);
List<Version> initialVersions = store.getVersions(aKey);
assertEquals(6, initialVersions.size());
Version mainVersion = initialVersions.get(0);
for (int i = 1; i < initialVersions.size(); i++) {
assertEquals(mainVersion, initialVersions.get(i));
}
// Do another put with all nodes in the zone 0 marked as
// unavailable. This will force the put to use a different pseudo
// master than before.
byte[] anotherValue = "john".getBytes();
// In this cluster, nodes 0 and 1 are in Zone 0. Mark them
// unavailable
recordException(failureDetector, cluster.getNodeById(0));
recordException(failureDetector, cluster.getNodeById(1));
Version newVersion = ((VectorClock) mainVersion).clone();
store.put(aKey, new Versioned<byte[]>(anotherValue, newVersion), null);
waitForOperationToComplete(500);
// Mark the nodes in Zone 0 as available and do a get. The Required
// reads = 4 and Zone count reads = 2 will force the client to read
// from all the zones and do the essential read repairs.
recordSuccess(failureDetector, cluster.getNodeById(0));
recordSuccess(failureDetector, cluster.getNodeById(1));
List<Versioned<byte[]>> versioneds = store.get(aKey, null);
assertEquals(1, versioneds.size());
assertEquals(new ByteArray(anotherValue), new ByteArray(versioneds.get(0).getValue()));
// Read repairs are done asynchronously, so we sleep for a short
// period. It may be a good idea to use a synchronous executor
// service.
Thread.sleep(500);
for (Map.Entry<Integer, Store<ByteArray, byte[], byte[]>> innerStoreEntry : routedStore.getInnerStores().entrySet()) {
// Only look at the nodes in the pref list
if (replicatingNodes.contains(innerStoreEntry.getKey())) {
List<Versioned<byte[]>> innerVersioneds = innerStoreEntry.getValue().get(aKey, null);
assertEquals(1, versioneds.size());
assertEquals(new ByteArray(anotherValue), new ByteArray(innerVersioneds.get(0).getValue()));
}
}
} catch (VoldemortException ve) {
fail("Unexpected error occurred : " + ve);
}
}
use of voldemort.versioning.Version in project voldemort by voldemort.
the class RoutedStoreTest method testZoneRouting.
@Test
public void testZoneRouting() throws Exception {
cluster = VoldemortTestConstants.getEightNodeClusterWithZones();
HashMap<Integer, Integer> zoneReplicationFactor = Maps.newHashMap();
zoneReplicationFactor.put(0, 2);
zoneReplicationFactor.put(1, 2);
long start;
Versioned<byte[]> versioned = new Versioned<byte[]>(new byte[] { 1 });
// Basic put with zone read = 0, zone write = 0 and timeout < cross-zone
// latency
Store<ByteArray, byte[], byte[]> s1 = getStore(cluster, 1, 1, 0, 0, 8, null, Sets.newHashSet(4, 5, 6, 7), zoneReplicationFactor, RoutingStrategyType.ZONE_STRATEGY, SLEEPY_TIME, OPERATION_TIMEOUT, new VoldemortException());
start = System.nanoTime();
try {
s1.put(new ByteArray("test".getBytes()), versioned, null);
} finally {
long elapsed = (System.nanoTime() - start) / Time.NS_PER_MS;
assertTrue(elapsed + " < " + SLEEPY_TIME, elapsed < SLEEPY_TIME);
}
// Putting extra key to test getAll
s1.put(new ByteArray("test2".getBytes()), versioned, null);
start = System.nanoTime();
try {
s1.get(new ByteArray("test".getBytes()), null);
} finally {
long elapsed = (System.nanoTime() - start) / Time.NS_PER_MS;
assertTrue(elapsed + " < " + SLEEPY_TIME, elapsed < SLEEPY_TIME);
}
start = System.nanoTime();
try {
List<Version> versions = s1.getVersions(new ByteArray("test".getBytes()));
for (Version version : versions) {
assertEquals(version.compare(versioned.getVersion()), Occurred.BEFORE);
}
} finally {
long elapsed = (System.nanoTime() - start) / Time.NS_PER_MS;
assertTrue(elapsed + " < " + SLEEPY_TIME, elapsed < SLEEPY_TIME);
}
start = System.nanoTime();
try {
s1.delete(new ByteArray("test".getBytes()), versioned.getVersion());
} finally {
long elapsed = (System.nanoTime() - start) / Time.NS_PER_MS;
assertTrue(elapsed + " < " + SLEEPY_TIME, elapsed < SLEEPY_TIME);
}
// make sure sleepy stores processed the delete before checking,
// otherwise, we might be bailing
// out of the test too early for the delete to be processed.
Thread.sleep(SLEEPY_TIME * 2);
List<ByteArray> keys = Lists.newArrayList(new ByteArray("test".getBytes()), new ByteArray("test2".getBytes()));
Map<ByteArray, List<Versioned<byte[]>>> values = s1.getAll(keys, null);
assertFalse("'test' did not get deleted.", values.containsKey(new ByteArray("test".getBytes())));
ByteUtils.compare(values.get(new ByteArray("test2".getBytes())).get(0).getValue(), new byte[] { 1 });
// Basic put with zone read = 1, zone write = 1
Store<ByteArray, byte[], byte[]> s2 = getStore(cluster, 1, 1, 1, 1, 8, null, Sets.newHashSet(4, 5, 6, 7), zoneReplicationFactor, RoutingStrategyType.ZONE_STRATEGY, SLEEPY_TIME, BANNAGE_PERIOD, new VoldemortException());
start = System.nanoTime();
try {
s2.put(new ByteArray("test".getBytes()), versioned, null);
} finally {
long elapsed = (System.nanoTime() - start) / Time.NS_PER_MS;
assertTrue(elapsed + " > " + SLEEPY_TIME, elapsed >= SLEEPY_TIME);
}
s2.put(new ByteArray("test2".getBytes()), versioned, null);
try {
s2.get(new ByteArray("test".getBytes()), null);
fail("Should have shown exception");
} catch (InsufficientZoneResponsesException e) {
/*
* Why would you want responses from two zones and wait for only one
* response...
*/
}
try {
s2.getVersions(new ByteArray("test".getBytes()));
fail("Should have shown exception");
} catch (InsufficientZoneResponsesException e) {
/*
* Why would you want responses from two zones and wait for only one
* response...
*/
}
try {
s2.delete(new ByteArray("test".getBytes()), null);
} catch (InsufficientZoneResponsesException e) {
/*
* Why would you want responses from two zones and wait for only one
* response...
*/
}
values = s2.getAll(keys, null);
assertFalse("'test' did not get deleted.", values.containsKey(new ByteArray("test".getBytes())));
ByteUtils.compare(values.get(new ByteArray("test2".getBytes())).get(0).getValue(), new byte[] { 1 });
// Basic put with zone read = 0, zone write = 0 and failures in other
// dc, but should still work
Store<ByteArray, byte[], byte[]> s3 = getStore(cluster, 1, 1, 0, 0, 8, Sets.newHashSet(4, 5, 6, 7), null, zoneReplicationFactor, RoutingStrategyType.ZONE_STRATEGY, SLEEPY_TIME, BANNAGE_PERIOD, new VoldemortException());
start = System.nanoTime();
try {
s3.put(new ByteArray("test".getBytes()), versioned, null);
} finally {
long elapsed = (System.nanoTime() - start) / Time.NS_PER_MS;
assertTrue(elapsed + " < " + SLEEPY_TIME, elapsed < SLEEPY_TIME);
}
// Putting extra key to test getAll
s3.put(new ByteArray("test2".getBytes()), versioned, null);
start = System.nanoTime();
try {
List<Version> versions = s3.getVersions(new ByteArray("test".getBytes()));
for (Version version : versions) {
assertEquals(version.compare(versioned.getVersion()), Occurred.BEFORE);
}
} finally {
long elapsed = (System.nanoTime() - start) / Time.NS_PER_MS;
assertTrue(elapsed + " < " + SLEEPY_TIME, elapsed < SLEEPY_TIME);
}
start = System.nanoTime();
try {
s3.get(new ByteArray("test".getBytes()), null);
} finally {
long elapsed = (System.nanoTime() - start) / Time.NS_PER_MS;
assertTrue(elapsed + " < " + SLEEPY_TIME, elapsed < SLEEPY_TIME);
}
start = System.nanoTime();
try {
s3.delete(new ByteArray("test".getBytes()), versioned.getVersion());
} finally {
long elapsed = (System.nanoTime() - start) / Time.NS_PER_MS;
assertTrue(elapsed + " < " + SLEEPY_TIME, elapsed < SLEEPY_TIME);
}
// Basic put with zone read = 1, zone write = 1 and failures in other
// dc, should not work
Store<ByteArray, byte[], byte[]> s4 = getStore(cluster, 2, 2, 1, 1, 8, Sets.newHashSet(4, 5, 6, 7), null, zoneReplicationFactor, RoutingStrategyType.ZONE_STRATEGY, SLEEPY_TIME, BANNAGE_PERIOD, new VoldemortException());
try {
s4.put(new ByteArray("test".getBytes()), new Versioned<byte[]>(new byte[] { 1 }), null);
fail("Should have shown exception");
} catch (InsufficientZoneResponsesException e) {
/*
* The other zone is down and you expect a result from both zones
*/
}
try {
s4.getVersions(new ByteArray("test".getBytes()));
fail("Should have shown exception");
} catch (InsufficientZoneResponsesException e) {
/*
* The other zone is down and you expect a result from both zones
*/
}
try {
s4.get(new ByteArray("test".getBytes()), null);
fail("Should have shown exception");
} catch (InsufficientZoneResponsesException e) {
/*
* The other zone is down and you expect a result from both zones
*/
}
try {
s4.delete(new ByteArray("test".getBytes()), versioned.getVersion());
fail("Should have shown exception");
} catch (InsufficientZoneResponsesException e) {
/*
* The other zone is down and you expect a result from both zones
*/
}
}
use of voldemort.versioning.Version in project voldemort by voldemort.
the class EndToEndTest method testUnversionedPutReturnVersion.
@Test
public void testUnversionedPutReturnVersion() {
Version oldVersion = null;
Version newVersion = null;
Versioned<String> getVersioned = null;
String oldValue = null;
String newValue = null;
for (int i = 0; i < 5; i++) {
oldValue = "value" + i;
newValue = "value" + i + 1;
oldVersion = storeClient.put("key1", oldValue);
newVersion = storeClient.put("key1", newValue);
assertEquals("Version did not advance", Occurred.AFTER, newVersion.compare(oldVersion));
getVersioned = storeClient.get("key1");
verifyResults(oldVersion, newVersion, getVersioned, newValue);
}
}
use of voldemort.versioning.Version in project voldemort by voldemort.
the class EndToEndTest method testPutReturnVersion.
/**
* Test the new put that returns the new version
*/
@Test
public void testPutReturnVersion() {
Version baseVersion = new VectorClock();
Version oldVersion = null;
Version newVersion = null;
Versioned<String> getVersioned = null;
String oldValue = null;
String newValue = null;
for (int i = 0; i < 5; i++) {
oldValue = "value" + i;
newValue = "value" + (i + 1);
oldVersion = storeClient.put("key1", Versioned.value(oldValue, baseVersion));
newVersion = storeClient.put("key1", Versioned.value(newValue, ((VectorClock) oldVersion).clone()));
getVersioned = storeClient.get("key1");
baseVersion = newVersion;
verifyResults(oldVersion, newVersion, getVersioned, newValue);
}
}
use of voldemort.versioning.Version in project voldemort by voldemort.
the class ZenStoreClient method registerClient.
private ClientRegistryRefresher registerClient(int intervalInSecs) {
ClientRegistryRefresher refresher = null;
if (this.sysRepository.getClientRegistryStore() != null) {
try {
Version version = this.sysRepository.getClientRegistryStore().putSysStore(clientId, clientInfo.toString());
refresher = new ClientRegistryRefresher(this.sysRepository, clientId, clientInfo, version);
GregorianCalendar cal = new GregorianCalendar();
cal.add(Calendar.SECOND, intervalInSecs);
if (scheduler != null) {
scheduler.schedule(makeClientRegistryRefresherJobId(), refresher, cal.getTime(), TimeUnit.MILLISECONDS.convert(intervalInSecs, TimeUnit.SECONDS));
logger.info("Client registry refresher thread started, refresh interval: " + intervalInSecs + " seconds");
} else {
logger.warn("Client registry won't run because scheduler service is not configured");
}
} catch (Exception e) {
logger.warn("Unable to register with the cluster due to the following error:", e);
}
} else {
logger.warn(SystemStoreConstants.SystemStoreName.voldsys$_client_registry.name() + "not found. Unable to registry with voldemort cluster.");
}
return refresher;
}
Aggregations