예제 #1
0
  @Override
  public Iterator<MarkedEdge> getEdgesToTargetBySourceType(
      final ApplicationScope scope, final SearchByIdType edgeType) {

    ValidationUtils.validateApplicationScope(scope);
    GraphValidation.validateSearchByIdType(edgeType);

    final Id targetId = edgeType.getNode();
    final String sourceType = edgeType.getIdType();
    final String type = edgeType.getType();
    final long maxTimestamp = edgeType.getMaxTimestamp();

    final DirectedEdgeMeta directedEdgeMeta =
        DirectedEdgeMeta.fromTargetNodeSourceType(targetId, type, sourceType);

    final Iterator<ShardEntryGroup> readShards =
        edgeShardStrategy.getReadShards(scope, maxTimestamp, directedEdgeMeta);

    return new ShardGroupColumnIterator(scope, directedEdgeMeta, shardGroupDeletion, readShards) {
      @Override
      protected Iterator<MarkedEdge> getIterator(final Collection<Shard> readShards) {
        return shardedEdgeSerialization.getEdgesToTargetBySourceType(
            edgeColumnFamilies, scope, edgeType, readShards);
      }

      @Override
      protected Iterator<MarkedEdge> getIteratorFullRange(final Collection<Shard> readShards) {

        final SearchByIdType edgeTypeFullRange =
            new SimpleSearchByIdType(
                edgeType.getNode(),
                edgeType.getType(),
                Long.MAX_VALUE,
                SearchByEdgeType.Order.DESCENDING,
                edgeType.getIdType(),
                Optional.absent(),
                false);

        return shardedEdgeSerialization.getEdgesToTargetBySourceType(
            edgeColumnFamilies, scope, edgeTypeFullRange, readShards);
      }
    };
  }
예제 #2
0
  @Override
  public Iterator<MarkedEdge> getEdgeVersions(
      final ApplicationScope scope, final SearchByEdge search) {
    ValidationUtils.validateApplicationScope(scope);
    GraphValidation.validateSearchByEdge(search);

    final Id targetId = search.targetNode();
    final Id sourceId = search.sourceNode();
    final String type = search.getType();
    final long maxTimestamp = search.getMaxTimestamp();

    final DirectedEdgeMeta versionMetaData = DirectedEdgeMeta.fromEdge(sourceId, targetId, type);

    final Iterator<ShardEntryGroup> readShards =
        edgeShardStrategy.getReadShards(scope, maxTimestamp, versionMetaData);

    // now create a result iterator with our iterator of read shards

    return new ShardGroupColumnIterator(scope, versionMetaData, shardGroupDeletion, readShards) {
      @Override
      protected Iterator<MarkedEdge> getIterator(final Collection<Shard> readShards) {
        return shardedEdgeSerialization.getEdgeVersions(
            edgeColumnFamilies, scope, search, readShards);
      }

      @Override
      protected Iterator<MarkedEdge> getIteratorFullRange(final Collection<Shard> readShards) {

        final SearchByEdge searchFullRange =
            new SimpleSearchByEdge(
                search.sourceNode(),
                search.getType(),
                search.targetNode(),
                Long.MAX_VALUE,
                SearchByEdgeType.Order.DESCENDING,
                Optional.absent());

        return shardedEdgeSerialization.getEdgeVersions(
            edgeColumnFamilies, scope, searchFullRange, readShards);
      }
    };
  }
예제 #3
0
  @Override
  public MutationBatch writeEdge(
      final ApplicationScope scope, final MarkedEdge markedEdge, final UUID timestamp) {

    ValidationUtils.validateApplicationScope(scope);
    GraphValidation.validateEdge(markedEdge);
    ValidationUtils.verifyTimeUuid(timestamp, "timestamp");

    final long now = timeService.getCurrentTime();
    final Id sourceNode = markedEdge.getSourceNode();
    final Id targetNode = markedEdge.getTargetNode();
    final String edgeType = markedEdge.getType();
    final long edgeTimestamp = markedEdge.getTimestamp();

    /** Source write */
    final DirectedEdgeMeta sourceEdgeMeta = DirectedEdgeMeta.fromSourceNode(sourceNode, edgeType);

    final Collection<Shard> sourceWriteShards =
        edgeShardStrategy.getWriteShards(scope, edgeTimestamp, sourceEdgeMeta).getWriteShards(now);

    final MutationBatch batch =
        shardedEdgeSerialization.writeEdgeFromSource(
            edgeColumnFamilies, scope, markedEdge, sourceWriteShards, sourceEdgeMeta, timestamp);

    /** Source with target type write */
    final DirectedEdgeMeta sourceTargetTypeEdgeMeta =
        DirectedEdgeMeta.fromSourceNodeTargetType(sourceNode, edgeType, targetNode.getType());

    final Collection<Shard> sourceTargetTypeWriteShards =
        edgeShardStrategy
            .getWriteShards(scope, edgeTimestamp, sourceTargetTypeEdgeMeta)
            .getWriteShards(now);

    batch.mergeShallow(
        shardedEdgeSerialization.writeEdgeFromSourceWithTargetType(
            edgeColumnFamilies,
            scope,
            markedEdge,
            sourceTargetTypeWriteShards,
            sourceTargetTypeEdgeMeta,
            timestamp));

    /** Target write */
    final DirectedEdgeMeta targetEdgeMeta = DirectedEdgeMeta.fromTargetNode(targetNode, edgeType);

    final Collection<Shard> targetWriteShards =
        edgeShardStrategy.getWriteShards(scope, edgeTimestamp, targetEdgeMeta).getWriteShards(now);

    batch.mergeShallow(
        shardedEdgeSerialization.writeEdgeToTarget(
            edgeColumnFamilies, scope, markedEdge, targetWriteShards, targetEdgeMeta, timestamp));

    /** Target with source type write */
    final DirectedEdgeMeta targetSourceTypeEdgeMeta =
        DirectedEdgeMeta.fromTargetNodeSourceType(targetNode, edgeType, sourceNode.getType());

    final Collection<Shard> targetSourceTypeWriteShards =
        edgeShardStrategy
            .getWriteShards(scope, edgeTimestamp, targetSourceTypeEdgeMeta)
            .getWriteShards(now);

    batch.mergeShallow(
        shardedEdgeSerialization.writeEdgeToTargetWithSourceType(
            edgeColumnFamilies,
            scope,
            markedEdge,
            targetSourceTypeWriteShards,
            targetSourceTypeEdgeMeta,
            timestamp));

    /** Version write */
    final DirectedEdgeMeta edgeVersionsMeta =
        DirectedEdgeMeta.fromEdge(sourceNode, targetNode, edgeType);

    final Collection<Shard> edgeVersionsShards =
        edgeShardStrategy
            .getWriteShards(scope, edgeTimestamp, edgeVersionsMeta)
            .getWriteShards(now);

    batch.mergeShallow(
        shardedEdgeSerialization.writeEdgeVersions(
            edgeColumnFamilies,
            scope,
            markedEdge,
            edgeVersionsShards,
            edgeVersionsMeta,
            timestamp));

    return batch;
  }