Search in sources :

Example 96 with Versioned

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

the class RoutedStoreTest method testBasicOperations.

private void testBasicOperations(int reads, int writes, int failures, int threads, RoutedStore customRoutedStore, long customSleepTime) throws Exception {
    RoutedStore routedStore = null;
    if (customRoutedStore == null) {
        routedStore = getStore(cluster, reads, writes, threads, failures);
    } else {
        routedStore = customRoutedStore;
    }
    Store<ByteArray, byte[], byte[]> store = new InconsistencyResolvingStore<ByteArray, byte[], byte[]>(routedStore, new VectorClockInconsistencyResolver<byte[]>());
    VectorClock clock = getClock(1);
    Versioned<byte[]> versioned = new Versioned<byte[]>(aValue, clock);
    routedStore.put(aKey, versioned, aTransform);
    waitForOperationToComplete(customSleepTime);
    assertNOrMoreEqual(routedStore, cluster.getNumberOfNodes() - failures, aKey, versioned);
    List<Versioned<byte[]>> found = store.get(aKey, aTransform);
    assertEquals(1, found.size());
    assertEquals(versioned, found.get(0));
    waitForOperationToComplete(customSleepTime);
    assertNOrMoreEqual(routedStore, cluster.getNumberOfNodes() - failures, aKey, versioned);
    assertTrue(routedStore.delete(aKey, versioned.getVersion()));
    waitForOperationToComplete(customSleepTime);
    assertNEqual(routedStore, 0, aKey, versioned);
    assertTrue(!routedStore.delete(aKey, versioned.getVersion()));
}
Also used : InconsistencyResolvingStore(voldemort.store.versioned.InconsistencyResolvingStore) Versioned(voldemort.versioning.Versioned) VectorClock(voldemort.versioning.VectorClock) ByteArray(voldemort.utils.ByteArray)

Example 97 with Versioned

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

the class RocksdbStorageEngineAPITest method generatePutWithConflictionVersions.

public List<Versioned<byte[]>> generatePutWithConflictionVersions(ByteArray key) {
    List<Versioned<byte[]>> versionedList = new ArrayList<Versioned<byte[]>>();
    VectorClock vectorClock1 = new VectorClock();
    vectorClock1.incrementVersion(voldemortConfig.getNodeId(), System.currentTimeMillis());
    Versioned<byte[]> value1 = new Versioned<byte[]>("valueOne".getBytes(), vectorClock1);
    try {
        // Do put
        this.rocksDbStore.put(key, value1, null);
    } catch (PersistenceFailureException pfe) {
        Assert.fail("initial put failed unexpectedly. Exception: " + pfe.getMessage());
    }
    versionedList.add(value1);
    VectorClock vectorClock2 = new VectorClock();
    vectorClock2.incrementVersion(1, System.currentTimeMillis());
    Versioned<byte[]> value2 = new Versioned<byte[]>("valueTwo".getBytes(), vectorClock2);
    try {
        // Do put
        this.rocksDbStore.put(key, value2, null);
    } catch (PersistenceFailureException pfe) {
        Assert.fail("initial put failed unexpectedly. Exception: " + pfe.getMessage());
    }
    versionedList.add(value2);
    return versionedList;
}
Also used : Versioned(voldemort.versioning.Versioned) VectorClock(voldemort.versioning.VectorClock) ArrayList(java.util.ArrayList) PersistenceFailureException(voldemort.store.PersistenceFailureException)

Example 98 with Versioned

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

the class RocksdbStorageEngineAPITest method testVersionedDelete.

@Test
public void testVersionedDelete() {
    logger.info("*********** testing versioned delete ***********");
    ByteArray key = new ByteArray("keyOne".getBytes());
    List<Versioned<byte[]>> conflictingVersions = generatePutWithConflictionVersions(key);
    if (conflictingVersions.size() == 0) {
        Assert.fail("Could not generate conflicting versions ");
    }
    testDelete(key, conflictingVersions.get(0).getVersion());
}
Also used : Versioned(voldemort.versioning.Versioned) ByteArray(voldemort.utils.ByteArray) Test(org.junit.Test)

Example 99 with Versioned

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

the class SetMetadataTest method testSetMetadataStoreXmlVerifyVersionUpdate.

@Test
public void testSetMetadataStoreXmlVerifyVersionUpdate() throws Exception {
    // setup new stores xml
    final String newStoreXMLFilePrefix = "updated.stores";
    final String newStoreXMLFileSuffix = "xml";
    List<StoreDefinition> newStores = new ArrayList<StoreDefinition>();
    for (StoreDefinition storeDef : ClusterTestUtils.getZZZStoreDefsInMemory()) {
        StoreDefinitionBuilder sb = storeDefToBuilder(storeDef);
        Map<Integer, Integer> zrf = sb.getZoneReplicationFactor();
        Integer zone0RepFactor = zrf.get(0);
        zrf.remove(0);
        sb.setReplicationFactor(sb.getReplicationFactor() - zone0RepFactor);
        newStores.add(sb.build());
    }
    File newStoresXMLFolder = TestUtils.createTempDir();
    File newStoreXMLFile = File.createTempFile(newStoreXMLFilePrefix, newStoreXMLFileSuffix, newStoresXMLFolder);
    FileWriter fwriter = new FileWriter(newStoreXMLFile);
    fwriter.write(new StoreDefinitionsMapper().writeStoreList(newStores));
    fwriter.close();
    // check version
    String sysStoreName = SystemStoreConstants.SystemStoreName.voldsys$_metadata_version_persistence.name();
    ByteArray metadataKey = new ByteArray(ByteUtils.getBytes(SystemStoreConstants.VERSIONS_METADATA_KEY, "utf-8"));
    for (VoldemortServer vs : vservers.values()) {
        List<Versioned<byte[]>> result = vs.getStoreRepository().getLocalStore(sysStoreName).get(metadataKey, null);
        String versionInfo = new String(result.get(0).getValue());
        System.out.format("[INITIAL]Version values on node [%d] is: \n %s\n", vs.getIdentityNode().getId(), versionInfo);
        Properties props = new Properties();
        props.load(new ByteArrayInputStream(versionInfo.getBytes()));
        for (StoreDefinition sd : oldStores) {
            if (!props.getProperty(sd.getName()).equals("0")) {
                Assert.fail("Initial version of key [" + sd.getName() + "] on node [" + vs.getIdentityNode().getId() + "] is expected to be 0 but not");
            }
        }
        if (!props.getProperty("cluster.xml").equals("0")) {
            Assert.fail("Final version of key [stores.xml] on node [" + vs.getIdentityNode().getId() + "] is expected to greater than 0 but not");
        }
    }
    // update the stores xml
    VoldemortAdminTool.main(new String[] { "--auto", "--set-metadata", MetadataStore.STORES_KEY, "--set-metadata-value", newStoreXMLFile.getAbsolutePath(), "--url", bsURL });
    // properly
    try {
        Thread.sleep(10000);
    } catch (Exception e) {
    }
    // check version
    for (VoldemortServer vs : vservers.values()) {
        List<Versioned<byte[]>> result = vs.getStoreRepository().getLocalStore(sysStoreName).get(metadataKey, null);
        String versionInfo = new String(result.get(0).getValue());
        System.out.format("[FINAL]Version values on node [%d] is: \n %s\n", vs.getIdentityNode().getId(), versionInfo);
        Properties props = new Properties();
        props.load(new ByteArrayInputStream(versionInfo.getBytes()));
        for (StoreDefinition sd : oldStores) {
            if (!(Long.parseLong(props.getProperty(sd.getName())) > 0)) {
                Assert.fail("Final version of key [" + sd.getName() + "] on node [" + vs.getIdentityNode().getId() + "] is expected to greater than 0 but not");
            }
        }
        if (!(Long.parseLong(props.getProperty("stores.xml")) > 0)) {
            Assert.fail("Final version of key [stores.xml] on node [" + vs.getIdentityNode().getId() + "] is expected to greater than 0 but not");
        }
    }
}
Also used : StoreDefinitionBuilder(voldemort.store.StoreDefinitionBuilder) Versioned(voldemort.versioning.Versioned) FileWriter(java.io.FileWriter) ArrayList(java.util.ArrayList) StoreDefinitionsMapper(voldemort.xml.StoreDefinitionsMapper) VoldemortServer(voldemort.server.VoldemortServer) Properties(java.util.Properties) IOException(java.io.IOException) ByteArrayInputStream(java.io.ByteArrayInputStream) StoreDefinition(voldemort.store.StoreDefinition) ByteArray(voldemort.utils.ByteArray) File(java.io.File) Test(org.junit.Test)

Example 100 with Versioned

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

the class AbstractSocketStoreTest method testVeryLargeValues.

@Test
public void testVeryLargeValues() throws Exception {
    final Store<ByteArray, byte[], byte[]> store = getStore();
    byte[] biggie = new byte[1 * 1024 * 1024];
    ByteArray key = new ByteArray(biggie);
    Random rand = new Random();
    for (int i = 0; i < 10; i++) {
        rand.nextBytes(biggie);
        Versioned<byte[]> versioned = new Versioned<byte[]>(biggie);
        store.put(key, versioned, null);
        Versioned<byte[]> result = store.get(key, null).get(0);
        assertArrayEquals("Get returned different value after put", result.getValue(), versioned.getValue());
        assertTrue(store.delete(key, versioned.getVersion()));
    }
}
Also used : Random(java.util.Random) Versioned(voldemort.versioning.Versioned) ByteArray(voldemort.utils.ByteArray) AbstractByteArrayStoreTest(voldemort.store.AbstractByteArrayStoreTest) Test(org.junit.Test)

Aggregations

Versioned (voldemort.versioning.Versioned)214 ByteArray (voldemort.utils.ByteArray)130 Test (org.junit.Test)88 VectorClock (voldemort.versioning.VectorClock)73 ArrayList (java.util.ArrayList)56 VoldemortException (voldemort.VoldemortException)48 List (java.util.List)36 StoreDefinition (voldemort.store.StoreDefinition)29 HashMap (java.util.HashMap)28 IOException (java.io.IOException)27 Node (voldemort.cluster.Node)27 Pair (voldemort.utils.Pair)25 Slop (voldemort.store.slop.Slop)22 ObsoleteVersionException (voldemort.versioning.ObsoleteVersionException)22 Map (java.util.Map)21 Cluster (voldemort.cluster.Cluster)17 AbstractByteArrayStoreTest (voldemort.store.AbstractByteArrayStoreTest)15 InvalidMetadataException (voldemort.store.InvalidMetadataException)13 PersistenceFailureException (voldemort.store.PersistenceFailureException)13 Version (voldemort.versioning.Version)13