use of voldemort.versioning.Versioned in project voldemort by voldemort.
the class RoutedStoreTest method testBasicOperations.
private void testBasicOperations(int reads, int writes, int failures, int threads, RoutedStore customRoutedStore, long customSleepTime) throws Exception {
RoutedStore routedStore = null;
if (customRoutedStore == null) {
routedStore = getStore(cluster, reads, writes, threads, failures);
} else {
routedStore = customRoutedStore;
}
Store<ByteArray, byte[], byte[]> store = new InconsistencyResolvingStore<ByteArray, byte[], byte[]>(routedStore, new VectorClockInconsistencyResolver<byte[]>());
VectorClock clock = getClock(1);
Versioned<byte[]> versioned = new Versioned<byte[]>(aValue, clock);
routedStore.put(aKey, versioned, aTransform);
waitForOperationToComplete(customSleepTime);
assertNOrMoreEqual(routedStore, cluster.getNumberOfNodes() - failures, aKey, versioned);
List<Versioned<byte[]>> found = store.get(aKey, aTransform);
assertEquals(1, found.size());
assertEquals(versioned, found.get(0));
waitForOperationToComplete(customSleepTime);
assertNOrMoreEqual(routedStore, cluster.getNumberOfNodes() - failures, aKey, versioned);
assertTrue(routedStore.delete(aKey, versioned.getVersion()));
waitForOperationToComplete(customSleepTime);
assertNEqual(routedStore, 0, aKey, versioned);
assertTrue(!routedStore.delete(aKey, versioned.getVersion()));
}
use of voldemort.versioning.Versioned in project voldemort by voldemort.
the class RocksdbStorageEngineAPITest method generatePutWithConflictionVersions.
public List<Versioned<byte[]>> generatePutWithConflictionVersions(ByteArray key) {
List<Versioned<byte[]>> versionedList = new ArrayList<Versioned<byte[]>>();
VectorClock vectorClock1 = new VectorClock();
vectorClock1.incrementVersion(voldemortConfig.getNodeId(), System.currentTimeMillis());
Versioned<byte[]> value1 = new Versioned<byte[]>("valueOne".getBytes(), vectorClock1);
try {
// Do put
this.rocksDbStore.put(key, value1, null);
} catch (PersistenceFailureException pfe) {
Assert.fail("initial put failed unexpectedly. Exception: " + pfe.getMessage());
}
versionedList.add(value1);
VectorClock vectorClock2 = new VectorClock();
vectorClock2.incrementVersion(1, System.currentTimeMillis());
Versioned<byte[]> value2 = new Versioned<byte[]>("valueTwo".getBytes(), vectorClock2);
try {
// Do put
this.rocksDbStore.put(key, value2, null);
} catch (PersistenceFailureException pfe) {
Assert.fail("initial put failed unexpectedly. Exception: " + pfe.getMessage());
}
versionedList.add(value2);
return versionedList;
}
use of voldemort.versioning.Versioned in project voldemort by voldemort.
the class RocksdbStorageEngineAPITest method testVersionedDelete.
@Test
public void testVersionedDelete() {
logger.info("*********** testing versioned delete ***********");
ByteArray key = new ByteArray("keyOne".getBytes());
List<Versioned<byte[]>> conflictingVersions = generatePutWithConflictionVersions(key);
if (conflictingVersions.size() == 0) {
Assert.fail("Could not generate conflicting versions ");
}
testDelete(key, conflictingVersions.get(0).getVersion());
}
use of voldemort.versioning.Versioned in project voldemort by voldemort.
the class SetMetadataTest method testSetMetadataStoreXmlVerifyVersionUpdate.
@Test
public void testSetMetadataStoreXmlVerifyVersionUpdate() throws Exception {
// setup new stores xml
final String newStoreXMLFilePrefix = "updated.stores";
final String newStoreXMLFileSuffix = "xml";
List<StoreDefinition> newStores = new ArrayList<StoreDefinition>();
for (StoreDefinition storeDef : ClusterTestUtils.getZZZStoreDefsInMemory()) {
StoreDefinitionBuilder sb = storeDefToBuilder(storeDef);
Map<Integer, Integer> zrf = sb.getZoneReplicationFactor();
Integer zone0RepFactor = zrf.get(0);
zrf.remove(0);
sb.setReplicationFactor(sb.getReplicationFactor() - zone0RepFactor);
newStores.add(sb.build());
}
File newStoresXMLFolder = TestUtils.createTempDir();
File newStoreXMLFile = File.createTempFile(newStoreXMLFilePrefix, newStoreXMLFileSuffix, newStoresXMLFolder);
FileWriter fwriter = new FileWriter(newStoreXMLFile);
fwriter.write(new StoreDefinitionsMapper().writeStoreList(newStores));
fwriter.close();
// check version
String sysStoreName = SystemStoreConstants.SystemStoreName.voldsys$_metadata_version_persistence.name();
ByteArray metadataKey = new ByteArray(ByteUtils.getBytes(SystemStoreConstants.VERSIONS_METADATA_KEY, "utf-8"));
for (VoldemortServer vs : vservers.values()) {
List<Versioned<byte[]>> result = vs.getStoreRepository().getLocalStore(sysStoreName).get(metadataKey, null);
String versionInfo = new String(result.get(0).getValue());
System.out.format("[INITIAL]Version values on node [%d] is: \n %s\n", vs.getIdentityNode().getId(), versionInfo);
Properties props = new Properties();
props.load(new ByteArrayInputStream(versionInfo.getBytes()));
for (StoreDefinition sd : oldStores) {
if (!props.getProperty(sd.getName()).equals("0")) {
Assert.fail("Initial version of key [" + sd.getName() + "] on node [" + vs.getIdentityNode().getId() + "] is expected to be 0 but not");
}
}
if (!props.getProperty("cluster.xml").equals("0")) {
Assert.fail("Final version of key [stores.xml] on node [" + vs.getIdentityNode().getId() + "] is expected to greater than 0 but not");
}
}
// update the stores xml
VoldemortAdminTool.main(new String[] { "--auto", "--set-metadata", MetadataStore.STORES_KEY, "--set-metadata-value", newStoreXMLFile.getAbsolutePath(), "--url", bsURL });
// properly
try {
Thread.sleep(10000);
} catch (Exception e) {
}
// check version
for (VoldemortServer vs : vservers.values()) {
List<Versioned<byte[]>> result = vs.getStoreRepository().getLocalStore(sysStoreName).get(metadataKey, null);
String versionInfo = new String(result.get(0).getValue());
System.out.format("[FINAL]Version values on node [%d] is: \n %s\n", vs.getIdentityNode().getId(), versionInfo);
Properties props = new Properties();
props.load(new ByteArrayInputStream(versionInfo.getBytes()));
for (StoreDefinition sd : oldStores) {
if (!(Long.parseLong(props.getProperty(sd.getName())) > 0)) {
Assert.fail("Final version of key [" + sd.getName() + "] on node [" + vs.getIdentityNode().getId() + "] is expected to greater than 0 but not");
}
}
if (!(Long.parseLong(props.getProperty("stores.xml")) > 0)) {
Assert.fail("Final version of key [stores.xml] on node [" + vs.getIdentityNode().getId() + "] is expected to greater than 0 but not");
}
}
}
use of voldemort.versioning.Versioned in project voldemort by voldemort.
the class AbstractSocketStoreTest method testVeryLargeValues.
@Test
public void testVeryLargeValues() throws Exception {
final Store<ByteArray, byte[], byte[]> store = getStore();
byte[] biggie = new byte[1 * 1024 * 1024];
ByteArray key = new ByteArray(biggie);
Random rand = new Random();
for (int i = 0; i < 10; i++) {
rand.nextBytes(biggie);
Versioned<byte[]> versioned = new Versioned<byte[]>(biggie);
store.put(key, versioned, null);
Versioned<byte[]> result = store.get(key, null).get(0);
assertArrayEquals("Get returned different value after put", result.getValue(), versioned.getValue());
assertTrue(store.delete(key, versioned.getVersion()));
}
}
Aggregations