Package voldemort.versioning

Examples of voldemort.versioning.VectorClock


        }
    }

    public void testGetRequests() throws Exception {
        testGetRequest(TestUtils.toByteArray("hello"), null, null, null, false);
        testGetRequest(TestUtils.toByteArray("hello"), "".getBytes(), null, new VectorClock(), true);
        testGetRequest(TestUtils.toByteArray("hello"),
                       "abc".getBytes(),
                       null,
                       TestUtils.getClock(1, 2, 2, 3),
                       true);
View Full Code Here


                          new boolean[] {});

        testGetAllRequest(new ByteArray[] { new ByteArray() },
                          new byte[][] { new byte[] {} },
                          null,
                          new VectorClock[] { new VectorClock() },
                          new boolean[] { true });

        testGetAllRequest(new ByteArray[] { TestUtils.toByteArray("hello") },
                          new byte[][] { "world".getBytes() },
                          null,
                          new VectorClock[] { new VectorClock() },
                          new boolean[] { true });

        testGetAllRequest(new ByteArray[] { TestUtils.toByteArray("hello"),
                TestUtils.toByteArray("holly") }, new byte[][] { "world".getBytes(),
                "cow".getBytes() }, null, new VectorClock[] { TestUtils.getClock(1, 1),
View Full Code Here

            this.store.deleteAll();
        }
    }

    public void testPutRequests() throws Exception {
        testPutRequest(new ByteArray(), new byte[0], null, new VectorClock(), null);
        testPutRequest(TestUtils.toByteArray("hello"),
                       "world".getBytes(),
                       null,
                       new VectorClock(),
                       null);

        // test obsolete exception
        this.store.put(TestUtils.toByteArray("hello"),
                       new Versioned<byte[]>("world".getBytes(), new VectorClock()),
                       null);
        testPutRequest(TestUtils.toByteArray("hello"),
                       "world".getBytes(),
                       null,
                       new VectorClock(),
                       ObsoleteVersionException.class);
    }
View Full Code Here

    }

    public void testDeleteRequests() throws Exception {
        // test pre-existing are deleted
        testDeleteRequest(new ByteArray(),
                          new VectorClock(),
                          new Versioned<byte[]>("hello".getBytes()),
                          true);
        testDeleteRequest(TestUtils.toByteArray("hello"),
                          new VectorClock(),
                          new Versioned<byte[]>("world".getBytes()),
                          true);

        // test non-existant aren't deleted
        testDeleteRequest(TestUtils.toByteArray("hello"), new VectorClock(), null, false);
    }
View Full Code Here

        runRetentionEnforcingStoreTest(true);
    }

    private void put(String... items) {
        for(String item: items) {
            VectorClock clock = null;
            List<Versioned<byte[]>> found = engine.get(new ByteArray(item.getBytes()), null);
            if(found.size() == 0) {
                clock = new VectorClock(time.getMilliseconds());
            } else if(found.size() == 1) {
                VectorClock oldClock = (VectorClock) found.get(0).getVersion();
                clock = oldClock.incremented(0, time.getMilliseconds());
            } else {
                fail("Found multiple versions.");
            }
            engine.put(new ByteArray(item.getBytes()),
                       new Versioned<byte[]>(item.getBytes(), clock),
View Full Code Here

    @Test
    public void testUpdateClusterMetadata() {
        Cluster updatedCluster = ServerTestUtils.getLocalCluster(4);
        AdminClient client = getAdminClient();
        for(int i = 0; i < NUM_RUNS; i++) {
            VectorClock clock = ((VectorClock) client.metadataMgmtOps.getRemoteCluster(0)
                                                                     .getVersion()).incremented(0,
                                                                                                System.currentTimeMillis());
            client.metadataMgmtOps.updateRemoteCluster(0, updatedCluster, clock);

            assertEquals("Cluster should match",
View Full Code Here

                    ts = baseTimeMs + i;
                } else {
                    // odd keys : storage version wins
                    ts = baseTimeMs - i;
                }
                nodeStore.put(key, new Versioned<byte[]>(val, new VectorClock(ts)), null);
            }
        }

        Iterator<Pair<ByteArray, Versioned<byte[]>>> iterator = new AbstractIterator<Pair<ByteArray, Versioned<byte[]>>>() {

            final Iterator<ByteArray> keysItr = keys.iterator();
            int keyCount = 0;

            @Override
            protected Pair<ByteArray, Versioned<byte[]>> computeNext() {
                while(keysItr.hasNext()) {
                    ByteArray key = keysItr.next();
                    byte[] val = entries.get(key);
                    long ts = 0;
                    if(keyCount == 0) {
                        // streaming put will be in the middle of two version on
                        // storage
                        keyCount++;
                        return new Pair<ByteArray, Versioned<byte[]>>(key,
                                                                      new Versioned<byte[]>(val,
                                                                                            new VectorClock(baseTimeMs)));
                    } else {
                        if(keyCount % 2 == 0) {
                            // even keys : streaming write wins
                            ts = baseTimeMs - keyCount;
                        } else {
                            // odd keys : storage version wins
                            ts = baseTimeMs + keyCount;
                        }
                        keyCount++;
                        return new Pair<ByteArray, Versioned<byte[]>>(key,
                                                                      new Versioned<byte[]>(val,
                                                                                            new VectorClock(ts)));
                    }
                }
                return endOfData();
            }
        };
View Full Code Here

            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
View Full Code Here

        // 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),
View Full Code Here

    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);
    }
View Full Code Here

TOP

Related Classes of voldemort.versioning.VectorClock

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.