@Override public Iterator<MarkedEdge> getEdgesToTarget( final ApplicationScope scope, final SearchByEdgeType edgeType) { ValidationUtils.validateApplicationScope(scope); GraphValidation.validateSearchByEdgeType(edgeType); final Id targetId = edgeType.getNode(); final String type = edgeType.getType(); final long maxTimestamp = edgeType.getMaxTimestamp(); final DirectedEdgeMeta directedEdgeMeta = DirectedEdgeMeta.fromTargetNode(targetId, type); 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.getEdgesToTarget( edgeColumnFamilies, scope, edgeType, readShards); } @Override protected Iterator<MarkedEdge> getIteratorFullRange(final Collection<Shard> readShards) { final SearchByEdgeType edgeTypeFullRange = new SimpleSearchByEdgeType( edgeType.getNode(), edgeType.getType(), Long.MAX_VALUE, SearchByEdgeType.Order.DESCENDING, Optional.absent(), false); return shardedEdgeSerialization.getEdgesToTarget( edgeColumnFamilies, scope, edgeTypeFullRange, readShards); } }; }
@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; }