Search in sources :

Example 61 with OrientBaseGraph

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

the class OInternalGraphImporter method runImport.

public void runImport(String inputFile, String dbURL) throws IOException, FileNotFoundException {
    if (inputFile == null)
        throw new OSystemException("needed an input file as first argument");
    if (dbURL == null)
        throw new OSystemException("needed an database location as second argument");
    ODatabaseDocumentTx db = new ODatabaseDocumentTx(dbURL);
    ODatabaseHelper.deleteDatabase(db, db.getStorage().getType());
    OrientBaseGraph g = OrientGraphFactory.getNoTxGraphImplFactory().getGraph(dbURL);
    System.out.println("Importing graph from file '" + inputFile + "' into database: " + g + "...");
    final long startTime = System.currentTimeMillis();
    OConsoleDatabaseApp console = new OGremlinConsole(new String[] { "import database " + inputFile }).setCurrentDatabase(g.getRawGraph());
    console.run();
    System.out.println("Imported in " + (System.currentTimeMillis() - startTime) + "ms. Vertexes: " + g.countVertices());
    g.command(new OCommandSQL("alter database TIMEZONE 'GMT'")).execute();
    g.command(new OCommandSQL("alter database LOCALECOUNTRY 'UK'")).execute();
    g.command(new OCommandSQL("alter database LOCALELANGUAGE 'EN'")).execute();
    g.shutdown();
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OSystemException(com.orientechnologies.common.exception.OSystemException) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OrientBaseGraph(com.tinkerpop.blueprints.impls.orient.OrientBaseGraph) OConsoleDatabaseApp(com.orientechnologies.orient.console.OConsoleDatabaseApp)

Example 62 with OrientBaseGraph

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

the class OGraphShortestPathWorkload method execute.

@Override
public void execute(final OStressTesterSettings settings, final ODatabaseIdentifier databaseIdentifier) {
    connectionStrategy = settings.loadBalancing;
    // RETRIEVE THE STARTING VERTICES
    final OrientGraphNoTx g = getGraphNoTx(databaseIdentifier);
    try {
        for (OIdentifiable id : g.getRawGraph().browseClass("V")) {
            startingVertices.add(id.getIdentity());
            if (limit > -1 && startingVertices.size() >= limit)
                break;
        }
    } finally {
        g.shutdown();
    }
    result.total = startingVertices.size();
    executeOperation(databaseIdentifier, result, settings, new OCallable<Void, OBaseWorkLoadContext>() {

        @Override
        public Void call(final OBaseWorkLoadContext context) {
            final OWorkLoadContext graphContext = ((OWorkLoadContext) context);
            final OrientBaseGraph graph = graphContext.graph;
            for (int i = 0; i < startingVertices.size(); ++i) {
                final Iterable<OrientVertex> commandResult = graph.command(new OCommandSQL("select shortestPath(?,?, 'both')")).execute(startingVertices.get(context.currentIdx), startingVertices.get(i));
                for (OrientVertex v : commandResult) {
                    Collection depth = v.getRecord().field("shortestPath");
                    if (depth != null && !depth.isEmpty()) {
                        totalDepth.addAndGet(depth.size());
                        long max = maxDepth.get();
                        while (depth.size() > max) {
                            if (maxDepth.compareAndSet(max, depth.size()))
                                break;
                            max = maxDepth.get();
                        }
                    } else
                        notConnected.incrementAndGet();
                }
            }
            result.current.incrementAndGet();
            return null;
        }
    });
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) Collection(java.util.Collection) OrientGraphNoTx(com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OrientBaseGraph(com.tinkerpop.blueprints.impls.orient.OrientBaseGraph) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable)

Example 63 with OrientBaseGraph

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

the class OGraphInsertWorkload method init.

@Override
protected void init(OBaseWorkLoadContext context) {
    synchronized (getClass()) {
        final OrientBaseGraph g = ((OWorkLoadContext) context).graph;
        if (g.getVertexType(className) == null) {
            try {
                final OrientVertexType c = g.createVertexType(className);
                c.createProperty("_id", OType.LONG);
                c.createProperty("ts", OType.DATETIME);
            } catch (OSchemaException e) {
            // IGNORE IT, ALREADY CREATED
            }
        }
    }
}
Also used : OrientVertexType(com.tinkerpop.blueprints.impls.orient.OrientVertexType) OrientBaseGraph(com.tinkerpop.blueprints.impls.orient.OrientBaseGraph) OSchemaException(com.orientechnologies.orient.core.exception.OSchemaException)

Example 64 with OrientBaseGraph

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

the class OGraphInsertWorkload method execute.

@Override
public void execute(final OStressTesterSettings settings, final ODatabaseIdentifier databaseIdentifier) {
    connectionStrategy = settings.loadBalancing;
    final List<OBaseWorkLoadContext> contexts = executeOperation(databaseIdentifier, resultVertices, settings, new OCallable<Void, OBaseWorkLoadContext>() {

        @Override
        public Void call(final OBaseWorkLoadContext context) {
            final OWorkLoadContext graphContext = ((OWorkLoadContext) context);
            final OrientBaseGraph graph = graphContext.graph;
            final OrientVertex v = graph.addVertex("class:" + className, "_id", resultVertices.current.get(), "ts", System.currentTimeMillis());
            if (graphContext.lastVertexToConnect != null) {
                v.addEdge("E", graphContext.lastVertexToConnect);
                resultEdges.current.incrementAndGet();
                graphContext.lastVertexEdges++;
                if (graphContext.lastVertexEdges > factor) {
                    graphContext.lastVertexEdges = 0;
                    if (strategy == STRATEGIES.LAST)
                        graphContext.lastVertexToConnect = v;
                    else if (strategy == STRATEGIES.RANDOM) {
                        do {
                            final int[] totalClusters = graph.getVertexBaseType().getClusterIds();
                            final int randomCluster = totalClusters[new Random().nextInt(totalClusters.length)];
                            long totClusterRecords = graph.getRawGraph().countClusterElements(randomCluster);
                            if (totClusterRecords > 0) {
                                final ORecordId randomRid = new ORecordId(randomCluster, new Random().nextInt((int) totClusterRecords));
                                graphContext.lastVertexToConnect = graph.getVertex(randomRid);
                                break;
                            }
                        } while (true);
                    } else if (strategy == STRATEGIES.SUPERNODE) {
                        final int[] totalClusters = graph.getVertexBaseType().getClusterIds();
                        final int firstCluster = totalClusters[0];
                        long totClusterRecords = graph.getRawGraph().countClusterElements(firstCluster);
                        if (totClusterRecords > 0) {
                            final ORecordId randomRid = new ORecordId(firstCluster, 0);
                            graphContext.lastVertexToConnect = graph.getVertex(randomRid);
                        }
                    }
                }
            } else
                graphContext.lastVertexToConnect = v;
            resultVertices.current.incrementAndGet();
            return null;
        }
    });
    final OrientBaseGraph graph = settings.operationsPerTransaction > 0 ? getGraph(databaseIdentifier) : getGraphNoTx(databaseIdentifier);
    try {
        // CONNECTED ALL THE SUB GRAPHS
        OrientVertex lastVertex = null;
        for (OBaseWorkLoadContext context : contexts) {
            for (int retry = 0; retry < 100; ++retry) try {
                if (lastVertex != null)
                    lastVertex.addEdge("E", ((OWorkLoadContext) context).lastVertexToConnect);
                lastVertex = ((OWorkLoadContext) context).lastVertexToConnect;
            } catch (ONeedRetryException e) {
                if (lastVertex.getIdentity().isPersistent())
                    lastVertex.reload();
                if (((OWorkLoadContext) context).lastVertexToConnect.getIdentity().isPersistent())
                    ((OWorkLoadContext) context).lastVertexToConnect.reload();
            }
        }
    } finally {
        graph.shutdown();
    }
}
Also used : OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OrientBaseGraph(com.tinkerpop.blueprints.impls.orient.OrientBaseGraph) ORecordId(com.orientechnologies.orient.core.id.ORecordId) Random(java.util.Random) ONeedRetryException(com.orientechnologies.common.concur.ONeedRetryException)

Example 65 with OrientBaseGraph

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

the class TestGraphRecovering method testRecoverPerfectGraphNonLW.

@Test
public void testRecoverPerfectGraphNonLW() {
    final OrientBaseGraph g = new OrientGraphNoTx("memory:testRecoverPerfectGraphNonLW");
    try {
        init(g, false);
        final TestListener eventListener = new TestListener();
        new OGraphRepair().setEventListener(eventListener).repair(g, null, null);
        Assert.assertEquals(eventListener.scannedEdges, 3);
        Assert.assertEquals(eventListener.removedEdges, 0);
        Assert.assertEquals(eventListener.scannedVertices, 3);
        Assert.assertEquals(eventListener.scannedLinks, 6);
        Assert.assertEquals(eventListener.removedLinks, 0);
        Assert.assertEquals(eventListener.repairedVertices, 0);
    } finally {
        g.shutdown();
    }
}
Also used : OGraphRepair(com.tinkerpop.blueprints.impls.orient.OGraphRepair) OrientGraphNoTx(com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx) OrientBaseGraph(com.tinkerpop.blueprints.impls.orient.OrientBaseGraph) Test(org.junit.Test)

Aggregations

OrientBaseGraph (com.tinkerpop.blueprints.impls.orient.OrientBaseGraph)75 OrientVertex (com.tinkerpop.blueprints.impls.orient.OrientVertex)40 OrientGraph (com.tinkerpop.blueprints.impls.orient.OrientGraph)21 OrientGraphNoTx (com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx)15 Vertex (com.tinkerpop.blueprints.Vertex)13 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)11 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)8 Edge (com.tinkerpop.blueprints.Edge)8 OrientGraphFactory (com.tinkerpop.blueprints.impls.orient.OrientGraphFactory)8 Test (org.junit.Test)8 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)6 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)6 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