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;
}
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();
}
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;
}
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);
}
}
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();
}
}
Aggregations