Search in sources :

Example 51 with VectorClock

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

the class BdbStorageEngineTest method testSimultaneousIterationAndModification.

@Test
public void testSimultaneousIterationAndModification() throws Exception {
    // start a thread to do modifications
    ExecutorService executor = Executors.newFixedThreadPool(2);
    final Random rand = new Random();
    final AtomicInteger count = new AtomicInteger(0);
    final AtomicBoolean keepRunning = new AtomicBoolean(true);
    executor.execute(new Runnable() {

        public void run() {
            while (keepRunning.get()) {
                byte[] bytes = Integer.toString(count.getAndIncrement()).getBytes();
                store.put(new ByteArray(bytes), Versioned.value(bytes), null);
                count.incrementAndGet();
            }
        }
    });
    executor.execute(new Runnable() {

        public void run() {
            while (keepRunning.get()) {
                byte[] bytes = Integer.toString(rand.nextInt(count.get())).getBytes();
                store.delete(new ByteArray(bytes), new VectorClock());
                count.incrementAndGet();
            }
        }
    });
    // wait a bit
    while (count.get() < 300) continue;
    // now simultaneously do iteration
    ClosableIterator<Pair<ByteArray, Versioned<byte[]>>> iter = this.store.entries();
    while (iter.hasNext()) iter.next();
    iter.close();
    keepRunning.set(false);
    executor.shutdown();
    assertTrue(executor.awaitTermination(5, TimeUnit.SECONDS));
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Random(java.util.Random) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) VectorClock(voldemort.versioning.VectorClock) ExecutorService(java.util.concurrent.ExecutorService) ByteArray(voldemort.utils.ByteArray) Pair(voldemort.utils.Pair) AbstractStorageEngineTest(voldemort.store.AbstractStorageEngineTest) Test(org.junit.Test)

Example 52 with VectorClock

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

the class BdbStorageEngineTest method testConcurrentReadAndPut.

@Test
public void testConcurrentReadAndPut() throws Exception {
    ExecutorService executor = Executors.newFixedThreadPool(10);
    final CountDownLatch latch = new CountDownLatch(10);
    final AtomicBoolean returnedEmpty = new AtomicBoolean(false);
    final byte[] keyBytes = "foo".getBytes();
    final byte[] valueBytes = "bar".getBytes();
    store.put(new ByteArray(keyBytes), new Versioned<byte[]>(valueBytes), null);
    for (int i = 0; i < 10; i++) {
        executor.submit(new Runnable() {

            public void run() {
                try {
                    for (int j = 0; j < 1000 && !returnedEmpty.get(); j++) {
                        List<Versioned<byte[]>> vals = store.get(new ByteArray(keyBytes), null);
                        if (vals.size() == 0 && j > 1)
                            returnedEmpty.set(true);
                        else {
                            VectorClock v = (VectorClock) vals.get(0).getVersion();
                            v.incrementVersion(0, System.currentTimeMillis());
                            try {
                                store.put(new ByteArray(keyBytes), new Versioned<byte[]>(valueBytes, v), null);
                            } catch (ObsoleteVersionException e) {
                            // Ignore these
                            }
                        }
                    }
                } finally {
                    latch.countDown();
                }
            }
        });
    }
    latch.await();
    assertFalse("Should not have seen any empty results", returnedEmpty.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ObsoleteVersionException(voldemort.versioning.ObsoleteVersionException) Versioned(voldemort.versioning.Versioned) VectorClock(voldemort.versioning.VectorClock) ExecutorService(java.util.concurrent.ExecutorService) ByteArray(voldemort.utils.ByteArray) List(java.util.List) CountDownLatch(java.util.concurrent.CountDownLatch) AbstractStorageEngineTest(voldemort.store.AbstractStorageEngineTest) Test(org.junit.Test)

Example 53 with VectorClock

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

the class ConfigurationStorageEngineTest method testDelete.

@Override
public void testDelete() {
    String key = getKey();
    Store<String, String, String> store = getStore();
    VectorClock c1 = getClock(1, 1);
    String value = getValue();
    // can't delete something that isn't there
    assertTrue(!store.delete(key, c1));
    store.put(key, new Versioned<String>(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)

Example 54 with VectorClock

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

the class MetadataStoreTest method testSimpleGetAndPut.

@Test
public void testSimpleGetAndPut() {
    for (int i = 0; i <= TEST_RUNS; i++) {
        ByteArray key = getValidKey();
        VectorClock clock = (VectorClock) metadataStore.get(key, null).get(0).getVersion();
        Versioned<byte[]> value = new Versioned<byte[]>(getValidValue(key), clock.incremented(0, 1));
        metadataStore.put(key, value, null);
        checkValues(value, metadataStore.get(key, null), key);
    }
}
Also used : Versioned(voldemort.versioning.Versioned) VectorClock(voldemort.versioning.VectorClock) ByteArray(voldemort.utils.ByteArray) AvroAddStoreTest(voldemort.tools.admin.AvroAddStoreTest) Test(org.junit.Test)

Example 55 with VectorClock

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

the class MetadataStoreTest method testObsoletePut.

@Test
public void testObsoletePut() {
    for (int i = 0; i <= TEST_RUNS; i++) {
        ByteArray key = getValidKey();
        VectorClock clock = (VectorClock) metadataStore.get(key, null).get(0).getVersion();
        Versioned<byte[]> value = new Versioned<byte[]>(getValidValue(key), clock.incremented(0, 1));
        try {
            metadataStore.put(key, value, null);
            assertTrue(true);
            metadataStore.put(key, value, null);
            fail();
        } catch (ObsoleteVersionException e) {
        // expected ObsoleteVersionException
        }
    }
}
Also used : ObsoleteVersionException(voldemort.versioning.ObsoleteVersionException) Versioned(voldemort.versioning.Versioned) VectorClock(voldemort.versioning.VectorClock) ByteArray(voldemort.utils.ByteArray) AvroAddStoreTest(voldemort.tools.admin.AvroAddStoreTest) Test(org.junit.Test)

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