use of voldemort.versioning.Version in project voldemort by voldemort.
the class NodeValueTest method testMultimap.
@Test
public void testMultimap() {
Multimap<Version, NodeValue<ByteArray, byte[]>> multimap = HashMultimap.create();
Version version = createVersion(1, 6);
NodeValue<ByteArray, byte[]> nodeValue = createNodeValue(1, version);
multimap.put(version, nodeValue);
Version version2 = createVersion(1, 7);
NodeValue<ByteArray, byte[]> nodeValue2 = createNodeValue(1, version2);
multimap.put(version2, nodeValue2);
multimap.removeAll(version2);
logger.info(multimap);
assertTrue("Multimap#containsKey() works", multimap.containsKey(version));
assertTrue("Multimap#containsEntry() works", multimap.containsEntry(version, nodeValue));
for (Version v : multimap.keySet()) {
logger.info(v);
assertTrue("Multimap#get(v) returns a non-empty iterator", multimap.get(v).iterator().hasNext());
NodeValue<ByteArray, byte[]> nv = multimap.get(v).iterator().next();
logger.info(nv);
}
}
use of voldemort.versioning.Version in project voldemort by voldemort.
the class ViewStorageEngineTest method testPutWithTransforms.
public void testPutWithTransforms() {
Integer[] values1 = { 9, 90, 10, 15, 25, 106 };
Integer[] filter1 = { 1, 10 };
Versioned<List<Integer>> values = Versioned.value(Arrays.asList(values1));
VectorClock clock = (VectorClock) values.getVersion();
clock.incrementVersion(0, System.currentTimeMillis());
view.put(1, Versioned.value(values.getValue(), clock), Arrays.asList(filter1));
assertEquals(10, view.get(1, Arrays.asList(filter1)).get(0).getValue().size());
Integer[] filter2 = { 5, 10 };
assertEquals(6, view.get(1, Arrays.asList(filter2)).get(0).getValue().size());
Version updatedVersion = view.get(1, Arrays.asList(filter2)).get(0).getVersion();
Integer[] filter3 = { 1, 50 };
Integer[] values2 = { 90, 15, 25, 106 };
clock = (VectorClock) updatedVersion;
VectorClock clock1 = clock.incremented(0, System.currentTimeMillis());
view.put(1, Versioned.value(Arrays.asList(values2), clock1), Arrays.asList(filter3));
assertEquals(12, view.get(1, Arrays.asList(filter3)).get(0).getValue().size());
}
use of voldemort.versioning.Version in project voldemort by voldemort.
the class ConsistencyCheckTest method testDetermineConsistencyHashValue.
@Test
public void testDetermineConsistencyHashValue() {
Map<ConsistencyCheck.Value, Set<ConsistencyCheck.ClusterNode>> versionNodeSetMap = new HashMap<ConsistencyCheck.Value, Set<ConsistencyCheck.ClusterNode>>();
int replicationFactor = 4;
// vector clocks
Version v1 = new VectorClock();
((VectorClock) v1).incrementVersion(1, 100000001);
((VectorClock) v1).incrementVersion(2, 100000003);
Version v2 = new VectorClock();
((VectorClock) v2).incrementVersion(1, 100000001);
((VectorClock) v2).incrementVersion(3, 100000002);
Version v3 = new VectorClock();
((VectorClock) v3).incrementVersion(1, 100000001);
((VectorClock) v3).incrementVersion(4, 100000001);
// Version is HashedValue
Versioned<byte[]> versioned1 = new Versioned<byte[]>(value1, v1);
Versioned<byte[]> versioned2 = new Versioned<byte[]>(value2, v2);
Versioned<byte[]> versioned3 = new Versioned<byte[]>(value3, v3);
ConsistencyCheck.Value hv1 = new ConsistencyCheck.HashedValue(versioned1);
ConsistencyCheck.Value hv2 = new ConsistencyCheck.HashedValue(versioned2);
ConsistencyCheck.Value hv3 = new ConsistencyCheck.HashedValue(versioned3);
// FULL
// one version
versionNodeSetMap.clear();
versionNodeSetMap.put(hv1, setFourNodes);
assertEquals(ConsistencyCheck.ConsistencyLevel.FULL, ConsistencyCheck.determineConsistency(versionNodeSetMap, replicationFactor));
// three versions
versionNodeSetMap.clear();
versionNodeSetMap.put(hv1, setFourNodes);
versionNodeSetMap.put(hv2, setFourNodes);
versionNodeSetMap.put(hv3, setFourNodes);
assertEquals(ConsistencyCheck.ConsistencyLevel.FULL, ConsistencyCheck.determineConsistency(versionNodeSetMap, replicationFactor));
// LATEST_CONSISTENT: not possible since timestamp is ignored
// INCONSISTENT
versionNodeSetMap.clear();
versionNodeSetMap.put(hv1, setThreeNodes);
assertEquals(ConsistencyCheck.ConsistencyLevel.INCONSISTENT, ConsistencyCheck.determineConsistency(versionNodeSetMap, replicationFactor));
versionNodeSetMap.clear();
versionNodeSetMap.put(hv1, setFourNodes);
versionNodeSetMap.put(hv2, setThreeNodes);
assertEquals(ConsistencyCheck.ConsistencyLevel.LATEST_CONSISTENT, ConsistencyCheck.determineConsistency(versionNodeSetMap, replicationFactor));
}
use of voldemort.versioning.Version in project voldemort by voldemort.
the class ImportTextDumpToBDB method lineToEntry.
public static Pair<ByteArray, Versioned<byte[]>> lineToEntry(String line) throws DecoderException {
String[] components = line.split(" ");
String keyBytesString = components[0];
byte[] keyBytes = ByteUtils.fromHexString(keyBytesString);
ByteArray key = new ByteArray(keyBytes);
String versionBytesString = components[1];
byte[] versionBytes = ByteUtils.fromHexString(versionBytesString);
Version version = new VectorClock(versionBytes, 0);
String valueBytesString = components[1];
byte[] value = ByteUtils.fromHexString(valueBytesString);
return new Pair<ByteArray, Versioned<byte[]>>(key, new Versioned<byte[]>(value, version));
}
use of voldemort.versioning.Version in project voldemort by voldemort.
the class BdbStorageEngine method delete.
@Override
public boolean delete(ByteArray key, Version version) throws PersistenceFailureException {
StoreUtils.assertValidKey(key);
long startTimeNs = -1;
if (logger.isTraceEnabled())
startTimeNs = System.nanoTime();
Transaction transaction = null;
try {
transaction = this.environment.beginTransaction(null, null);
DatabaseEntry keyEntry = new DatabaseEntry(key.get());
if (version == null) {
// unversioned delete. Just blow away the whole thing
OperationStatus status = getBdbDatabase().delete(transaction, keyEntry);
if (OperationStatus.SUCCESS == status)
return true;
else
return false;
} else {
// versioned deletes; need to determine what to delete
DatabaseEntry valueEntry = new DatabaseEntry();
// do a get for the existing values
OperationStatus status = getBdbDatabase().get(transaction, keyEntry, valueEntry, LockMode.RMW);
// key does not exist to begin with.
if (OperationStatus.NOTFOUND == status)
return false;
List<Versioned<byte[]>> vals = StoreBinaryFormat.fromByteArray(valueEntry.getData());
Iterator<Versioned<byte[]>> iter = vals.iterator();
int numVersions = vals.size();
int numDeletedVersions = 0;
// supplied version
while (iter.hasNext()) {
Versioned<byte[]> curr = iter.next();
Version currentVersion = curr.getVersion();
if (currentVersion.compare(version) == Occurred.BEFORE) {
iter.remove();
numDeletedVersions++;
}
}
if (numDeletedVersions < numVersions) {
// we still have some valid versions
valueEntry.setData(StoreBinaryFormat.toByteArray(vals));
getBdbDatabase().put(transaction, keyEntry, valueEntry);
} else {
// we have deleted all the versions; so get rid of the entry
// in the database
getBdbDatabase().delete(transaction, keyEntry);
}
return numDeletedVersions > 0;
}
} catch (DatabaseException e) {
this.bdbEnvironmentStats.reportException(e);
logger.error(e);
throw new PersistenceFailureException(e);
} finally {
attemptCommit(transaction);
if (logger.isTraceEnabled()) {
logger.trace("Completed DELETE (" + getName() + ") of key " + ByteUtils.toHexString(key.get()) + " (keyRef: " + System.identityHashCode(key) + ") in " + (System.nanoTime() - startTimeNs) + " ns at " + System.currentTimeMillis());
}
}
}
Aggregations