Search in sources :

Example 16 with Version

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);
    }
}
Also used : Version(voldemort.versioning.Version) ByteArray(voldemort.utils.ByteArray) Test(org.junit.Test)

Example 17 with Version

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());
}
Also used : Version(voldemort.versioning.Version) VectorClock(voldemort.versioning.VectorClock) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList)

Example 18 with Version

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));
}
Also used : ClusterNode(voldemort.utils.ConsistencyCheck.ClusterNode) HashSet(java.util.HashSet) Set(java.util.Set) Versioned(voldemort.versioning.Versioned) HashMap(java.util.HashMap) HashedValue(voldemort.utils.ConsistencyCheck.HashedValue) VectorClock(voldemort.versioning.VectorClock) Version(voldemort.versioning.Version) HashedValue(voldemort.utils.ConsistencyCheck.HashedValue) Test(org.junit.Test)

Example 19 with Version

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));
}
Also used : Version(voldemort.versioning.Version) VectorClock(voldemort.versioning.VectorClock) ByteArray(voldemort.utils.ByteArray) Pair(voldemort.utils.Pair)

Example 20 with 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());
        }
    }
}
Also used : Transaction(com.sleepycat.je.Transaction) Versioned(voldemort.versioning.Versioned) Version(voldemort.versioning.Version) OperationStatus(com.sleepycat.je.OperationStatus) AsyncOperationStatus(voldemort.server.protocol.admin.AsyncOperationStatus) DatabaseEntry(com.sleepycat.je.DatabaseEntry) DatabaseException(com.sleepycat.je.DatabaseException) PersistenceFailureException(voldemort.store.PersistenceFailureException)

Aggregations

Version (voldemort.versioning.Version)35 VectorClock (voldemort.versioning.VectorClock)16 Versioned (voldemort.versioning.Versioned)13 Test (org.junit.Test)11 ByteArray (voldemort.utils.ByteArray)10 VoldemortException (voldemort.VoldemortException)7 ArrayList (java.util.ArrayList)6 AbstractByteArrayStoreTest (voldemort.store.AbstractByteArrayStoreTest)5 HashMap (java.util.HashMap)4 IOException (java.io.IOException)3 List (java.util.List)3 ByteString (com.linkedin.data.ByteString)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 InvalidMetadataException (voldemort.store.InvalidMetadataException)2 Pair (voldemort.utils.Pair)2 ObsoleteVersionException (voldemort.versioning.ObsoleteVersionException)2 ImmutableList (com.google.common.collect.ImmutableList)1 RestException (com.linkedin.r2.message.rest.RestException)1 RestRequestBuilder (com.linkedin.r2.message.rest.RestRequestBuilder)1