Examples of VectorClock


Examples of voldemort.versioning.VectorClock

                     client.get("k", new Versioned<String>("v")));
        assertEquals("null should be an acceptable default value.",
                     null,
                     client.getValue("k", null));
        client.put("k", "v");
        VectorClock expectedVC = new VectorClock().incremented(nodeId, time.getMilliseconds());
        assertEquals("If there is a value for k, get(k) should return it.",
                     "v",
                     client.get("k", new Versioned<String>("v2")).getValue());
        assertNotNull(client.get("k").getVersion());
    }
View Full Code Here

Examples of voldemort.versioning.VectorClock

            }
            if(this.zoneId != INVALID_ZONE_ID) {
                rb.setHeader(RestMessageHeaders.X_VOLD_ZONE_ID, String.valueOf(this.zoneId));
            }
            // Serialize the Vector clock
            VectorClock vc = (VectorClock) version;

            // If the given Vector clock is empty, we'll let the receiver of
            // this request fetch the existing vector clock and increment
            // before
            // doing the put.
            if(vc != null && vc.getEntries().size() != 0) {
                String serializedVC = null;
                if(!vc.getEntries().isEmpty()) {
                    serializedVC = RestUtils.getSerializedVectorClock(vc);
                }

                if(serializedVC != null && serializedVC.length() > 0) {
                    rb.setHeader(RestMessageHeaders.X_VOLD_VECTOR_CLOCK, serializedVC);
View Full Code Here

Examples of voldemort.versioning.VectorClock

                InputStream input = part.getInputStream();
                byte[] bodyPartBytes = new byte[contentLength];
                input.read(bodyPartBytes);

                VectorClock clock = new VectorClock(vcWrapper.getVersions(),
                                                    vcWrapper.getTimestamp());
                results.add(new Versioned<byte[]>(bodyPartBytes, clock));

            }
View Full Code Here

Examples of voldemort.versioning.VectorClock

            if(this.zoneId != INVALID_ZONE_ID) {
                rb.setHeader(RestMessageHeaders.X_VOLD_ZONE_ID, String.valueOf(this.zoneId));
            }

            // Serialize the Vector clock
            VectorClock vc = (VectorClock) value.getVersion();

            // If the given Vector clock is empty, we'll let the receiver of
            // this request fetch the existing vector clock and increment before
            // doing the put.
            if(vc != null) {
                String serializedVC = null;
                if(!vc.getEntries().isEmpty()) {
                    serializedVC = RestUtils.getSerializedVectorClock(vc);
                }

                if(serializedVC != null && serializedVC.length() > 0) {
                    rb.setHeader(RestMessageHeaders.X_VOLD_VECTOR_CLOCK, serializedVC);
                }
            }

            RestRequest request = rb.build();
            Future<RestResponse> f = client.restRequest(request);

            // This will block
            response = f.get();

            String serializedUpdatedVC = response.getHeader(RestMessageHeaders.X_VOLD_VECTOR_CLOCK);
            if(serializedUpdatedVC == null || serializedUpdatedVC.length() == 0) {
                if(logger.isDebugEnabled()) {
                    logger.debug("Received empty vector clock in the response");
                }
            } else {
                VectorClock updatedVC = RestUtils.deserializeVectorClock(serializedUpdatedVC);
                VectorClock originalVC = (VectorClock) value.getVersion();
                originalVC.copyFromVectorClock(updatedVC);
            }

            final ByteString entity = response.getEntity();
            if(entity == null) {
                if(logger.isDebugEnabled()) {
View Full Code Here

Examples of voldemort.versioning.VectorClock

                    // get the value bytes
                    InputStream input = valuePart.getInputStream();
                    byte[] bodyPartBytes = new byte[contentLength];
                    input.read(bodyPartBytes);

                    VectorClock clock = new VectorClock(vcWrapper.getVersions(),
                                                        vcWrapper.getTimestamp());
                    valueResultList.add(new Versioned<byte[]>(bodyPartBytes, clock));

                }
                results.put(key, valueResultList);
View Full Code Here

Examples of voldemort.versioning.VectorClock

    }

    @Override
    @Test
    public void testPutVersioned() {
        VectorClock vc = new VectorClock();
        vc.incrementVersion(this.nodeId, System.currentTimeMillis());
        VectorClock initialVC = vc.clone();

        client.put("k", new Versioned<String>("v", vc));
        Versioned<String> v = client.get("k");
        assertEquals("GET should return the version set by PUT.", "v", v.getValue());

        VectorClock expected = initialVC.clone();
        expected.incrementVersion(this.nodeId, System.currentTimeMillis());
        assertEquals("The version should be incremented after a put.",
                     expected.getEntries(),
                     ((VectorClock) v.getVersion()).getEntries());
        try {
            client.put("k", new Versioned<String>("v", initialVC));
            fail("Put of obsolete version should throw exception.");
        } catch(ObsoleteVersionException e) {
            // this is good
        }
        // PUT of a concurrent version should succeed
        client.put("k",
                   new Versioned<String>("v2",
                                         new VectorClock().incremented(nodeId + 1,
                                                                       time.getMilliseconds())));
        assertEquals("GET should return the new value set by PUT.", "v2", client.getValue("k"));
        assertEquals("GET should return the new version set by PUT.",
                     expected.incremented(nodeId + 1, time.getMilliseconds()),
                     client.get("k").getVersion());
    }
View Full Code Here

Examples of voldemort.versioning.VectorClock

    }

    @Override
    @Test
    public void testPutIfNotObsolete() {
        VectorClock vc = new VectorClock();
        vc.incrementVersion(this.nodeId, System.currentTimeMillis());
        VectorClock initialVC = vc.clone();

        client.putIfNotObsolete("k", new Versioned<String>("v", vc));
        assertEquals("PUT of non-obsolete version should succeed.", "v", client.getValue("k"));
        assertFalse(client.putIfNotObsolete("k", new Versioned<String>("v2", initialVC)));
        assertEquals("Failed PUT should not change the value stored.", "v", client.getValue("k"));
View Full Code Here

Examples of voldemort.versioning.VectorClock

    }

    @Override
    @Test
    public void testDeleteVersion() {
        VectorClock vc = new VectorClock();
        vc.incrementVersion(this.nodeId, System.currentTimeMillis());
        VectorClock initialVC = vc.clone();

        assertFalse("Delete of non-existant key should be false.", client.delete("k", vc));
        client.put("k", new Versioned<String>("v", vc));
        assertFalse("Delete of a lesser version should be false.", client.delete("k", initialVC));
        assertNotNull("After failed delete, value should still be there.", client.get("k"));
        assertTrue("Delete of k, with the current version should succeed.",
                   client.delete("k", initialVC.incremented(this.nodeId, time.getMilliseconds())));
        assertNull("After a successful delete(k), get(k) should return null.", client.get("k"));
    }
View Full Code Here

Examples of voldemort.versioning.VectorClock

            srcPrimaryResolvingStoreClient.put(entry.getKey(), entry.getValue());
        }

        // generate a conflict on the master partition
        int masterNode = srcStoreInstance.getNodeIdForPartitionId(srcStoreInstance.getMasterPartitionId(conflictKey.getBytes("UTF-8")));
        VectorClock losingClock = new VectorClock(Lists.newArrayList(new ClockEntry((short) 0, 5)),
                                                  System.currentTimeMillis());
        VectorClock winningClock = new VectorClock(Lists.newArrayList(new ClockEntry((short) 1, 5)),
                                                   losingClock.getTimestamp() + 1);
        srcAdminClient.storeOps.putNodeKeyValue(PRIMARY_RESOLVING_STORE_NAME,
                                                new NodeValue<ByteArray, byte[]>(masterNode,
                                                                                 new ByteArray(conflictKey.getBytes("UTF-8")),
                                                                                 new Versioned<byte[]>("losing value".getBytes("UTF-8"),
View Full Code Here

Examples of voldemort.versioning.VectorClock

            srcGloballyResolvingStoreClient.put(entry.getKey(), entry.getValue());
        }

        // generate a conflict on the primary and a secondary
        List<Integer> nodeList = srcStoreInstance.getReplicationNodeList(srcStoreInstance.getMasterPartitionId(conflictKey.getBytes("UTF-8")));
        VectorClock losingClock = new VectorClock(Lists.newArrayList(new ClockEntry((short) 0, 5)),
                                                  System.currentTimeMillis());
        VectorClock winningClock = new VectorClock(Lists.newArrayList(new ClockEntry((short) 1, 5)),
                                                   losingClock.getTimestamp() + 1);
        srcAdminClient.storeOps.putNodeKeyValue(GLOBALLY_RESOLVING_STORE_NAME,
                                                new NodeValue<ByteArray, byte[]>(nodeList.get(0),
                                                                                 new ByteArray(conflictKey.getBytes("UTF-8")),
                                                                                 new Versioned<byte[]>("losing value".getBytes("UTF-8"),
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.