/** * Utility function to generate a new key from the scope */ public static <K> BucketScopedRowKey<K> fromKey( final Id scope, final K key, final int bucketNumber ) { return new BucketScopedRowKey<>( scope, key, bucketNumber ); }
@Override public ByteBuffer toByteBuffer( final BucketScopedRowKey<K> scopedRowKey ) { final CompositeBuilder builder = Composites.newCompositeBuilder(); //add the organization's id ID_SER.toComposite( builder, scopedRowKey.getScope() ); //add the bucket builder.addInteger( scopedRowKey.getBucketNumber() ); //add the key type keySerializer.toComposite( builder, scopedRowKey.getKey() ); return builder.build(); }
/** * 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; }
/** * Get the edge types from the search criteria. * * @param scope The org scope * @param search The edge type search info * @param cf The column family to execute on */ private Iterator<String> getEdgeTypes( final ApplicationScope scope, final SearchEdgeType search, final MultiTenantColumnFamily<BucketScopedRowKey<Id>, String> cf ) { ValidationUtils.validateApplicationScope( scope ); GraphValidation.validateSearchEdgeType( search ); final Id applicationId = scope.getApplication(); final Id searchNode = search.getNode(); final int[] bucketIds = idExpandingShardLocator.getAllBuckets( searchNode ); //no generics is intentional here final List<BucketScopedRowKey<Id>> buckets = BucketScopedRowKey.fromRange( applicationId, searchNode, bucketIds ); final ColumnSearch<String> columnSearch = createSearch( search ); return new MultiRowColumnIterator( keyspace, cf, cassandraConfig.getReadCL(), PARSER, columnSearch, STRING_COMPARATOR, buckets, graphFig.getScanPageSize() ); }
/** * 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; }
/** * Get the id types from the specified column family * * @param scope The organization scope to use * @param search The search criteria * @param cf The column family to search */ public Iterator<String> getIdTypes( final ApplicationScope scope, final SearchIdType search, final MultiTenantColumnFamily<BucketScopedRowKey<EdgeIdTypeKey>, String> cf ) { ValidationUtils.validateApplicationScope( scope ); GraphValidation.validateSearchEdgeIdType( search ); final Id applicationId = scope.getApplication(); final Id searchNode = search.getNode(); final EdgeIdTypeKey edgeIdTypeKey = new EdgeIdTypeKey( searchNode, search.getEdgeType() ); final int[] bucketIds = edgeTypeExpandingShardLocator.getAllBuckets( edgeIdTypeKey ); //no generics is intentional here final List<BucketScopedRowKey<EdgeIdTypeKey>> buckets = BucketScopedRowKey.fromRange( applicationId, edgeIdTypeKey, bucketIds ); final ColumnSearch<String> columnSearch = createSearch( search ); return new MultiRowColumnIterator( keyspace, cf, cassandraConfig.getReadCL(), PARSER, columnSearch, STRING_COMPARATOR, buckets, graphFig.getScanPageSize() ); }
/** * Create a list of all buckets from [0, totalBuckets}. Note that this is an n-1 0 based system */ public static <K> List<BucketScopedRowKey<K>> fromRange( final Id scope, final K key, final int... buckets ) { final List<BucketScopedRowKey<K>> results = new ArrayList<>( buckets.length ); for ( int i = 0; i < buckets.length; i++ ) { results.add( new BucketScopedRowKey<>( scope, key, buckets[i] ) ); } return results; } }
final BucketScopedRowKey<Id> sourceKey = BucketScopedRowKey.fromKey( scopeId, source, sourceKeyBucket ); BucketScopedRowKey.fromKey( scopeId, sourceTargetTypeKey, sourceTargetTypeBucket ); final BucketScopedRowKey<Id> targetKey = BucketScopedRowKey.fromKey( scopeId, target, targetKeyBucket ); BucketScopedRowKey.fromKey( scopeId, targetSourceTypeKey, targetSourceTypeKeyBucket );
@Override public BucketScopedRowKey<K> fromByteBuffer( final ByteBuffer byteBuffer ) { final CompositeParser parser = Composites.newCompositeParser( byteBuffer ); //read back the id final Id orgId = ID_SER.fromComposite( parser ); final int bucket = parser.readInteger(); final K value = keySerializer.fromComposite( parser ); return new BucketScopedRowKey<>( orgId, value, bucket ); } }