Search in sources :

Example 21 with OrientBaseGraph

use of com.tinkerpop.blueprints.impls.orient.OrientBaseGraph in project orientdb by orientechnologies.

the class TestAsyncReplMode2ServersAddEdge method dbClient2.

protected void dbClient2() {
    sleep(500);
    synchronized (LOCK) {
        OrientBaseGraph graph = new OrientGraph(getLocalURL2());
        try {
            sleep(500);
            OrientVertex parentV1 = graph.getVertex(parentV1Id);
            assertEquals(NUM_OF_LOOP_ITERATIONS + 1, parentV1.getRecord().getVersion());
        } catch (Throwable e) {
            if (exceptionInThread == null) {
                exceptionInThread = e;
            }
        } finally {
            System.out.println("Shutting down");
            graph.shutdown();
            LOCK.notifyAll();
        }
    }
}
Also used : OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OrientBaseGraph(com.tinkerpop.blueprints.impls.orient.OrientBaseGraph)

Example 22 with OrientBaseGraph

use of com.tinkerpop.blueprints.impls.orient.OrientBaseGraph in project orientdb by orientechnologies.

the class TestAsyncReplMode2ServersOverflow method exec.

protected void exec(final String iClient) {
    counter.countDown();
    try {
        counter.await();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    OrientBaseGraph graph = new OrientGraphNoTx(getLocalURL());
    try {
        int i = 0;
        for (; i < TOTAL; ++i) {
            final OrientVertex v = graph.addVertex(null);
            Assert.assertTrue(v.getIdentity().isPersistent());
        }
    } catch (Throwable e) {
        if (exceptionInThread == null)
            exceptionInThread = e;
    } finally {
        System.out.println("Shutting down");
        graph.shutdown();
    }
}
Also used : OrientGraphNoTx(com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OrientBaseGraph(com.tinkerpop.blueprints.impls.orient.OrientBaseGraph)

Example 23 with OrientBaseGraph

use of com.tinkerpop.blueprints.impls.orient.OrientBaseGraph in project orientdb by orientechnologies.

the class TestDistributedDatabaseRepair method testNoWinner.

private void testNoWinner(OrientGraphFactory localFactory0, OrientGraphFactory localFactory1, OrientGraphFactory localFactory2) throws Exception {
    OrientBaseGraph graph = localFactory0.getTx();
    OrientVertex product;
    try {
        product = graph.addVertex("class:ProductType");
        product.setProperty("status", "ok");
    } finally {
        graph.shutdown();
    }
    banner("CORRUPT A RECORD IN SERVER 0");
    graph = localFactory0.getNoTx();
    try {
        final OrientVertex product2 = graph.getVertex(product.getIdentity());
        product2.getRecord().field("status", "corrupted0");
        final ODistributedResponse result = updateRemoteRecord(0, product2.getRecord(), new String[] { serverInstance.get(0).getServerInstance().getDistributedManager().getLocalNodeName() });
        Assert.assertFalse(result.getPayload() instanceof Throwable);
    } finally {
        graph.shutdown();
    }
    banner("CORRUPT A RECORD IN SERVER 1");
    graph = localFactory1.getNoTx();
    try {
        final OrientVertex product2 = graph.getVertex(product.getIdentity());
        product2.getRecord().field("status", "corrupted1");
        ODistributedResponse result = updateRemoteRecord(1, product2.getRecord(), new String[] { serverInstance.get(1).getServerInstance().getDistributedManager().getLocalNodeName() });
        Assert.assertFalse(result.getPayload() instanceof Throwable);
    } finally {
        graph.shutdown();
    }
    serverInstance.get(0).getServerInstance().getDistributedManager().getMessageService().getDatabase(getDatabaseName()).getDatabaseRepairer().enqueueRepairRecord((ORecordId) product.getIdentity());
    Thread.sleep(3000);
    // TEST NOTHING IS CHANGED
    graph = localFactory0.getNoTx();
    try {
        final OrientVertex product2 = graph.getVertex(product.getIdentity());
        Assert.assertEquals("corrupted0", product2.getProperty("status"));
    } finally {
        graph.shutdown();
    }
    graph = localFactory1.getNoTx();
    try {
        final OrientVertex product2 = graph.getVertex(product.getIdentity());
        Assert.assertEquals("corrupted1", product2.getProperty("status"));
    } finally {
        graph.shutdown();
    }
    graph = localFactory2.getNoTx();
    try {
        final OrientVertex product2 = graph.getVertex(product.getIdentity());
        Assert.assertEquals("ok", product2.getProperty("status"));
    } finally {
        graph.shutdown();
    }
}
Also used : OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OrientBaseGraph(com.tinkerpop.blueprints.impls.orient.OrientBaseGraph)

Example 24 with OrientBaseGraph

use of com.tinkerpop.blueprints.impls.orient.OrientBaseGraph in project orientdb by orientechnologies.

the class TestDistributedDatabaseRepair method testRepairClusters.

/**
   * Breaks a cluster by creating new records only on certain servers
   */
private void testRepairClusters(OrientGraphFactory localFactory0, OrientGraphFactory localFactory1, OrientGraphFactory localFactory2) throws Exception {
    Thread.sleep(2000);
    OrientBaseGraph graph = localFactory0.getNoTx();
    graph.createVertexType("Employee");
    graph.shutdown();
    final ODistributedConfiguration cfg = serverInstance.get(1).getServerInstance().getDistributedManager().getDatabaseConfiguration(getDatabaseName());
    // FIND THE LOCAL CLUSTER
    String localCluster = null;
    final Set<String> owner = cfg.getClustersOwnedByServer(serverInstance.get(1).getServerInstance().getDistributedManager().getLocalNodeName());
    for (String s : owner) {
        if (s.toLowerCase().startsWith("employee")) {
            localCluster = s;
            break;
        }
    }
    graph = localFactory1.getTx();
    OrientVertex employee;
    try {
        employee = graph.addVertex("Employee", localCluster);
        employee.setProperty("status", "ok");
    } finally {
        graph.shutdown();
    }
    banner("CREATE 10 RECORDS ONLY ON local (1) SERVER and 0");
    graph = localFactory1.getTx();
    try {
        for (int i = 0; i < 10; ++i) {
            OrientVertex v = graph.addVertex("Employee", localCluster);
            v.setProperty("status", "onlyServer0and1");
            graph.getRawGraph().getStorage().getUnderlying().createRecord((ORecordId) v.getRecord().getIdentity(), v.getRecord().toStream(), v.getRecord().getVersion(), ODocument.RECORD_TYPE, 0, null);
            final ODistributedResponse result = createRemoteRecord(0, v.getRecord(), new String[] { serverInstance.get(0).getServerInstance().getDistributedManager().getLocalNodeName() });
            Assert.assertFalse(result.getPayload() instanceof Throwable);
        }
    } finally {
        graph.rollback();
    }
    banner("CREATE 10 RECORDS ONLY ON SERVER 0");
    graph = localFactory1.getTx();
    try {
        for (int i = 0; i < 10; ++i) {
            OrientVertex v = graph.addVertex("Employee", localCluster);
            v.setProperty("status", "onlyServer0and1");
            graph.getRawGraph().getStorage().getUnderlying().createRecord((ORecordId) v.getRecord().getIdentity(), v.getRecord().toStream(), v.getRecord().getVersion(), ODocument.RECORD_TYPE, 0, null);
        }
    } finally {
        graph.rollback();
    }
    // TRY TO CREATE A RECORD TO START THE REPAIR
    graph = localFactory1.getTx();
    try {
        OrientVertex v = graph.addVertex("Employee", localCluster);
        v.setProperty("status", "check");
        graph.commit();
    } catch (ODistributedOperationException e) {
        Assert.assertTrue(true);
    } finally {
        graph.shutdown();
    }
    Thread.sleep(5000);
    banner("CHECK RECORDS...");
    graph = localFactory0.getNoTx();
    try {
        Assert.assertEquals(21, graph.countVertices("Employee"));
    } finally {
        graph.shutdown();
    }
    graph = localFactory1.getNoTx();
    try {
        Assert.assertEquals(21, graph.countVertices("Employee"));
    } finally {
        graph.shutdown();
    }
    graph = localFactory2.getNoTx();
    try {
        Assert.assertEquals(21, graph.countVertices("Employee"));
    } finally {
        graph.shutdown();
    }
}
Also used : OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OrientBaseGraph(com.tinkerpop.blueprints.impls.orient.OrientBaseGraph) ODistributedOperationException(com.orientechnologies.orient.server.distributed.task.ODistributedOperationException)

Example 25 with OrientBaseGraph

use of com.tinkerpop.blueprints.impls.orient.OrientBaseGraph in project orientdb by orientechnologies.

the class TestDistributedDatabaseRepair method testWinnerIsMajorityPlusVersion.

private void testWinnerIsMajorityPlusVersion(OrientGraphFactory localFactory0, OrientGraphFactory localFactory1, OrientGraphFactory localFactory2) throws Exception {
    OrientBaseGraph graph = localFactory0.getTx();
    OrientVertex product;
    try {
        product = graph.addVertex("class:ProductType");
        product.setProperty("status", "ok");
    } finally {
        graph.shutdown();
    }
    banner("CORRUPT A RECORD IN SERVER 0");
    graph = localFactory0.getNoTx();
    try {
        final OrientVertex product2 = graph.getVertex(product.getIdentity());
        product2.getRecord().field("status", "corrupted0");
        final ODistributedResponse result = updateRemoteRecord(0, product2.getRecord(), new String[] { serverInstance.get(0).getServerInstance().getDistributedManager().getLocalNodeName() });
        Assert.assertFalse(result.getPayload() instanceof Throwable);
    } finally {
        graph.shutdown();
    }
    banner("CORRUPT A RECORD IN SERVER 1 WITH THE HIGHEST VERSION (=WINNER)");
    graph = localFactory1.getNoTx();
    try {
        final OrientVertex product2 = graph.getVertex(product.getIdentity());
        product2.getRecord().field("status", "thisIsTheMostRecent");
        ORecordInternal.setVersion(product2.getRecord(), ORecordVersionHelper.setRollbackMode(1000));
        ODistributedResponse result = updateRemoteRecord(1, product2.getRecord(), new String[] { serverInstance.get(1).getServerInstance().getDistributedManager().getLocalNodeName() });
        Assert.assertFalse(result.getPayload() instanceof Throwable);
    } finally {
        graph.shutdown();
    }
    serverInstance.get(0).getServerInstance().getDistributedManager().getMessageService().getDatabase(getDatabaseName()).getDatabaseRepairer().enqueueRepairRecord((ORecordId) product.getIdentity());
    Thread.sleep(3000);
    banner("EXPECTING AUTO RECOVER ON ALL NODES...");
    // TEST RECOVER IS CHANGED
    graph = localFactory0.getNoTx();
    try {
        final OrientVertex product2 = graph.getVertex(product.getIdentity());
        Assert.assertEquals("thisIsTheMostRecent", product2.getProperty("status"));
        Assert.assertEquals(1000, product2.getRecord().getVersion());
    } finally {
        graph.shutdown();
    }
    graph = localFactory1.getNoTx();
    try {
        final OrientVertex product2 = graph.getVertex(product.getIdentity());
        Assert.assertEquals("thisIsTheMostRecent", product2.getProperty("status"));
        Assert.assertEquals(1000, product2.getRecord().getVersion());
    } finally {
        graph.shutdown();
    }
    graph = localFactory2.getNoTx();
    try {
        final OrientVertex product2 = graph.getVertex(product.getIdentity());
        Assert.assertEquals("thisIsTheMostRecent", product2.getProperty("status"));
        Assert.assertEquals(1000, product2.getRecord().getVersion());
    } finally {
        graph.shutdown();
    }
}
Also used : OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OrientBaseGraph(com.tinkerpop.blueprints.impls.orient.OrientBaseGraph)

Aggregations

OrientBaseGraph (com.tinkerpop.blueprints.impls.orient.OrientBaseGraph)70 OrientVertex (com.tinkerpop.blueprints.impls.orient.OrientVertex)40 OrientGraph (com.tinkerpop.blueprints.impls.orient.OrientGraph)19 Vertex (com.tinkerpop.blueprints.Vertex)13 OrientGraphNoTx (com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx)13 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)11 OrientGraphFactory (com.tinkerpop.blueprints.impls.orient.OrientGraphFactory)8 Test (org.junit.Test)8 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)7 Edge (com.tinkerpop.blueprints.Edge)7 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)6 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)5 OGraphRepair (com.tinkerpop.blueprints.impls.orient.OGraphRepair)5 ArrayList (java.util.ArrayList)5 ONeedRetryException (com.orientechnologies.common.concur.ONeedRetryException)4 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)4 OConcurrentModificationException (com.orientechnologies.orient.core.exception.OConcurrentModificationException)4 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)4 ORecordDuplicatedException (com.orientechnologies.orient.core.storage.ORecordDuplicatedException)4 OrientEdge (com.tinkerpop.blueprints.impls.orient.OrientEdge)4