Package voldemort.versioning

Examples of voldemort.versioning.VectorClock


    public void testRepeatedPuts() {
        for(int i = 0; i <= TEST_RUNS; i++) {
            for(int j = 0; j <= 5; j++) {
                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);
            }
        }
View Full Code Here


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

    @Test
    public void testSynchronousPut() {
        for(int i = 0; i <= TEST_RUNS; i++) {
            ByteArray key = getValidKey();
            VectorClock clock = (VectorClock) metadataStore.get(key, null).get(0).getVersion();

            Versioned<byte[]> value1 = new Versioned<byte[]>(getValidValue(key),
                                                             clock.incremented(1, 1));
            Versioned<byte[]> value2 = new Versioned<byte[]>(getValidValue(key),
                                                             clock.incremented(2, 1));

            metadataStore.put(key, value1, null);
            metadataStore.put(key, value2, null);

            assertEquals("Only one metadata value should return", 1, metadataStore.get(key, null)
View Full Code Here

     * @param key
     * @param value
     */
    private void incrementVersionAndPut(MetadataStore metadataStore, String keyString, Object value) {
        ByteArray key = new ByteArray(ByteUtils.getBytes(keyString, "UTF-8"));
        VectorClock current = (VectorClock) metadataStore.getVersions(key).get(0);

        metadataStore.put(keyString,
                          new Versioned<Object>(value,
                                                current.incremented(0, System.currentTimeMillis())));
    }
View Full Code Here

        byte[] keyBytes = ByteUtils.fromHexString(keyBytesString);
        ByteArray key = new ByteArray(keyBytes);

        String versionBytesString = components[1];
        byte[] versionBytes = ByteUtils.fromHexString(versionBytesString);
        Version version = new VectorClock(versionBytes, 0);

        String valueBytesString = components[1];
        byte[] value = ByteUtils.fromHexString(valueBytesString);

        return new Pair<ByteArray, Versioned<byte[]>>(key, new Versioned<byte[]>(value, version));
View Full Code Here

                Versioned<byte[]> value = values.get(0);
                // check version matches
                if(baselineVersions == null) {
                    // expecting base version for all
                    assertEquals("Value version should match",
                                 new VectorClock(),
                                 value.getVersion());
                } else {
                    assertEquals("Value version should match",
                                 baselineVersions.get(entry.getKey()),
                                 value.getVersion());
View Full Code Here

                    this.version = null;
                    this.key = inputStream.readUTF();
                    this.value = null;
                    break;
                case VoldemortOpCode.PUT_OP_CODE:
                    this.version = new VectorClock(bytes, 1);
                    this.key = inputStream.readUTF();
                    int valueSize = inputStream.readInt();
                    this.value = new byte[valueSize];
                    ByteUtils.read(inputStream, this.value);
                    break;
                case VoldemortOpCode.DELETE_OP_CODE:
                    this.version = new VectorClock(bytes, 1);
                    this.key = inputStream.readUTF();
                    this.value = null;
                    break;
                default:
                    throw new SerializationException("Unknown opcode: " + bytes[0]);
View Full Code Here

        byte[] objectBytes = innerSerializer.toBytes(versioned.getValue());
        return ByteUtils.cat(versionBytes, objectBytes);
    }

    public Versioned<T> toObject(byte[] bytes) {
        VectorClock vectorClock = getVectorClock(bytes);

        int size = 1;
        if(vectorClock != null)
            size = vectorClock.sizeInBytes();

        T t = innerSerializer.toObject(ByteUtils.copy(bytes, size, bytes.length));
        return new Versioned<T>(t, vectorClock);
    }
View Full Code Here

        return getVectorClock(bytes);
    }

    private VectorClock getVectorClock(byte[] bytes) {
        if(bytes[0] >= 0)
            return new VectorClock(bytes);
        return null;
    }
View Full Code Here

            if(this.cachedVersion == null) {
                File versionFile = getVersionFile();
                if(versionFile.exists()) {
                    // read the version file and return version.
                    String hexCode = FileUtils.readFileToString(versionFile, "UTF-8");
                    this.cachedVersion = new VectorClock(Hex.decodeHex(hexCode.toCharArray()));
                }
            }
            return this.cachedVersion;
        } catch(Exception e) {
            throw new VoldemortException("Failed to read Version for file :" + getName(), e);
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.