Search in sources :

Example 41 with VectorClock

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

the class AdminCommandStream method readEntriesBinary.

private static Iterator<Pair<ByteArray, Versioned<byte[]>>> readEntriesBinary(File inputDir, String storeName) throws IOException {
    File inputFile = new File(inputDir, storeName + ".entries");
    if (!inputFile.exists()) {
        throw new FileNotFoundException("File " + inputFile.getAbsolutePath() + " does not exist!");
    }
    final DataInputStream dis = new DataInputStream(new BufferedInputStream(new FileInputStream(inputFile)));
    return new AbstractIterator<Pair<ByteArray, Versioned<byte[]>>>() {

        @Override
        protected Pair<ByteArray, Versioned<byte[]>> computeNext() {
            try {
                int length = dis.readInt();
                byte[] keyBytes = new byte[length];
                ByteUtils.read(dis, keyBytes);
                length = dis.readInt();
                byte[] versionBytes = new byte[length];
                ByteUtils.read(dis, versionBytes);
                length = dis.readInt();
                byte[] valueBytes = new byte[length];
                ByteUtils.read(dis, valueBytes);
                ByteArray key = new ByteArray(keyBytes);
                VectorClock version = new VectorClock(versionBytes);
                Versioned<byte[]> value = new Versioned<byte[]>(valueBytes, version);
                return new Pair<ByteArray, Versioned<byte[]>>(key, value);
            } catch (EOFException e) {
                try {
                    dis.close();
                } catch (IOException ie) {
                    ie.printStackTrace();
                }
                return endOfData();
            } catch (IOException e) {
                try {
                    dis.close();
                } catch (IOException ie) {
                    ie.printStackTrace();
                }
                throw new VoldemortException("Error reading from input file ", e);
            }
        }
    };
}
Also used : Versioned(voldemort.versioning.Versioned) VectorClock(voldemort.versioning.VectorClock) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) VoldemortException(voldemort.VoldemortException) FileInputStream(java.io.FileInputStream) BufferedInputStream(java.io.BufferedInputStream) EOFException(java.io.EOFException) ByteArray(voldemort.utils.ByteArray) AbstractIterator(com.google.common.collect.AbstractIterator) File(java.io.File) Pair(voldemort.utils.Pair)

Example 42 with VectorClock

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

the class RebootstrappingStoreTest method rebalance.

public void rebalance() {
    assert servers != null && servers.size() > 1;
    VoldemortConfig config = servers.get(0).getVoldemortConfig();
    AdminClient adminClient = AdminClient.createTempAdminClient(config, cluster, 4);
    List<Integer> partitionIds = ImmutableList.of(0, 1);
    int req = adminClient.storeMntOps.migratePartitions(0, 1, STORE_NAME, partitionIds, null, null);
    adminClient.rpcOps.waitForCompletion(1, req, 5, TimeUnit.SECONDS);
    Versioned<Cluster> versionedCluster = adminClient.metadataMgmtOps.getRemoteCluster(0);
    Node node0 = versionedCluster.getValue().getNodeById(0);
    Node node1 = versionedCluster.getValue().getNodeById(1);
    Node newNode0 = new Node(node0.getId(), node0.getHost(), node0.getHttpPort(), node0.getSocketPort(), node0.getAdminPort(), ImmutableList.<Integer>of());
    Node newNode1 = new Node(node1.getId(), node1.getHost(), node1.getHttpPort(), node1.getSocketPort(), node1.getAdminPort(), ImmutableList.of(0, 1));
    long deleted = adminClient.storeMntOps.deletePartitions(0, STORE_NAME, ImmutableList.of(0, 1), null);
    assert deleted > 0;
    Cluster newCluster = new Cluster(cluster.getName(), ImmutableList.of(newNode0, newNode1), Lists.newArrayList(cluster.getZones()));
    for (Node node : cluster.getNodes()) {
        VectorClock clock = (VectorClock) versionedCluster.getVersion();
        clock.incrementVersion(node.getId(), System.currentTimeMillis());
        adminClient.metadataMgmtOps.updateRemoteCluster(node.getId(), newCluster, clock);
    }
}
Also used : Node(voldemort.cluster.Node) VectorClock(voldemort.versioning.VectorClock) Cluster(voldemort.cluster.Cluster) VoldemortConfig(voldemort.server.VoldemortConfig) AdminClient(voldemort.client.protocol.admin.AdminClient)

Example 43 with VectorClock

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

the class RedirectingStoreTest method testProxyPuts.

@Test
public void testProxyPuts() {
    List<ByteArray> testPrimaryKeys = new ArrayList<ByteArray>(this.proxyPutTestPrimaryEntries.keySet());
    List<ByteArray> testSecondaryKeys = new ArrayList<ByteArray>(this.proxyPutTestSecondaryEntries.keySet());
    final RedirectingStore redirectingStoreNode2 = getRedirectingStore(2, servers[2].getMetadataStore(), "test");
    final RedirectingStore redirectingStoreNode0 = getRedirectingStore(0, servers[0].getMetadataStore(), "test");
    final Store<ByteArray, byte[], byte[]> socketStoreNode2 = redirectingStoreNode2.getRedirectingSocketStore("test", 2);
    final Store<ByteArray, byte[], byte[]> socketStoreNode0 = redirectingStoreNode0.getRedirectingSocketStore("test", 0);
    // 1. Make sure the vector clocks make sense.. Read through Node 2 and
    // proxy getting from Node 0 and issue a write based off that,
    // incrementing the clock for Node 2 and make sure there is no
    // ObsoleteVersionException at both Node 0 and
    // Node 2.
    ByteArray secondaryKey = testSecondaryKeys.get(0);
    VectorClock clock1 = ((VectorClock) redirectingStoreNode2.getVersions(secondaryKey).get(0)).incremented(2, System.currentTimeMillis());
    try {
        redirectingStoreNode2.put(secondaryKey, Versioned.value("write-through".getBytes("UTF-8"), clock1), null);
    } catch (Exception e) {
        fail("Unexpected error in testing write through proxy put");
        e.printStackTrace();
    }
    waitForProxyPutsToDrain(redirectingStoreNode2);
    assertTrue("Unexpected failures in proxy put", redirectingStoreNode2.getProxyPutStats().getNumProxyPutFailures() == 0);
    assertEquals("Unexpected value in Node 2", "write-through", new String(socketStoreNode2.get(secondaryKey, null).get(0).getValue()));
    assertTrue("Proxy write not seen on proxy node 0", "write-through".equals(new String(socketStoreNode0.get(secondaryKey, null).get(0).getValue())));
    // Also test that if put fails locally, proxy put is not attempted.
    try {
        redirectingStoreNode2.put(secondaryKey, Versioned.value("write-through-updated".getBytes("UTF-8"), clock1), null);
        fail("Should have thrown OVE");
    } catch (ObsoleteVersionException ove) {
    // Expected
    } catch (Exception e) {
        fail("Unexpected error in testing write through proxy put");
        e.printStackTrace();
    }
    waitForProxyPutsToDrain(redirectingStoreNode2);
    assertFalse("Proxy write not seen on proxy node 0", "write-through-updated".equals(new String(socketStoreNode0.get(secondaryKey, null).get(0).getValue())));
    // 2. Make sure if the proxy node is still a replica, we don't issue
    // proxy puts. Node 2 -> Node 0 on partition 0, for which Node 0 is
    // still a replica
    ByteArray primaryKey = testPrimaryKeys.get(0);
    VectorClock clock2 = ((VectorClock) redirectingStoreNode2.getVersions(primaryKey).get(0)).incremented(2, System.currentTimeMillis());
    try {
        redirectingStoreNode2.put(primaryKey, Versioned.value("write-through".getBytes("UTF-8"), clock2), null);
    } catch (Exception e) {
        fail("Unexpected error in testing write through proxy put");
        e.printStackTrace();
    }
    waitForProxyPutsToDrain(redirectingStoreNode2);
    assertEquals("Unexpected value in Node 2", "write-through", new String(socketStoreNode2.get(primaryKey, null).get(0).getValue()));
    assertFalse("Proxy write seen on proxy node which is a replica", "write-through".equals(new String(socketStoreNode0.get(primaryKey, null).get(0).getValue())));
    // generate OVE.
    try {
        redirectingStoreNode2.put(primaryKey, Versioned.value("write-through".getBytes("UTF-8"), clock2), null);
        fail("Should have thrown OVE");
    } catch (ObsoleteVersionException ove) {
    // Expected
    } catch (Exception e) {
        fail("Unexpected error in testing write through proxy put");
        e.printStackTrace();
    }
}
Also used : ObsoleteVersionException(voldemort.versioning.ObsoleteVersionException) VectorClock(voldemort.versioning.VectorClock) ArrayList(java.util.ArrayList) ByteArray(voldemort.utils.ByteArray) ObsoleteVersionException(voldemort.versioning.ObsoleteVersionException) IOException(java.io.IOException) InvalidMetadataException(voldemort.store.InvalidMetadataException) Test(org.junit.Test)

Example 44 with VectorClock

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

the class FileBackedCachingStorageEngineTest method testGetAll.

@Override
@Test
public void testGetAll() throws Exception {
    Store<ByteArray, byte[], byte[]> store = getStore();
    int putCount = 10;
    List<ByteArray> keys = getKeys(putCount);
    List<byte[]> values = getValues(putCount);
    assertEquals(putCount, values.size());
    VectorClock clock = new VectorClock();
    for (int i = 0; i < putCount; i++) {
        store.put(keys.get(i), new Versioned<byte[]>(values.get(i), clock), null);
        clock = clock.incremented(0, System.currentTimeMillis());
    }
    int countForGet = putCount / 2;
    List<ByteArray> keysForGet = keys.subList(0, countForGet);
    List<byte[]> valuesForGet = values.subList(0, countForGet);
    Map<ByteArray, List<Versioned<byte[]>>> result = store.getAll(keysForGet, null);
    assertGetAllValues(keysForGet, valuesForGet, result);
}
Also used : VectorClock(voldemort.versioning.VectorClock) ByteArray(voldemort.utils.ByteArray) ArrayList(java.util.ArrayList) List(java.util.List) AbstractStoreTest(voldemort.store.AbstractStoreTest) Test(org.junit.Test)

Example 45 with VectorClock

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

the class FileBackedCachingStorageEngineTest method testDelete.

@Override
public void testDelete() {
    ByteArray key = getKey();
    Store<ByteArray, byte[], byte[]> store = getStore();
    VectorClock c1 = getClock(1, 1);
    byte[] value = getValue();
    // can't delete something that isn't there
    assertTrue(!store.delete(key, c1));
    store.put(key, new Versioned<byte[]>(value, c1), null);
    assertEquals(1, store.get(key, null).size());
    // now delete that version too
    assertTrue("Delete failed!", store.delete(key, c1));
    assertEquals(0, store.get(key, null).size());
}
Also used : VectorClock(voldemort.versioning.VectorClock) ByteArray(voldemort.utils.ByteArray)

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