@Override
    public void doLoad() {

      TitanLabel connect = makeSimpleEdgeLabel("connect");
      TitanKey name = makeUniqueStringPropertyKey("name");
      TitanKey id = makeIntegerUIDPropertyKey("uid");

      String[] names = new String[noNodes];
      TitanVertex[] nodes = new TitanVertex[noNodes];
      for (int i = 0; i < noNodes; i++) {
        do {
          names[i] = RandomGenerator.randomString();
          // Retry in case of collision with existing name
        } while (null != tx.getVertex(name, names[i]));
        nodes[i] = tx.addVertex();
        nodes[i].addProperty(name, names[i]);
        nodes[i].addProperty(id, i);
      }
      log.info("Nodes loaded.");
      int offsets[] = {-99, -71, -20, -17, -13, 2, 7, 15, 33, 89};
      assert offsets.length == noEdgesPerNode;

      for (int i = 0; i < noNodes; i++) {
        TitanVertex n = nodes[i];
        for (int e = 0; e < noEdgesPerNode; e++) {
          TitanVertex n2 = nodes[wrapAround(i + offsets[e], noNodes)];
          n.addEdge(connect, n2);
        }
        if ((i + 1) % 10000 == 0) System.out.println("" + (i + 1));
      }
    }
    public void run() {

      final long start = System.nanoTime();
      final long mil = 1000000;

      doLoad();

      long precommit = System.nanoTime();
      tx.commit();
      long postcommit = System.nanoTime();
      clopen();
      long end = System.nanoTime();

      long precommitMS = (precommit - start) / mil;
      long postcommitMS = (postcommit - start) / mil;
      long endMS = (end - start) / mil;

      getMetric("Time from start to just before commit", "ms").addValue(precommitMS);
      getMetric("Time from start through commit", "ms").addValue(postcommitMS);
      getMetric("Total time", "ms").addValue(endMS);

      long edgesPerSec = noNodes * noEdgesPerNode * 1000 / Math.max(1, postcommitMS - precommitMS);
      getMetric("TitanRelation commit rate", "edges/sec").addValue(edgesPerSec);

      // Verify that data was written
      TitanVertex v1 = tx.getVertex("uid", 50);
      TitanVertex v2 = tx.getVertex("uid", 150);
      assertTrue(v1.query().count() > 0);
      assertEquals(v1.query().count(), v2.query().count());
    }
    @Override
    protected void doLoad() {
      TitanKey weight = makeWeightPropertyKey("weight");
      TitanKey id = makeIntegerUIDPropertyKey("uid");
      TitanLabel knows = makeKeyedEdgeLabel("knows", id, weight);
      TitanKey name = makeUniqueStringPropertyKey("name");

      String[] names = new String[noNodes];
      TitanVertex[] nodes = new TitanVertex[noNodes];
      for (int i = 0; i < noNodes; i++) {
        do {
          names[i] = RandomGenerator.randomString();
          // Retry in case of collision with existing name
        } while (null != tx.getVertex(name, names[i]));
        nodes[i] = tx.addVertex();
        nodes[i].addProperty(name, names[i]);
        nodes[i].addProperty(id, i);
      }
      log.info("Nodes loaded.");
      int offsets[] = {-99, -71, -20, -17, -13, 2, 7, 15, 33, 89};
      assert offsets.length == noEdgesPerNode;

      for (int i = 0; i < noNodes; i++) {
        TitanVertex n = nodes[i];
        for (int e = 0; e < noEdgesPerNode; e++) {
          TitanVertex n2 = nodes[wrapAround(i + offsets[e], noNodes)];
          TitanEdge r = n.addEdge(knows, n2);
          r.addProperty(id, RandomGenerator.randomInt(0, Integer.MAX_VALUE));
          r.addProperty(weight, Math.random());
        }
        if ((i + 1) % 10000 == 0) System.out.println("" + (i + 1));
      }
    }
Exemple #4
0
 public final void verifyAccess(TitanVertex... vertices) {
   verifyOpen();
   for (TitanVertex v : vertices) {
     Preconditions.checkArgument(v instanceof InternalVertex, "Invalid vertex: %s", v);
     if (!(v instanceof SystemType) && this != ((InternalVertex) v).tx())
       throw new IllegalArgumentException(
           "The vertex or type is not associated with this transaction [" + v + "]");
     if (v.isRemoved())
       throw new IllegalArgumentException("The vertex or type has been removed [" + v + "]");
   }
 }
  @Test
  public void testValueOrdering() {
    StandardTitanGraph graph = (StandardTitanGraph) StorageSetup.getInMemoryGraph();
    TitanLabel father = graph.makeLabel("father").manyToOne().make();
    for (int i = 1; i <= 5; i++) graph.makeKey("key" + i).single().dataType(Integer.class).make();

    TitanVertex v1 = graph.addVertex(null), v2 = graph.addVertex(null);
    TitanEdge e1 = v1.addEdge("father", v2);
    for (int i = 1; i <= 5; i++) e1.setProperty("key" + i, i);

    graph.commit();

    e1.remove();
    graph.commit();
  }
Exemple #6
0
  public TitanProperty setProperty(TitanVertex vertex, final TitanKey key, Object value) {
    Preconditions.checkNotNull(key);
    Preconditions.checkArgument(
        key.isUnique(Direction.OUT), "Not an out-unique key: %s", key.getName());

    Lock uniqueLock = FakeLock.INSTANCE;
    try {
      if (config.hasVerifyUniqueness()) {
        // Acquire uniqueness lock, remove and add
        uniqueLock = getUniquenessLock(vertex, key, value);
        uniqueLock.lock();
        vertex.removeProperty(key);
      } else {
        // Only delete in-memory
        InternalVertex v = (InternalVertex) vertex;
        for (InternalRelation r :
            v.it()
                .getAddedRelations(
                    new Predicate<InternalRelation>() {
                      @Override
                      public boolean apply(@Nullable InternalRelation p) {
                        return p.getType().equals(key);
                      }
                    })) {
          r.remove();
        }
      }
      return addPropertyInternal(vertex, key, value);
    } finally {
      uniqueLock.unlock();
    }
  }
 public static void addProperty(Vertex vertex, String propertyName, Object value) {
   LOG.debug("Setting property {} = \"{}\" to vertex {}", propertyName, value, vertex);
   ((TitanVertex) vertex).addProperty(propertyName, value);
 }
Exemple #8
0
        @Override
        public Iterator<TitanElement> getNew(final StandardElementQuery query) {
          Preconditions.checkArgument(
              query.getType() == StandardElementQuery.Type.VERTEX
                  || query.getType() == StandardElementQuery.Type.EDGE);
          if (query.getType() == StandardElementQuery.Type.VERTEX && hasModifications()) {
            // Collect all keys from the query - ASSUMPTION: query is an AND of KeyAtom
            final Set<TitanKey> keys = Sets.newHashSet();
            KeyAtom<TitanKey> standardIndexKey = null;
            for (KeyCondition<TitanKey> cond : query.getCondition().getChildren()) {
              KeyAtom<TitanKey> atom = (KeyAtom<TitanKey>) cond;
              if (atom.getRelation() == Cmp.EQUAL && isVertexIndexProperty(atom.getKey()))
                standardIndexKey = atom;
              keys.add(atom.getKey());
            }
            Iterator<TitanVertex> vertices;
            if (standardIndexKey == null) {
              Set<TitanVertex> vertexSet = Sets.newHashSet();
              for (TitanRelation r :
                  addedRelations.getView(
                      new Predicate<InternalRelation>() {
                        @Override
                        public boolean apply(@Nullable InternalRelation relation) {
                          return keys.contains(relation.getType());
                        }
                      })) {
                vertexSet.add(((TitanProperty) r).getVertex());
              }
              for (TitanRelation r : deletedRelations.values()) {
                if (keys.contains(r.getType())) {
                  TitanVertex v = ((TitanProperty) r).getVertex();
                  if (!v.isRemoved()) vertexSet.add(v);
                }
              }
              vertices = vertexSet.iterator();
            } else {
              vertices =
                  Iterators.transform(
                      newVertexIndexEntries
                          .get(standardIndexKey.getCondition(), standardIndexKey.getKey())
                          .iterator(),
                      new Function<TitanProperty, TitanVertex>() {
                        @Nullable
                        @Override
                        public TitanVertex apply(@Nullable TitanProperty o) {
                          return o.getVertex();
                        }
                      });
            }

            return (Iterator)
                Iterators.filter(
                    vertices,
                    new Predicate<TitanVertex>() {
                      @Override
                      public boolean apply(@Nullable TitanVertex vertex) {
                        return query.matches(vertex);
                      }
                    });
          } else if (query.getType() == StandardElementQuery.Type.EDGE
              && !addedRelations.isEmpty()) {
            return (Iterator)
                addedRelations
                    .getView(
                        new Predicate<InternalRelation>() {
                          @Override
                          public boolean apply(@Nullable InternalRelation relation) {
                            return (relation instanceof TitanEdge)
                                && !relation.isHidden()
                                && query.matches(relation);
                          }
                        })
                    .iterator();
          } else throw new IllegalArgumentException("Unexpected type: " + query.getType());
        }