Search in sources :

Example 96 with VectorClock

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

the class RedirectingStoreTest method makeSuperClock.

private VectorClock makeSuperClock(long time) {
    List<ClockEntry> clockEntries = new ArrayList<ClockEntry>();
    clockEntries.add(new ClockEntry((short) 0, time));
    clockEntries.add(new ClockEntry((short) 1, time));
    clockEntries.add(new ClockEntry((short) 2, time));
    return new VectorClock(clockEntries, time);
}
Also used : VectorClock(voldemort.versioning.VectorClock) ArrayList(java.util.ArrayList) ClockEntry(voldemort.versioning.ClockEntry)

Example 97 with VectorClock

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

the class FileBackedCachingStorageEngineTest method testConcurrentWriteFailure.

@Test
public void testConcurrentWriteFailure() {
    ByteArray key = getKey();
    Store<ByteArray, byte[], byte[]> store = getStore();
    VectorClock c1 = getClock(1, 1);
    VectorClock c2 = getClock(1, 2);
    byte[] value = getValue();
    // put two conflicting versions, then delete one
    Versioned<byte[]> v1 = new Versioned<byte[]>(value, c1);
    Versioned<byte[]> v2 = new Versioned<byte[]>(value, c2);
    store.put(key, v1, null);
    try {
        store.put(key, v2, null);
        fail("Concurrent write succeeded in FileBackedCachingStorageEngine. Should not be allowed.");
    } catch (VoldemortException ve) {
    // This is OK
    }
}
Also used : Versioned(voldemort.versioning.Versioned) VectorClock(voldemort.versioning.VectorClock) ByteArray(voldemort.utils.ByteArray) VoldemortException(voldemort.VoldemortException) AbstractStoreTest(voldemort.store.AbstractStoreTest) Test(org.junit.Test)

Example 98 with VectorClock

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

the class ServerSideRoutingTest method checkServerSideRouting.

private void checkServerSideRouting(VoldemortServer server0, VoldemortServer server1) {
    // create bunch of key-value pairs
    HashMap<ByteArray, byte[]> entryMap = ServerTestUtils.createRandomKeyValuePairs(TEST_VALUES_SIZE);
    // populate all entries in server1
    Store<ByteArray, byte[], byte[]> store = server1.getStoreRepository().getRoutedStore(testStoreName);
    for (Entry<ByteArray, byte[]> entry : entryMap.entrySet()) {
        store.put(entry.getKey(), Versioned.value(entry.getValue(), new VectorClock().incremented(0, System.currentTimeMillis())), null);
    }
    // try fetching them from server0
    store = server0.getStoreRepository().getLocalStore(testStoreName);
    RoutingStrategy routing = server0.getMetadataStore().getRoutingStrategy(testStoreName);
    for (Entry<ByteArray, byte[]> entry : entryMap.entrySet()) {
        List<Node> nodes = routing.routeRequest(entry.getKey().get());
        if (hasNode(nodes, 0)) {
            assertTrue("ServerSideRouting should return keys from other nodes.", ByteUtils.compare(entry.getValue(), store.get(entry.getKey(), null).get(0).getValue()) == 0);
        }
    }
}
Also used : VectorClock(voldemort.versioning.VectorClock) Node(voldemort.cluster.Node) RoutingStrategy(voldemort.routing.RoutingStrategy) ByteArray(voldemort.utils.ByteArray)

Example 99 with VectorClock

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

the class RedirectingStoreTest method testProxyGetDuringPut.

@Test
public void testProxyGetDuringPut() {
    final RedirectingStore storeNode2 = getRedirectingStore(2, servers[2].getMetadataStore(), "test");
    final RedirectingStore storeNode0 = getRedirectingStore(0, servers[0].getMetadataStore(), "test");
    // Check primary
    for (final Entry<ByteArray, byte[]> entry : primaryEntriesMoved.entrySet()) {
        try {
            // should see obsoleteVersionException for same vectorClock
            storeNode2.put(entry.getKey(), Versioned.value(entry.getValue(), new VectorClock().incremented(0, System.currentTimeMillis())), null);
            fail("Should see obsoleteVersionException here.");
        } catch (ObsoleteVersionException e) {
        // ignore
        }
        try {
            // should see obsoleteVersionException for same vectorClock
            storeNode0.put(entry.getKey(), Versioned.value(entry.getValue(), new VectorClock().incremented(0, System.currentTimeMillis())), null);
            fail("Should see obsoleteVersionException here.");
        } catch (ObsoleteVersionException e) {
        // ignore
        } catch (InvalidMetadataException e) {
        }
    }
}
Also used : ObsoleteVersionException(voldemort.versioning.ObsoleteVersionException) VectorClock(voldemort.versioning.VectorClock) InvalidMetadataException(voldemort.store.InvalidMetadataException) ByteArray(voldemort.utils.ByteArray) Test(org.junit.Test)

Example 100 with VectorClock

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

the class AbstractZoneAffinityTest method setup.

@Before
public void setup() throws IOException {
    byte[] v1_bytes = { (byte) 'V', (byte) '1' };
    byte[] v2_bytes = { (byte) 'V', (byte) '2' };
    byte[] k1_bytes = { (byte) 'K', (byte) '1' };
    byte[] k2_bytes = { (byte) 'K', (byte) '2' };
    byte[] k3_bytes = { (byte) 'K', (byte) '3' };
    clientConfig = new ClientConfig();
    clientConfig.setBootstrapUrls(cluster.getNodes().iterator().next().getSocketUrl().toString());
    clientConfig.setClientZoneId(clientZoneId);
    setupZoneAffinitySettings();
    SocketStoreClientFactory socketStoreClientFactory = new SocketStoreClientFactory(clientConfig);
    for (Integer nodeId : cluster.getNodeIds()) {
        SocketStoreFactory socketStoreFactory = new ClientRequestExecutorPool(2, 10000, 100000, 1024);
        VoldemortConfig config = ServerTestUtils.createServerConfigWithDefs(true, nodeId, TestUtils.createTempDir().getAbsolutePath(), cluster, stores, new Properties());
        VoldemortServer vs = ServerTestUtils.startVoldemortServer(socketStoreFactory, config, cluster);
        vservers.put(nodeId, vs);
        socketStoreFactories.put(nodeId, socketStoreFactory);
        Store<ByteArray, byte[], byte[]> store = vs.getStoreRepository().getLocalStore(storeDef.getName());
        Node node = cluster.getNodeById(nodeId);
        VectorClock version1 = new VectorClock();
        version1.incrementVersion(0, System.currentTimeMillis());
        VectorClock version2 = version1.incremented(0, System.currentTimeMillis());
        if (node.getZoneId() == clientZoneId) {
            // local zone
            store.put(new ByteArray(k1_bytes), new Versioned<byte[]>(v1_bytes, version1), null);
            store.put(new ByteArray(k2_bytes), new Versioned<byte[]>(v1_bytes, version1), null);
        } else {
            // remote zone
            store.put(new ByteArray(k1_bytes), new Versioned<byte[]>(v2_bytes, version2), null);
            store.put(new ByteArray(k2_bytes), new Versioned<byte[]>(v1_bytes, version1), null);
            store.put(new ByteArray(k3_bytes), new Versioned<byte[]>(v1_bytes, version1), null);
        }
    }
    client = socketStoreClientFactory.getRawStore(storeDef.getName(), null);
}
Also used : Node(voldemort.cluster.Node) VectorClock(voldemort.versioning.VectorClock) SocketStoreFactory(voldemort.store.socket.SocketStoreFactory) Properties(java.util.Properties) VoldemortServer(voldemort.server.VoldemortServer) VoldemortConfig(voldemort.server.VoldemortConfig) ClientRequestExecutorPool(voldemort.store.socket.clientrequest.ClientRequestExecutorPool) SocketStoreClientFactory(voldemort.client.SocketStoreClientFactory) ByteArray(voldemort.utils.ByteArray) ClientConfig(voldemort.client.ClientConfig) Before(org.junit.Before)

Aggregations

VectorClock (voldemort.versioning.VectorClock)162 Versioned (voldemort.versioning.Versioned)73 Test (org.junit.Test)65 ByteArray (voldemort.utils.ByteArray)65 ArrayList (java.util.ArrayList)33 IOException (java.io.IOException)25 VoldemortException (voldemort.VoldemortException)24 List (java.util.List)22 HashMap (java.util.HashMap)21 ObsoleteVersionException (voldemort.versioning.ObsoleteVersionException)21 Version (voldemort.versioning.Version)16 Node (voldemort.cluster.Node)15 AbstractByteArrayStoreTest (voldemort.store.AbstractByteArrayStoreTest)11 StoreDefinition (voldemort.store.StoreDefinition)11 AdminClient (voldemort.client.protocol.admin.AdminClient)10 VoldemortServer (voldemort.server.VoldemortServer)10 Pair (voldemort.utils.Pair)10 ClockEntry (voldemort.versioning.ClockEntry)10 File (java.io.File)8 Map (java.util.Map)8