Search in sources :

Example 86 with OrientVertex

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

the class TestAsyncReplMode2Servers2OpsCommitConcurrent method dbClient1.

protected void dbClient1() {
    // OGlobalConfiguration.LOG_CONSOLE_LEVEL.setValue("FINEST");
    OrientBaseGraph graph = new OrientGraph(getLocalURL());
    OrientVertex vertex1 = graph.addVertex("vertextype", (String) null);
    graph.commit();
    graph.shutdown();
    vertex1Id = vertex1.getIdentity();
    exec("client1");
}
Also used : OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OrientBaseGraph(com.tinkerpop.blueprints.impls.orient.OrientBaseGraph)

Example 87 with OrientVertex

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

the class TestAsyncReplMode2Servers2OpsCommitConcurrent method exec.

protected void exec(final String iClient) {
    counter.countDown();
    try {
        counter.await();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    OrientBaseGraph graph = new OrientGraph(getLocalURL());
    OrientVertex vertex1 = graph.getVertex(vertex1Id);
    try {
        int i = 0;
        for (; i < TOTAL; ++i) {
            for (int retry = 0; retry < 20; ++retry) {
                try {
                    OrientVertex vertex2 = graph.addVertex("vertextype", (String) null);
                    vertex1.addEdge("edgetype", vertex2);
                    graph.commit();
                    System.out.println(iClient + " - successfully committed version: " + vertex1.getRecord().getVersion() + " retry: " + retry);
                    break;
                } catch (ONeedRetryException e) {
                    System.out.println(iClient + " - caught conflict, reloading vertex. v=" + vertex1.getRecord().getVersion() + " retry: " + retry);
                    graph.rollback();
                    vertex1.reload();
                }
            }
        }
        // STATISTICALLY HERE AT LEAST ONE CONFLICT HAS BEEN RECEIVED
        vertex1.reload();
        Assert.assertTrue(vertex1.getRecord().getVersion() > TOTAL + 1);
        Assert.assertEquals(TOTAL, i);
    } catch (Throwable e) {
        if (exceptionInThread == null)
            exceptionInThread = e;
    } finally {
        System.out.println("Shutting down");
        graph.shutdown();
    }
}
Also used : OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) ONeedRetryException(com.orientechnologies.common.concur.ONeedRetryException) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OrientBaseGraph(com.tinkerpop.blueprints.impls.orient.OrientBaseGraph)

Example 88 with OrientVertex

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

the class TestAsyncReplMode2ServersAddEdge method dbClient1.

protected void dbClient1() {
    OGlobalConfiguration.LOG_CONSOLE_LEVEL.setValue("FINEST");
    synchronized (LOCK) {
        OrientBaseGraph graph = new OrientGraph(getLocalURL());
        try {
            OrientVertex parentV1 = graph.addVertex("vertextype", (String) null);
            graph.commit();
            assertEquals(1, parentV1.getRecord().getVersion());
            parentV1Id = parentV1.getId();
            for (int i = 0; i < NUM_OF_LOOP_ITERATIONS; i++) {
                Vertex childV = graph.addVertex("vertextype", (String) null);
                graph.commit();
                assertEquals(1, ((OrientVertex) childV).getRecord().getVersion());
                parentV1.addEdge("edgetype", childV);
                graph.commit();
                OLogManager.instance().error(this, "parentV1 %s v%d should be v%d", parentV1.getIdentity(), parentV1.getRecord().getVersion(), i + 2);
                assertEquals(i + 2, ((OrientVertex) parentV1).getRecord().getVersion());
                assertEquals(2, ((OrientVertex) childV).getRecord().getVersion());
            }
            pause();
        } catch (Throwable e) {
            OLogManager.instance().error(this, "Exception", e);
            if (exceptionInThread == null) {
                exceptionInThread = e;
            }
        } finally {
            System.out.println("Shutting down");
            graph.shutdown();
            LOCK.notifyAll();
        }
    }
}
Also used : OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) Vertex(com.tinkerpop.blueprints.Vertex) OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OrientBaseGraph(com.tinkerpop.blueprints.impls.orient.OrientBaseGraph)

Example 89 with OrientVertex

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

the class TestShardingManualSync method executeTest.

@Override
protected void executeTest() throws Exception {
    final OrientGraphFactory localFactoryEurope = new OrientGraphFactory("plocal:target/server0/databases/" + getDatabaseName());
    OrientGraphFactory localFactoryUsa = new OrientGraphFactory("plocal:target/server1/databases/" + getDatabaseName());
    final ORID v1Identity;
    OrientGraphNoTx graphNoTxEurope = localFactoryEurope.getNoTx();
    try {
        final OrientVertexType clientType = graphNoTxEurope.createVertexType("Client-Type");
        for (int i = 1; i < serverInstance.size(); ++i) {
            final String serverName = serverInstance.get(i).getServerInstance().getDistributedManager().getLocalNodeName();
            clientType.addCluster("client_" + serverName);
        }
        final OrientVertex v1 = graphNoTxEurope.addVertex("class:Client-Type");
        v1Identity = v1.getIdentity();
        log("Created vertex " + v1Identity + "...");
    } finally {
        graphNoTxEurope.shutdown();
    }
    OrientGraphNoTx graphNoTxUsa = localFactoryUsa.getNoTx();
    try {
        Assert.assertEquals(1, graphNoTxUsa.countVertices());
    } finally {
        graphNoTxUsa.shutdown();
        localFactoryUsa.close();
    }
    final String clusterName;
    graphNoTxEurope = localFactoryEurope.getNoTx();
    try {
        Assert.assertEquals(1, graphNoTxEurope.countVertices());
        // CHANGE THE WRITE QUORUM = 1
        final OModifiableDistributedConfiguration dCfg = serverInstance.get(0).server.getDistributedManager().getDatabaseConfiguration(getDatabaseName()).modify();
        ODocument newCfg = dCfg.getDocument().field("writeQuorum", 1);
        serverInstance.get(0).server.getDistributedManager().updateCachedDatabaseConfiguration(getDatabaseName(), dCfg, true);
        // CREATE A NEW RECORD ON SERVER 0 BYPASSING REPLICATION
        final ODocument v2 = new ODocument("Client");
        ((ORecordId) v2.getIdentity()).setClusterId(v1Identity.getClusterId());
        ((ORecordId) v2.getIdentity()).setClusterPosition(v1Identity.getClusterPosition() + 1);
        final Object result = createRemoteRecord(0, v2, new String[] { serverInstance.get(0).getServerInstance().getDistributedManager().getLocalNodeName() });
        Assert.assertFalse(result instanceof Throwable);
        Assert.assertEquals(2, graphNoTxEurope.countVertices());
        clusterName = graphNoTxEurope.getRawGraph().getClusterNameById(v2.getIdentity().getClusterId());
        Assert.assertEquals(2, graphNoTxEurope.countVertices());
    } finally {
        graphNoTxEurope.shutdown();
    }
    // TEST SECOND VERTEX IS MISSING ON USA NODE
    localFactoryUsa = new OrientGraphFactory("plocal:target/server1/databases/" + getDatabaseName());
    graphNoTxUsa = localFactoryUsa.getNoTx();
    try {
        Assert.assertEquals(1, graphNoTxUsa.countVertices());
        log("Manually syncing cluster client-type of node USA...");
        graphNoTxUsa.command(new OCommandSQL("ha sync cluster `" + clusterName + "`")).execute();
        Assert.assertEquals(2, graphNoTxUsa.countVertices());
    } finally {
        graphNoTxUsa.shutdown();
    }
    localFactoryEurope.close();
    localFactoryUsa.close();
}
Also used : OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) ORecordId(com.orientechnologies.orient.core.id.ORecordId) OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OrientGraphFactory(com.tinkerpop.blueprints.impls.orient.OrientGraphFactory) OrientGraphNoTx(com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx) OrientVertexType(com.tinkerpop.blueprints.impls.orient.OrientVertexType) ORID(com.orientechnologies.orient.core.id.ORID) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 90 with OrientVertex

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

the class AsyncIndexRemoteTest method dbClient1.

protected void dbClient1() {
    OrientBaseGraph graph = new OrientGraphNoTx(getRemoteURL());
    try {
        graph.command(new OCommandSQL("create class SMS")).execute();
        graph.command(new OCommandSQL("create property SMS.type string")).execute();
        graph.command(new OCommandSQL("create property SMS.lang string")).execute();
        graph.command(new OCommandSQL("create property SMS.source integer")).execute();
        graph.command(new OCommandSQL("create property SMS.content string")).execute();
        graph.command(new OCommandSQL("alter property SMS.lang min 2")).execute();
        graph.command(new OCommandSQL("alter property SMS.lang max 2")).execute();
        graph.command(new OCommandSQL("create index sms_keys ON SMS (type, lang) unique")).execute();
        graph.command(new OCommandSQL("insert into sms (type, lang, source, content) values ( 'notify', 'en', 1, 'This is a test')")).execute();
        try {
            graph.command(new OCommandSQL("insert into sms (type, lang, source, content) values ( 'notify', 'en', 1, 'This is a test')")).execute();
            Assert.fail("violated unique index was not raised");
        } catch (ORecordDuplicatedException e) {
        }
        final Iterable<OrientVertex> result = graph.command(new OSQLSynchQuery<OrientVertex>("select count(*) from SMS")).execute();
        Assert.assertEquals(1, ((Number) result.iterator().next().getProperty("count")).intValue());
    } catch (Throwable e) {
        if (exceptionInThread == null) {
            exceptionInThread = e;
        }
    } finally {
        OLogManager.instance().info(this, "Shutting down db1");
        graph.shutdown();
    }
    // CHECK ON THE 2ND NODE
    OrientBaseGraph graph2 = new OrientGraphNoTx(getRemoteURL2());
    try {
        try {
            graph2.command(new OCommandSQL("insert into sms (type, lang, source, content) values ( 'notify', 'en', 1, 'This is a test')")).execute();
            Assert.fail("violated unique index was not raised");
        } catch (ORecordDuplicatedException e) {
        }
        final Iterable<OrientVertex> result = graph2.command(new OSQLSynchQuery<OrientVertex>("select count(*) from SMS")).execute();
        Assert.assertEquals(1, ((Number) result.iterator().next().getProperty("count")).intValue());
    } catch (Throwable e) {
        if (exceptionInThread == null) {
            exceptionInThread = e;
        }
    } finally {
        OLogManager.instance().info(this, "Shutting down db2");
        graph2.shutdown();
    }
    // CHECK ON THE 2ND NODE
    OrientBaseGraph graph3 = new OrientGraphNoTx(getRemoteURL3());
    try {
        try {
            graph3.command(new OCommandSQL("insert into sms (type, lang, source, content) values ( 'notify', 'en', 1, 'This is a test')")).execute();
            Assert.fail("violated unique index was not raised");
        } catch (ORecordDuplicatedException e) {
        }
        final Iterable<OrientVertex> result = graph3.command(new OSQLSynchQuery<OrientVertex>("select count(*) from SMS")).execute();
        Assert.assertEquals(1, ((Number) result.iterator().next().getProperty("count")).intValue());
    } catch (Throwable e) {
        if (exceptionInThread == null) {
            exceptionInThread = e;
        }
    } finally {
        OLogManager.instance().info(this, "Shutting down db3");
        graph3.shutdown();
    }
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) ORecordDuplicatedException(com.orientechnologies.orient.core.storage.ORecordDuplicatedException) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) OrientGraphNoTx(com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OrientBaseGraph(com.tinkerpop.blueprints.impls.orient.OrientBaseGraph)

Aggregations

OrientVertex (com.tinkerpop.blueprints.impls.orient.OrientVertex)155 Test (org.junit.Test)73 OrientGraph (com.tinkerpop.blueprints.impls.orient.OrientGraph)42 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)40 OrientBaseGraph (com.tinkerpop.blueprints.impls.orient.OrientBaseGraph)37 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)35 OrientGraphNoTx (com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx)26 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)25 OrientEdge (com.tinkerpop.blueprints.impls.orient.OrientEdge)25 Vertex (com.tinkerpop.blueprints.Vertex)24 HashMap (java.util.HashMap)20 OBasicCommandContext (com.orientechnologies.orient.core.command.OBasicCommandContext)13 OrientGraphFactory (com.tinkerpop.blueprints.impls.orient.OrientGraphFactory)13 OrientVertexType (com.tinkerpop.blueprints.impls.orient.OrientVertexType)13 Edge (com.tinkerpop.blueprints.Edge)12 OConcurrentModificationException (com.orientechnologies.orient.core.exception.OConcurrentModificationException)10 GraphNoTxAbstractTest (com.orientechnologies.orient.graph.GraphNoTxAbstractTest)9 ORID (com.orientechnologies.orient.core.id.ORID)7 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)7 GraphTxAbstractTest (com.orientechnologies.orient.graph.GraphTxAbstractTest)7