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"); }
public MeasureStandard(OrientVertex scale, OrientVertex vUser, OrientBaseGraph g) throws AccessForbiddenException { super(scale, vUser, g); if (!AccessRights.canRead(vUser, scale, g)) { throw new AccessForbiddenException( (String) vUser.getProperty(DataModel.Properties.id), (String) scale.getProperty(DataModel.Properties.id)); } this.userCanDelete = DeleteUtils.canUserDeleteSubGraph(scale, vUser, g); Double lengthInMm = scale.getProperty(DataModel.Properties.length); Iterator<Vertex> itMeasurements = scale.getVertices(Direction.IN, DataModel.Links.definedAsMeasureStandard).iterator(); // It's 1 and only 1 (except for new versions of it) Vertex vMeasurement = AccessUtils.findLatestVersion(itMeasurements, g); Double lengthInPixels = vMeasurement.getProperty(DataModel.Properties.pxValue); this.mmPerPixel = lengthInMm / lengthInPixels; }
public ODocument createLink(String sourceId, String destId, String edgeName) throws DocumentNotFoundException { DbHelper.requestTransaction(); OrientEdge edge = null; try { OrientVertex sourceVertex = StorageUtils.getNodeVertex(sourceId); OrientVertex destVertex = StorageUtils.getNodeVertex(destId); UUID token = UUID.randomUUID(); edge = (OrientEdge) sourceVertex.addEdge(edgeName, destVertex); edge.getRecord().field(BaasBoxPrivateFields.ID.toString(), token.toString()); edge.getRecord().field(BaasBoxPrivateFields.AUTHOR.toString(), DbHelper.currentUsername()); edge.getRecord().field(BaasBoxPrivateFields.CREATION_DATE.toString(), new Date()); edge.save(); DbHelper.commitTransaction(); } catch (DocumentNotFoundException e) { DbHelper.rollbackTransaction(); throw e; } // edge.getGraph().commit(); return edge.getRecord(); }
@Override public Object executeTransform(final Object input) { final OrientVertex v = pipeline.getGraphDatabase().getVertex(input); if (v == null) return null; if (vertexClass != null && !vertexClass.equals(v.getRecord().getClassName())) try { v.getRecord().setClassName(vertexClass); // v.save(clusterName); } catch (ORecordDuplicatedException e) { if (skipDuplicates) { return null; } else { throw e; } } return v; }
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()); } catch (ONeedRetryException e) { System.out.println( iClient + " - caught conflict, reloading vertex. v=" + vertex1.getRecord().getVersion()); vertex1.reload(); } } } // STATISTICALLY HERE AT LEAST ON CONFLICT HAS BEEN RECEIVED vertex1.reload(); Assert.assertTrue(vertex1.getRecord().getVersion() > TOTAL * 2 + 1); Assert.assertEquals(TOTAL, i); } catch (Throwable e) { if (exceptionInThread == null) exceptionInThread = e; } finally { System.out.println("Shutting down"); graph.shutdown(); sleep(1000); } }
@Override public Void call() throws Exception { String name = Integer.toString(serverId); for (int i = 0; i < count; i += 2) { final OrientGraph graph = factory.getTx(); final OrientVertex localVertex = graph.getVertex(v); try { if ((i + 1) % 100 == 0) System.out.println( "\nWriter " + databaseUrl + " id=" + Thread.currentThread().getId() + " managed " + (i + 1) + "/" + count + " vertices so far"); int retry = 0; boolean success = false; for (; retry < 200; ++retry) { try { updateVertex(localVertex); graph.commit(); OLogManager.instance().debug(this, "Success count %d retry %d", i, retry); success = true; break; } catch (ODistributedRecordLockedException e) { lockExceptions.incrementAndGet(); OLogManager.instance() .info(this, "increment lockExceptions %d", lockExceptions.get()); } catch (ONeedRetryException e) { OLogManager.instance().info(this, "Concurrent Exceptions " + e); } catch (Exception e) { graph.rollback(); throw e; } Thread.sleep(10 + new Random().nextInt(500)); localVertex.reload(); OLogManager.instance() .info( this, "Retry %d with reloaded vertex v=%d", retry, localVertex.getRecord().getVersion()); } Assert.assertTrue( "Unable to complete the transaction (last=" + i + "/" + count + "), even after " + retry + " retries", success); } catch (InterruptedException e) { System.out.println("Writer received interrupt (db=" + databaseUrl); Thread.currentThread().interrupt(); break; } catch (Exception e) { System.out.println("Writer received exception (db=" + databaseUrl); e.printStackTrace(); break; } finally { graph.shutdown(); } } System.out.println( "\nWriter " + name + " END. count = " + count + " lockExceptions: " + lockExceptions); return null; }
protected void updateVertex(OrientVertex v) { v.setProperty("saved", ((Integer) v.getProperty("saved")) + 1); }