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; }