Search in sources :

Example 56 with Versioned

use of voldemort.versioning.Versioned in project voldemort by voldemort.

the class OfflineStateTest method testSlopStreaming.

private boolean testSlopStreaming() {
    final List<Versioned<Slop>> entrySet = ServerTestUtils.createRandomSlops(0, 10000, testStoreName, "users", "test-replication-persistent", "test-readrepair-memory", "test-consistent", "test-consistent-with-pref-list");
    Iterator<Versioned<Slop>> slopIterator = entrySet.iterator();
    try {
        getAdminClient().streamingOps.updateSlopEntries(0, slopIterator);
    } catch (VoldemortException e) {
        return false;
    }
    // check updated values
    Iterator<Versioned<Slop>> entrysetItr = entrySet.iterator();
    while (entrysetItr.hasNext()) {
        Versioned<Slop> versioned = entrysetItr.next();
        Slop nextSlop = versioned.getValue();
        Store<ByteArray, byte[], byte[]> store = getStore(0, nextSlop.getStoreName());
        if (nextSlop.getOperation().equals(Slop.Operation.PUT)) {
            return store.get(nextSlop.getKey(), null).size() != 0;
        } else if (nextSlop.getOperation().equals(Slop.Operation.DELETE)) {
            return store.get(nextSlop.getKey(), null).size() == 0;
        }
    }
    return false;
}
Also used : Versioned(voldemort.versioning.Versioned) ByteArray(voldemort.utils.ByteArray) VoldemortException(voldemort.VoldemortException) Slop(voldemort.store.slop.Slop)

Example 57 with Versioned

use of voldemort.versioning.Versioned in project voldemort by voldemort.

the class ClientTrafficVerifier method run.

@SuppressWarnings("serial")
@Override
public void run() {
    Random r = new Random(System.currentTimeMillis());
    while (!shouldStop) {
        String k = keys.get(r.nextInt(KV_POOL_SIZE));
        try {
            switch(r.nextInt(3)) {
                case // update
                0:
                    if ((operationMode & MODE_ALLOW_PUT) == 0) {
                        break;
                    }
                    int newCount = kvUpdateCount.get(k) + 1;
                    client.put(k, kvMap.get(k) + "_" + newCount);
                    kvUpdateCount.put(k, newCount);
                    requestCount.put("PUT", requestCount.get("PUT") + 1);
                    break;
                case // get
                1:
                    if ((operationMode & MODE_ALLOW_GET) == 0) {
                        break;
                    }
                    Versioned<String> value = client.get(k);
                    verifyValue(k, value);
                    requestCount.put("GET", requestCount.get("GET") + 1);
                    break;
                case // get all
                2:
                    if ((operationMode & MODE_ALLOW_GETALL) == 0) {
                        break;
                    }
                    String k2 = keys.get(r.nextInt(KV_POOL_SIZE));
                    Map<String, Versioned<String>> result = client.getAll(Arrays.asList(k, k2));
                    verifyValue(k, result.get(k));
                    verifyValue(k2, result.get(k2));
                    requestCount.put("GETALL", requestCount.get("GETALL") + 1);
                    break;
            }
        } catch (ObsoleteVersionException e) {
        // Theoretically, each thread works with its own set of keys the
        // ObsoleteVersionException should not happen. But partitions
        // are moving around nodes and because of the way we
        // acknowledge writes before all nodes are complete and using
        // async writes they can be out of sync and the exceptions can
        // still happen. Did not try digging deeper on this one
        // as it is irrelevant for the refactoring I am doing.
        } catch (Exception e) {
            logger.info("CLIENT EXCEPTION FAILURE on key [" + k + "]", e);
            String exceptionName = "Key " + k + " " + e.getClass().toString();
            if (exceptionCount.containsKey(exceptionName)) {
                exceptionCount.put(exceptionName, exceptionCount.get(exceptionName) + 1);
            } else {
                exceptionCount.put(exceptionName, 1);
            }
        }
    }
}
Also used : ObsoleteVersionException(voldemort.versioning.ObsoleteVersionException) Random(java.util.Random) Versioned(voldemort.versioning.Versioned) ObsoleteVersionException(voldemort.versioning.ObsoleteVersionException)

Example 58 with Versioned

use of voldemort.versioning.Versioned in project voldemort by voldemort.

the class VoldemortServer method getTestMetadataStore.

private static MetadataStore getTestMetadataStore(VoldemortConfig voldemortConfig, Cluster cluster) {
    ConfigurationStorageEngine metadataInnerEngine = new ConfigurationStorageEngine("metadata-config-store", voldemortConfig.getMetadataDirectory());
    List<Versioned<String>> clusterXmlValue = metadataInnerEngine.get(MetadataStore.CLUSTER_KEY, null);
    VectorClock version = null;
    if (clusterXmlValue.size() <= 0) {
        version = new VectorClock();
    } else {
        version = (VectorClock) clusterXmlValue.get(0).getVersion();
    }
    int nodeId = getNodeId(voldemortConfig, cluster);
    version.incrementVersion(nodeId, System.currentTimeMillis());
    metadataInnerEngine.put(MetadataStore.CLUSTER_KEY, new Versioned<String>(new ClusterMapper().writeCluster(cluster), version), null);
    return MetadataStore.createInMemoryMetadataStore(metadataInnerEngine, nodeId);
}
Also used : Versioned(voldemort.versioning.Versioned) VectorClock(voldemort.versioning.VectorClock) ConfigurationStorageEngine(voldemort.store.configuration.ConfigurationStorageEngine) ClusterMapper(voldemort.xml.ClusterMapper)

Example 59 with Versioned

use of voldemort.versioning.Versioned in project voldemort by voldemort.

the class DynamicTimeoutStoreClient method putWithCustomTimeout.

/**
     * Performs a put operation with the specified composite request object
     * 
     * @param requestWrapper A composite request object containing the key and
     *        value
     * @return Version of the value for the successful put
     */
public Version putWithCustomTimeout(CompositeVoldemortRequest<K, V> requestWrapper) {
    validateTimeout(requestWrapper.getRoutingTimeoutInMs());
    List<Versioned<V>> versionedValues;
    long startTime = System.currentTimeMillis();
    String keyHexString = "";
    if (logger.isDebugEnabled()) {
        ByteArray key = (ByteArray) requestWrapper.getKey();
        keyHexString = RestUtils.getKeyHexString(key);
        logger.debug("PUT requested for key: " + keyHexString + " , for store: " + this.storeName + " at time(in ms): " + startTime + " . Nested GET and PUT VERSION requests to follow ---");
    }
    // We use the full timeout for doing the Get. In this, we're being
    // optimistic that the subsequent put might be faster such that all the
    // steps might finish within the allotted time
    requestWrapper.setResolveConflicts(true);
    versionedValues = getWithCustomTimeout(requestWrapper);
    Versioned<V> versioned = getItemOrThrow(requestWrapper.getKey(), null, versionedValues);
    long endTime = System.currentTimeMillis();
    if (versioned == null)
        versioned = Versioned.value(requestWrapper.getRawValue(), new VectorClock());
    else
        versioned.setObject(requestWrapper.getRawValue());
    // This should not happen unless there's a bug in the
    // getWithCustomTimeout
    long timeLeft = requestWrapper.getRoutingTimeoutInMs() - (endTime - startTime);
    if (timeLeft <= 0) {
        throw new StoreTimeoutException("PUT request timed out");
    }
    CompositeVersionedPutVoldemortRequest<K, V> putVersionedRequestObject = new CompositeVersionedPutVoldemortRequest<K, V>(requestWrapper.getKey(), versioned, timeLeft);
    putVersionedRequestObject.setRequestOriginTimeInMs(requestWrapper.getRequestOriginTimeInMs());
    Version result = putVersionedWithCustomTimeout(putVersionedRequestObject);
    long endTimeInMs = System.currentTimeMillis();
    if (logger.isDebugEnabled()) {
        logger.debug("PUT response received for key: " + keyHexString + " , for store: " + this.storeName + " at time(in ms): " + endTimeInMs);
    }
    return result;
}
Also used : Versioned(voldemort.versioning.Versioned) VectorClock(voldemort.versioning.VectorClock) CompositeVersionedPutVoldemortRequest(voldemort.store.CompositeVersionedPutVoldemortRequest) Version(voldemort.versioning.Version) StoreTimeoutException(voldemort.store.StoreTimeoutException) ByteArray(voldemort.utils.ByteArray)

Example 60 with Versioned

use of voldemort.versioning.Versioned in project voldemort by voldemort.

the class VersionedSerializer method toObject.

public Versioned<T> toObject(byte[] bytes) {
    VectorClock vectorClock = getVectorClock(bytes);
    int size = 1;
    if (vectorClock != null)
        size = vectorClock.sizeInBytes();
    T t = innerSerializer.toObject(ByteUtils.copy(bytes, size, bytes.length));
    return new Versioned<T>(t, vectorClock);
}
Also used : Versioned(voldemort.versioning.Versioned) VectorClock(voldemort.versioning.VectorClock)

Aggregations

Versioned (voldemort.versioning.Versioned)214 ByteArray (voldemort.utils.ByteArray)130 Test (org.junit.Test)88 VectorClock (voldemort.versioning.VectorClock)73 ArrayList (java.util.ArrayList)56 VoldemortException (voldemort.VoldemortException)48 List (java.util.List)36 StoreDefinition (voldemort.store.StoreDefinition)29 HashMap (java.util.HashMap)28 IOException (java.io.IOException)27 Node (voldemort.cluster.Node)27 Pair (voldemort.utils.Pair)25 Slop (voldemort.store.slop.Slop)22 ObsoleteVersionException (voldemort.versioning.ObsoleteVersionException)22 Map (java.util.Map)21 Cluster (voldemort.cluster.Cluster)17 AbstractByteArrayStoreTest (voldemort.store.AbstractByteArrayStoreTest)15 InvalidMetadataException (voldemort.store.InvalidMetadataException)13 PersistenceFailureException (voldemort.store.PersistenceFailureException)13 Version (voldemort.versioning.Version)13