コード例 #1
0
    @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;
    }
コード例 #2
0
 protected void updateVertex(OrientVertex v) {
   v.setProperty("saved", ((Integer) v.getProperty("saved")) + 1);
 }