@Override public MutationBatch writeShardMeta( final ApplicationScope scope, final Shard shard, final DirectedEdgeMeta metaData) { ValidationUtils.validateApplicationScope( scope ); GraphValidation.validateDirectedEdgeMeta( metaData ); Preconditions.checkNotNull( metaData, "metadata must be present" ); Preconditions.checkNotNull( shard ); Preconditions.checkArgument( shard.getShardIndex() > -1, "shardid must be greater than -1" ); Preconditions.checkArgument( shard.getCreatedTime() > -1, "createdTime must be greater than -1" ); final ScopedRowKey rowKey = ScopedRowKey.fromKey( scope.getApplication(), metaData ); final MutationBatch batch = keyspace.prepareMutationBatch(); // write the row with a current timestamp so we can ensure that it's persisted with updated shard meta long batchTimestamp = System.currentTimeMillis(); batch.withTimestamp( batchTimestamp ).withRow( EDGE_SHARDS, rowKey ) .putColumn( shard.getShardIndex(), SHARD_SERIALIZER.toByteBuffer(shard)).setTimestamp(batchTimestamp); return batch; }
/** * Remove the edge * * @param scope The scope * @param rowKeyId The id to use in the row key * @param edgeType The edge type * @param version The version of the edge * @param cf The column family */ private MutationBatch removeEdgeType( final ApplicationScope scope, final Id rowKeyId, final String edgeType, final long version, final MultiTenantColumnFamily<ScopedRowKey<Id>, String> cf ) { //write target<--source edge type meta data final ScopedRowKey< Id> rowKey = new ScopedRowKey< Id>( scope.getApplication(), rowKeyId ); final MutationBatch batch = keyspace.prepareMutationBatch().withTimestamp( version ); batch.withRow( cf, rowKey ).deleteColumn( edgeType ); return batch; }
@Override public MutationBatch removeShardMeta( final ApplicationScope scope, final Shard shard, final DirectedEdgeMeta metaData) { ValidationUtils.validateApplicationScope( scope ); GraphValidation.valiateShard( shard ); GraphValidation.validateDirectedEdgeMeta( metaData ); final ScopedRowKey rowKey = ScopedRowKey.fromKey( scope.getApplication(), metaData ); final MutationBatch batch = keyspace.prepareMutationBatch(); // write the row with a current timestamp so we can ensure that it's persisted with updated shard meta long batchTimestamp = System.currentTimeMillis(); batch.withTimestamp(batchTimestamp).withRow( EDGE_SHARDS, rowKey ) .deleteColumn( shard.getShardIndex() ).setTimestamp(batchTimestamp); return batch; }
/** * Remove the edge * * @param scope The scope * @param rowKeyId The id to use in the row key * @param edgeType The edge type * @param version The version of the edge * @param cf The column family */ private MutationBatch removeEdgeType( final ApplicationScope scope, final Id rowKeyId, final String edgeType, final long version, final MultiTenantColumnFamily<BucketScopedRowKey<Id>, String> cf ) { //write target<--source edge type meta data final int currentShard = idExpandingShardLocator.getCurrentBucket( rowKeyId ); final BucketScopedRowKey<Id> rowKey = BucketScopedRowKey.fromKey( scope.getApplication(), rowKeyId, currentShard ); final MutationBatch batch = keyspace.prepareMutationBatch().withTimestamp( version ); batch.withRow( cf, rowKey ).deleteColumn( edgeType ); return batch; }
.withTimestamp( opTimestamp.timestamp() );
/** * Remove the id type * * @param scope The scope to use * @param rowId The id to use in the row key * @param idType The id type to use in the column * @param edgeType The edge type to use in the column * @param version The version to use on the column * @param cf The column family to use * * @return A populated mutation with the remove operations */ private MutationBatch removeIdType( final ApplicationScope scope, final Id rowId, final String idType, final String edgeType, final long version, final MultiTenantColumnFamily<ScopedRowKey<EdgeIdTypeKey>, String> cf ) { final MutationBatch batch = keyspace.prepareMutationBatch().withTimestamp( version ); //write target<--source edge type and id type to meta data final ScopedRowKey< EdgeIdTypeKey> rowKey = new ScopedRowKey<>( scope.getApplication(), new EdgeIdTypeKey( rowId, edgeType ) ); batch.withRow( cf, rowKey ).deleteColumn( idType ); return batch; }
/** * Remove the id type * * @param scope The scope to use * @param rowId The id to use in the row key * @param idType The id type to use in the column * @param edgeType The edge type to use in the column * @param version The version to use on the column * @param cf The column family to use * * @return A populated mutation with the remove operations */ private MutationBatch removeIdType( final ApplicationScope scope, final Id rowId, final String idType, final String edgeType, final long version, final MultiTenantColumnFamily<BucketScopedRowKey<EdgeIdTypeKey>, String> cf ) { final EdgeIdTypeKey edgeIdTypeKey = new EdgeIdTypeKey( rowId, edgeType ); final int currentShard = edgeTypeExpandingShardLocator.getCurrentBucket( edgeIdTypeKey ); final MutationBatch batch = keyspace.prepareMutationBatch().withTimestamp( version ); //write target<--source edge type and id type to meta data final BucketScopedRowKey<EdgeIdTypeKey> rowKey = BucketScopedRowKey.fromKey( scope.getApplication(), edgeIdTypeKey, currentShard ); batch.withRow( cf, rowKey ).deleteColumn( idType ); return batch; }
@Override public MutationBatch writeEdge( final ApplicationScope scope, final Edge edge ) { ValidationUtils.validateApplicationScope( scope ); GraphValidation.validateEdge( edge ); final Id scopeId = scope.getApplication(); final Id source = edge.getSourceNode(); final Id target = edge.getTargetNode(); final String edgeType = edge.getType(); final long timestamp = edge.getTimestamp(); final MutationBatch batch = keyspace.prepareMutationBatch().withConsistencyLevel( cassandraConfig.getWriteCL() ) .withTimestamp( timestamp ); //add source->target edge type to meta data final ScopedRowKey< Id> sourceKey = new ScopedRowKey<>( scopeId, source ); batch.withRow( CF_SOURCE_EDGE_TYPES, sourceKey ).putColumn( edgeType, HOLDER ); //write source->target edge type and id type to meta data EdgeIdTypeKey tk = new EdgeIdTypeKey( source, edgeType ); final ScopedRowKey<EdgeIdTypeKey> sourceTypeKey = new ScopedRowKey<>( scopeId, tk ); batch.withRow( CF_SOURCE_EDGE_ID_TYPES, sourceTypeKey ).putColumn( target.getType(), HOLDER ); //write target<--source edge type meta data final ScopedRowKey< Id> targetKey = new ScopedRowKey<>( scopeId, target ); batch.withRow( CF_TARGET_EDGE_TYPES, targetKey ).putColumn( edgeType, HOLDER ); //write target<--source edge type and id type to meta data final ScopedRowKey<EdgeIdTypeKey> targetTypeKey = new ScopedRowKey<>( scopeId, new EdgeIdTypeKey( target, edgeType ) ); batch.withRow( CF_TARGET_EDGE_ID_TYPES, targetTypeKey ).putColumn( source.getType(), HOLDER ); return batch; }
.withTimestamp( timestamp );
@Override public MutationBatch withTimestamp(long timestamp) { primary.withTimestamp(timestamp); secondary.withTimestamp(timestamp); return this; }