Search in sources :

Example 1 with OIntentMassiveInsert

use of com.orientechnologies.orient.core.intent.OIntentMassiveInsert in project orientdb by orientechnologies.

the class OIndexAbstract method rebuild.

/**
   * {@inheritDoc}
   */
public long rebuild(final OProgressListener iProgressListener) {
    long documentIndexed = 0;
    final boolean intentInstalled = getDatabase().declareIntent(new OIntentMassiveInsert());
    acquireExclusiveLock();
    try {
        // DO NOT REORDER 2 assignments bellow
        // see #getRebuildVersion()
        rebuilding = true;
        rebuildVersion.incrementAndGet();
        try {
            if (indexId >= 0)
                storage.deleteIndexEngine(indexId);
        } catch (Exception e) {
            OLogManager.instance().error(this, "Error during index '%s' delete", name);
        }
        removeValuesContainer();
        indexId = storage.addIndexEngine(name, algorithm, type, indexDefinition, determineValueSerializer(), isAutomatic(), isDurableInNonTxMode(), version, getEngineProperties(), clustersToIndex, metadata);
        onIndexEngineChange(indexId);
    } catch (Exception e) {
        try {
            if (indexId >= 0)
                storage.clearIndex(indexId);
        } catch (Exception e2) {
            OLogManager.instance().error(this, "Error during index rebuild", e2);
        // IGNORE EXCEPTION: IF THE REBUILD WAS LAUNCHED IN CASE OF RID INVALID CLEAR ALWAYS GOES IN ERROR
        }
        rebuilding = false;
        throw OException.wrapException(new OIndexException("Error on rebuilding the index for clusters: " + clustersToIndex), e);
    } finally {
        releaseExclusiveLock();
    }
    acquireSharedLock();
    try {
        documentIndexed = fillIndex(iProgressListener);
    } catch (final Exception e) {
        OLogManager.instance().error(this, "Error during index rebuild", e);
        try {
            if (indexId >= 0)
                storage.clearIndex(indexId);
        } catch (Exception e2) {
            OLogManager.instance().error(this, "Error during index rebuild", e2);
        // IGNORE EXCEPTION: IF THE REBUILD WAS LAUNCHED IN CASE OF RID INVALID CLEAR ALWAYS GOES IN ERROR
        }
        throw OException.wrapException(new OIndexException("Error on rebuilding the index for clusters: " + clustersToIndex), e);
    } finally {
        rebuilding = false;
        if (intentInstalled)
            getDatabase().declareIntent(null);
        releaseSharedLock();
    }
    return documentIndexed;
}
Also used : OIntentMassiveInsert(com.orientechnologies.orient.core.intent.OIntentMassiveInsert) OConfigurationException(com.orientechnologies.orient.core.exception.OConfigurationException) OException(com.orientechnologies.common.exception.OException) OInvalidIndexEngineIdException(com.orientechnologies.orient.core.exception.OInvalidIndexEngineIdException) OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) OTooBigIndexKeyException(com.orientechnologies.orient.core.exception.OTooBigIndexKeyException)

Example 2 with OIntentMassiveInsert

use of com.orientechnologies.orient.core.intent.OIntentMassiveInsert in project orientdb by orientechnologies.

the class OSBTreeRidBagConcurrencySingleRidBag method testConcurrency.

public void testConcurrency() throws Exception {
    ODatabaseDocumentTx db = new ODatabaseDocumentTx(URL);
    if (db.exists()) {
        db.open("admin", "admin");
        db.drop();
    }
    db.create();
    db.declareIntent(new OIntentMassiveInsert());
    ODocument document = new ODocument();
    ORidBag ridBag = new ORidBag();
    ridBag.setAutoConvertToRecord(false);
    document.field("ridBag", ridBag);
    for (int i = 0; i < 100; i++) {
        final ORID ridToAdd = new ORecordId(0, positionCounter.incrementAndGet());
        ridBag.add(ridToAdd);
        ridTree.add(ridToAdd);
    }
    document.save();
    docContainerRid = document.getIdentity();
    List<Future<Void>> futures = new ArrayList<Future<Void>>();
    for (int i = 0; i < 5; i++) futures.add(threadExecutor.submit(new RidAdder(i)));
    for (int i = 0; i < 5; i++) futures.add(threadExecutor.submit(new RidDeleter(i)));
    latch.countDown();
    Thread.sleep(30 * 60000);
    cont = false;
    for (Future<Void> future : futures) future.get();
    document = db.load(document.getIdentity());
    document.setLazyLoad(false);
    ridBag = document.field("ridBag");
    for (OIdentifiable identifiable : ridBag) Assert.assertTrue(ridTree.remove(identifiable.getIdentity()));
    Assert.assertTrue(ridTree.isEmpty());
    System.out.println("Result size is " + ridBag.size());
    db.close();
}
Also used : ORidBag(com.orientechnologies.orient.core.db.record.ridbag.ORidBag) ArrayList(java.util.ArrayList) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) OIntentMassiveInsert(com.orientechnologies.orient.core.intent.OIntentMassiveInsert) ORecordId(com.orientechnologies.orient.core.id.ORecordId) Future(java.util.concurrent.Future) ORID(com.orientechnologies.orient.core.id.ORID) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 3 with OIntentMassiveInsert

use of com.orientechnologies.orient.core.intent.OIntentMassiveInsert in project orientdb by orientechnologies.

the class OrientDbCreationHelper method loadFile.

private static List<ORID> loadFile(ODatabaseDocumentInternal database, String filePath, int bufferSize) throws IOException {
    File binaryFile = new File(filePath);
    long binaryFileLength = binaryFile.length();
    int numberOfRecords = (int) (binaryFileLength / bufferSize);
    int remainder = (int) (binaryFileLength % bufferSize);
    if (remainder > 0)
        numberOfRecords++;
    List<ORID> binaryChuncks = new ArrayList<ORID>(numberOfRecords);
    BufferedInputStream binaryStream = new BufferedInputStream(new FileInputStream(binaryFile));
    byte[] chunk;
    database.declareIntent(new OIntentMassiveInsert());
    OBlob recordChunk;
    for (int i = 0; i < numberOfRecords; i++) {
        if (i == numberOfRecords - 1)
            chunk = new byte[remainder];
        else
            chunk = new byte[bufferSize];
        binaryStream.read(chunk);
        recordChunk = new ORecordBytes(database, chunk);
        database.save(recordChunk);
        binaryChuncks.add(recordChunk.getIdentity());
    }
    database.declareIntent(null);
    return binaryChuncks;
}
Also used : OBlob(com.orientechnologies.orient.core.record.impl.OBlob) BufferedInputStream(java.io.BufferedInputStream) ORecordBytes(com.orientechnologies.orient.core.record.impl.ORecordBytes) ArrayList(java.util.ArrayList) ORID(com.orientechnologies.orient.core.id.ORID) File(java.io.File) FileInputStream(java.io.FileInputStream) OIntentMassiveInsert(com.orientechnologies.orient.core.intent.OIntentMassiveInsert)

Example 4 with OIntentMassiveInsert

use of com.orientechnologies.orient.core.intent.OIntentMassiveInsert in project orientdb by orientechnologies.

the class OCommandExecutorSQLOptimizeDatabase method optimizeEdges.

private String optimizeEdges() {
    final ODatabaseDocumentInternal db = getDatabase();
    db.declareIntent(new OIntentMassiveInsert());
    try {
        long transformed = 0;
        if (db.getTransaction().isActive())
            db.commit();
        db.begin();
        try {
            final long totalEdges = db.countClass("E");
            long browsedEdges = 0;
            long lastLapBrowsed = 0;
            long lastLapTime = System.currentTimeMillis();
            for (ODocument doc : db.browseClass("E")) {
                if (Thread.currentThread().isInterrupted())
                    break;
                browsedEdges++;
                if (doc != null) {
                    if (doc.fields() == 2) {
                        final ORID edgeIdentity = doc.getIdentity();
                        final ODocument outV = doc.field("out");
                        final ODocument inV = doc.field("in");
                        // OUTGOING
                        final Object outField = outV.field("out_" + doc.getClassName());
                        if (outField instanceof ORidBag) {
                            final Iterator<OIdentifiable> it = ((ORidBag) outField).iterator();
                            while (it.hasNext()) {
                                OIdentifiable v = it.next();
                                if (edgeIdentity.equals(v)) {
                                    // REPLACE EDGE RID WITH IN-VERTEX RID
                                    it.remove();
                                    ((ORidBag) outField).add(inV.getIdentity());
                                    break;
                                }
                            }
                        }
                        outV.save();
                        // INCOMING
                        final Object inField = inV.field("in_" + doc.getClassName());
                        if (outField instanceof ORidBag) {
                            final Iterator<OIdentifiable> it = ((ORidBag) inField).iterator();
                            while (it.hasNext()) {
                                OIdentifiable v = it.next();
                                if (edgeIdentity.equals(v)) {
                                    // REPLACE EDGE RID WITH IN-VERTEX RID
                                    it.remove();
                                    ((ORidBag) inField).add(outV.getIdentity());
                                    break;
                                }
                            }
                        }
                        inV.save();
                        doc.delete();
                        if (++transformed % batch == 0) {
                            db.commit();
                            db.begin();
                        }
                        final long now = System.currentTimeMillis();
                        if (verbose && (now - lastLapTime > 2000)) {
                            final long elapsed = now - lastLapTime;
                            OLogManager.instance().info(this, "Browsed %,d of %,d edges, transformed %,d so far (%,d edges/sec)", browsedEdges, totalEdges, transformed, (((browsedEdges - lastLapBrowsed) * 1000 / elapsed)));
                            lastLapTime = System.currentTimeMillis();
                            lastLapBrowsed = browsedEdges;
                        }
                    }
                }
            }
            // LAST COMMIT
            db.commit();
        } finally {
            if (db.getTransaction().isActive())
                db.rollback();
        }
        return "Transformed " + transformed + " regular edges in lightweight edges";
    } finally {
        db.declareIntent(null);
    }
}
Also used : ORidBag(com.orientechnologies.orient.core.db.record.ridbag.ORidBag) ORID(com.orientechnologies.orient.core.id.ORID) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal) OIntentMassiveInsert(com.orientechnologies.orient.core.intent.OIntentMassiveInsert) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 5 with OIntentMassiveInsert

use of com.orientechnologies.orient.core.intent.OIntentMassiveInsert in project orientdb by orientechnologies.

the class TestDirtyTrackingTreeRidBagRemote method test.

@Test
public void test() {
    final int max = OGlobalConfiguration.RID_BAG_EMBEDDED_TO_SBTREEBONSAI_THRESHOLD.getValueAsInteger() * 2;
    OrientGraph graph = new OrientGraph("remote:localhost:3064/" + TestDirtyTrackingTreeRidBagRemote.class.getSimpleName(), "root", "root");
    try {
        graph.getRawGraph().declareIntent(new OIntentMassiveInsert());
        graph.createEdgeType("Edge");
        OIdentifiable oneVertex = null;
        Map<Object, Vertex> vertices = new HashMap<Object, Vertex>();
        for (int i = 0; i < max; i++) {
            Vertex v = graph.addVertex("class:V");
            v.setProperty("key", "foo" + i);
            graph.commit();
            vertices.put(v.getProperty("key"), v);
            if (i == max / 2 + 1)
                oneVertex = ((OrientVertex) v).getIdentity();
        }
        graph.commit();
        // Add the edges
        for (int i = 0; i < max; i++) {
            String codeUCD1 = "foo" + i;
            // Take the first vertex
            Vertex med1 = (Vertex) vertices.get(codeUCD1);
            // For the 2nd term
            for (int j = 0; j < max; j++) {
                String key = "foo" + j;
                // Take the second vertex
                Vertex med2 = (Vertex) vertices.get(key);
                // ((OrientVertex)med2).getRecord().reload();
                OrientEdge eInteraction = graph.addEdge(null, med1, med2, "Edge");
                assertNotNull(graph.getRawGraph().getTransaction().getRecordEntry(((OrientVertex) med2).getIdentity()));
            }
            // COMMIT
            graph.commit();
        }
        graph.getRawGraph().getLocalCache().clear();
        OrientVertex vertex = graph.getVertex(oneVertex);
        assertEquals(new GremlinPipeline<Vertex, Long>().start(vertex).in("Edge").count(), max);
    } finally {
        graph.shutdown();
    }
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) GremlinPipeline(com.tinkerpop.gremlin.java.GremlinPipeline) HashMap(java.util.HashMap) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) OIntentMassiveInsert(com.orientechnologies.orient.core.intent.OIntentMassiveInsert) Test(org.junit.Test)

Aggregations

OIntentMassiveInsert (com.orientechnologies.orient.core.intent.OIntentMassiveInsert)31 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)14 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)8 ArrayList (java.util.ArrayList)7 ORID (com.orientechnologies.orient.core.id.ORID)5 OrientMonoThreadTest (com.orientechnologies.orient.test.database.base.OrientMonoThreadTest)5 Test (org.junit.Test)5 Test (org.testng.annotations.Test)5 Future (java.util.concurrent.Future)4 OCommandOutputListener (com.orientechnologies.orient.core.command.OCommandOutputListener)3 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)3 ODatabaseCompare (com.orientechnologies.orient.core.db.tool.ODatabaseCompare)3 ORecordBytes (com.orientechnologies.orient.core.record.impl.ORecordBytes)3 OStorage (com.orientechnologies.orient.core.storage.OStorage)3 OrientVertex (com.tinkerpop.blueprints.impls.orient.OrientVertex)3 OException (com.orientechnologies.common.exception.OException)2 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)2 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)2 ORidBag (com.orientechnologies.orient.core.db.record.ridbag.ORidBag)2 OCommandExecutionException (com.orientechnologies.orient.core.exception.OCommandExecutionException)2