Search in sources :

Example 1 with Attempt

use of voldemort.Attempt in project voldemort by voldemort.

the class ReadOnlyStorageEngineTest method testBackupLogic.

@Test
public void testBackupLogic() throws Exception {
    File dirv0 = new File(dir, "version-0");
    createStoreFiles(dirv0, this.indexEntrySize * 5, 4 * 5 * 10, node, 2);
    ReadOnlyStorageEngine engine = new ReadOnlyStorageEngine("test", strategy, routingStrategy, 0, dir, 0);
    assertVersionsExist(dir, 0);
    // create directory to imitate a fetch state happening concurrently
    // with swap
    File dirv2 = new File(dir, "version-2");
    createStoreFiles(dirv2, this.indexEntrySize * 5, 4 * 5 * 10, node, 2);
    // swap in directory 1
    File dirv1 = new File(dir, "version-1");
    createStoreFiles(dirv1, this.indexEntrySize * 5, 4 * 5 * 10, node, 2);
    engine.swapFiles(dirv1.getAbsolutePath());
    // check latest symbolic link exists
    File latest = new File(dir, "latest");
    assertTrue(latest.exists());
    // ...and points to 1
    assertTrue(latest.getCanonicalPath().contains("version-1"));
    // ...and version-2 is still in fetch state. Assert with backoff since
    // delete may take time
    TestUtils.assertWithBackoff(100, 5000, new Attempt() {

        public void checkCondition() throws Exception, AssertionError {
            assertEquals(ReadOnlyUtils.getVersionDirs(dir).length, 2);
        }
    });
}
Also used : Attempt(voldemort.Attempt) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) VoldemortException(voldemort.VoldemortException) IOException(java.io.IOException) Test(org.junit.Test)

Example 2 with Attempt

use of voldemort.Attempt in project voldemort by voldemort.

the class GossiperTest method testGossiper.

// Protect against this test running forever until the root cause of running
// forever is found.
@Test(timeout = 1800)
public void testGossiper() throws Exception {
    Cluster newCluster = null;
    boolean startedAdditionalServer = false;
    while (!startedAdditionalServer) {
        try {
            newCluster = attemptStartAdditionalServer();
            startedAdditionalServer = true;
        } catch (IOException ioe) {
            logger.warn("Caught an IOException when attempting to start additional server. Will print stacktrace and then attempt to start additional server again.");
            ioe.printStackTrace();
        }
    }
    // Get the new cluster.xml
    AdminClient localAdminClient = getAdminClient(newCluster);
    Versioned<String> versionedClusterXML = localAdminClient.metadataMgmtOps.getRemoteMetadata(3, MetadataStore.CLUSTER_KEY);
    // Increment the version, let what would be the "donor node" know about
    // it to seed the Gossip.
    Version version = versionedClusterXML.getVersion();
    ((VectorClock) version).incrementVersion(3, ((VectorClock) version).getTimestamp() + 1);
    ((VectorClock) version).incrementVersion(0, ((VectorClock) version).getTimestamp() + 1);
    localAdminClient.metadataMgmtOps.updateRemoteMetadata(0, MetadataStore.CLUSTER_KEY, versionedClusterXML);
    localAdminClient.metadataMgmtOps.updateRemoteMetadata(3, MetadataStore.CLUSTER_KEY, versionedClusterXML);
    try {
        Thread.sleep(500);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    }
    // Wait up to five seconds for Gossip to spread
    final Cluster newFinalCluster = newCluster;
    try {
        TestUtils.assertWithBackoff(5000, new Attempt() {

            public void checkCondition() {
                int serversSeen = 0;
                // Now verify that we have gossiped correctly
                for (VoldemortServer server : servers) {
                    Cluster clusterAtServer = server.getMetadataStore().getCluster();
                    int nodeId = server.getMetadataStore().getNodeId();
                    assertEquals("server " + nodeId + " has heard " + " the gossip about number of nodes", clusterAtServer.getNumberOfNodes(), newFinalCluster.getNumberOfNodes());
                    assertEquals("server " + nodeId + " has heard " + " the gossip about partitions", clusterAtServer.getNodeById(nodeId).getPartitionIds(), newFinalCluster.getNodeById(nodeId).getPartitionIds());
                    serversSeen++;
                }
                assertEquals("saw all servers", serversSeen, servers.size());
            }
        });
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    }
}
Also used : Attempt(voldemort.Attempt) Version(voldemort.versioning.Version) VectorClock(voldemort.versioning.VectorClock) Cluster(voldemort.cluster.Cluster) IOException(java.io.IOException) VoldemortServer(voldemort.server.VoldemortServer) AdminClient(voldemort.client.protocol.admin.AdminClient) Test(org.junit.Test)

Example 3 with Attempt

use of voldemort.Attempt in project voldemort by voldemort.

the class ReadOnlyStorageEngineTest method testSwap.

@Test
public void testSwap() throws Exception {
    File versionDir = new File(dir, "version-0");
    createStoreFiles(versionDir, this.indexEntrySize * 5, 4 * 5 * 10, this.node, 2);
    ReadOnlyStorageEngine engine = new ReadOnlyStorageEngine("test", strategy, routingStrategy, 0, dir, 2);
    assertVersionsExist(dir, 0);
    // swap to a new version with latest present
    File newDirv1 = new File(dir, "version-1");
    createStoreFiles(newDirv1, 0, 0, this.node, 2);
    engine.swapFiles(newDirv1.getAbsolutePath());
    assertVersionsExist(dir, 0, 1);
    // swap to a new version with no latest present
    File latestSymLink = new File(dir, "latest");
    latestSymLink.delete();
    File newDirv2 = new File(dir, "version-2");
    createStoreFiles(newDirv2, 0, 0, this.node, 2);
    engine.swapFiles(newDirv2.getAbsolutePath());
    assertVersionsExist(dir, 0, 1, 2);
    // rollback
    engine.rollback(versionDir);
    TestUtils.assertWithBackoff(100, 5000, new Attempt() {

        public void checkCondition() throws Exception, AssertionError {
            assertVersionsExist(dir, 0);
        }
    });
    // test initial open without latest
    engine.close();
    latestSymLink.delete();
    File newDirv100 = new File(dir, "version-100");
    createStoreFiles(newDirv100, 0, 0, this.node, 2);
    File newDirv534 = new File(dir, "version-534");
    createStoreFiles(newDirv534, 0, 0, this.node, 2);
    engine.open(null);
    assertTrue(latestSymLink.getCanonicalPath().contains("version-534"));
    engine.close();
    // test initial open with latest pointing at intermediate version folder
    Utils.symlink(newDirv100.getAbsolutePath(), latestSymLink.getAbsolutePath());
    engine.open(null);
}
Also used : Attempt(voldemort.Attempt) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) VoldemortException(voldemort.VoldemortException) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

IOException (java.io.IOException)3 Test (org.junit.Test)3 Attempt (voldemort.Attempt)3 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 VoldemortException (voldemort.VoldemortException)2 AdminClient (voldemort.client.protocol.admin.AdminClient)1 Cluster (voldemort.cluster.Cluster)1 VoldemortServer (voldemort.server.VoldemortServer)1 VectorClock (voldemort.versioning.VectorClock)1 Version (voldemort.versioning.Version)1