Exemplo n.º 1
0
  @Override
  public Iterator<MarkedEdge> getEdgesFromSourceByTargetType(
      final ApplicationScope scope, final SearchByIdType edgeType) {

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

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

    final DirectedEdgeMeta directedEdgeMeta =
        DirectedEdgeMeta.fromSourceNodeTargetType(sourceId, type, targetType);

    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.getEdgesFromSourceByTargetType(
            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.getEdgesFromSourceByTargetType(
            edgeColumnFamilies, scope, edgeTypeFullRange, readShards);
      }
    };
  }
Exemplo n.º 2
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;
  }