Search in sources :

Example 11 with Version

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

the class DefaultStoreClient method put.

public Version put(K key, V value, Object transforms) {
    Version version = getVersionForPut(key);
    Versioned<V> versioned = Versioned.value(value, version);
    return put(key, versioned, transforms);
}
Also used : Version(voldemort.versioning.Version)

Example 12 with Version

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

the class SystemStoreClient method putSysStore.

public Version putSysStore(K key, Versioned<V> value) {
    Version version = null;
    try {
        if (logger.isDebugEnabled()) {
            logger.debug("Invoking Put for key : " + key + " on store name : " + this.storeName);
        }
        this.sysStore.put(key, value, null);
        version = value.getVersion();
    } catch (Exception e) {
        if (logger.isDebugEnabled()) {
            logger.debug("Exception caught during putSysStore: " + e);
        }
        logger.info("Exception during put", e);
    }
    return version;
}
Also used : Version(voldemort.versioning.Version) InconsistentDataException(voldemort.versioning.InconsistentDataException) InvalidMetadataException(voldemort.store.InvalidMetadataException) VoldemortException(voldemort.VoldemortException)

Example 13 with Version

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

the class GossiperTest method testGossiper.

// Protect against this test running forever until the root cause of running
// forever is found.
@Test(timeout = 1800)
public void testGossiper() throws Exception {
    Cluster newCluster = null;
    boolean startedAdditionalServer = false;
    while (!startedAdditionalServer) {
        try {
            newCluster = attemptStartAdditionalServer();
            startedAdditionalServer = true;
        } catch (IOException ioe) {
            logger.warn("Caught an IOException when attempting to start additional server. Will print stacktrace and then attempt to start additional server again.");
            ioe.printStackTrace();
        }
    }
    // Get the new cluster.xml
    AdminClient localAdminClient = getAdminClient(newCluster);
    Versioned<String> versionedClusterXML = localAdminClient.metadataMgmtOps.getRemoteMetadata(3, MetadataStore.CLUSTER_KEY);
    // Increment the version, let what would be the "donor node" know about
    // it to seed the Gossip.
    Version version = versionedClusterXML.getVersion();
    ((VectorClock) version).incrementVersion(3, ((VectorClock) version).getTimestamp() + 1);
    ((VectorClock) version).incrementVersion(0, ((VectorClock) version).getTimestamp() + 1);
    localAdminClient.metadataMgmtOps.updateRemoteMetadata(0, MetadataStore.CLUSTER_KEY, versionedClusterXML);
    localAdminClient.metadataMgmtOps.updateRemoteMetadata(3, MetadataStore.CLUSTER_KEY, versionedClusterXML);
    try {
        Thread.sleep(500);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    }
    // Wait up to five seconds for Gossip to spread
    final Cluster newFinalCluster = newCluster;
    try {
        TestUtils.assertWithBackoff(5000, new Attempt() {

            public void checkCondition() {
                int serversSeen = 0;
                // Now verify that we have gossiped correctly
                for (VoldemortServer server : servers) {
                    Cluster clusterAtServer = server.getMetadataStore().getCluster();
                    int nodeId = server.getMetadataStore().getNodeId();
                    assertEquals("server " + nodeId + " has heard " + " the gossip about number of nodes", clusterAtServer.getNumberOfNodes(), newFinalCluster.getNumberOfNodes());
                    assertEquals("server " + nodeId + " has heard " + " the gossip about partitions", clusterAtServer.getNodeById(nodeId).getPartitionIds(), newFinalCluster.getNodeById(nodeId).getPartitionIds());
                    serversSeen++;
                }
                assertEquals("saw all servers", serversSeen, servers.size());
            }
        });
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    }
}
Also used : Attempt(voldemort.Attempt) Version(voldemort.versioning.Version) VectorClock(voldemort.versioning.VectorClock) Cluster(voldemort.cluster.Cluster) IOException(java.io.IOException) VoldemortServer(voldemort.server.VoldemortServer) AdminClient(voldemort.client.protocol.admin.AdminClient) Test(org.junit.Test)

Example 14 with Version

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

the class AbstractRequestFormatTest method testGetVersionRequest.

public void testGetVersionRequest(ByteArray key, byte[] value, VectorClock version, boolean isPresent) throws Exception {
    try {
        if (isPresent) {
            testPutRequest(key, value, null, version, null, false);
        }
        ByteArrayOutputStream getVersionRequest = new ByteArrayOutputStream();
        this.clientWireFormat.writeGetVersionRequest(new DataOutputStream(getVersionRequest), storeName, key, RequestRoutingType.NORMAL);
        ByteArrayOutputStream getVersionResponse = handleRequest(getVersionRequest);
        testIsCompleteGetVersionResponse(getVersionResponse);
        List<Version> values = this.clientWireFormat.readGetVersionResponse(inputStream(getVersionResponse));
        if (isPresent) {
            assertEquals(1, values.size());
            VectorClock returnValue = (VectorClock) values.get(0);
            assertEquals(version, returnValue);
            assertEquals(version.getTimestamp(), returnValue.getTimestamp());
        } else {
            assertEquals(0, values.size());
        }
    } finally {
        this.store.deleteAll();
    }
}
Also used : Version(voldemort.versioning.Version) DataOutputStream(java.io.DataOutputStream) VectorClock(voldemort.versioning.VectorClock) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 15 with Version

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

the class RoutedStoreTest method testGetVersions2.

@Test
public void testGetVersions2() throws Exception {
    List<ByteArray> keys = getKeys(2);
    ByteArray key = keys.get(0);
    byte[] value = getValue();
    Store<ByteArray, byte[], byte[]> store = getStore();
    store.put(key, Versioned.value(value), null);
    List<Versioned<byte[]>> versioneds = store.get(key, null);
    List<Version> versions = store.getVersions(key);
    assertEquals(1, versioneds.size());
    assertEquals(9, versions.size());
    for (int i = 0; i < versions.size(); i++) assertEquals(versioneds.get(0).getVersion(), versions.get(i));
    assertEquals(0, store.getVersions(keys.get(1)).size());
}
Also used : Versioned(voldemort.versioning.Versioned) Version(voldemort.versioning.Version) ByteArray(voldemort.utils.ByteArray) AbstractByteArrayStoreTest(voldemort.store.AbstractByteArrayStoreTest) Test(org.junit.Test)

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