Refine search
.withConcurrencyLevel(CONCURRENCY).call(); byte[] json = jsonMapper.writeValueAsBytes(segment); MutationBatch mutation = this.keyspace.prepareMutationBatch(); mutation.withRow(descriptorStorage, key) .putColumn("lastmodified", System.currentTimeMillis(), null) .putColumn("descriptor", json, null); mutation.execute(); log.info("Wrote index to C* in [%s] ms", System.currentTimeMillis() - start);
@Override public void mutateMany(Map<String, Map<StaticBuffer, KCVMutation>> batch, StoreTransaction txh) throws BackendException { MutationBatch m = keyspaceContext.getClient().prepareMutationBatch().withAtomicBatch(atomicBatch) .setConsistencyLevel(getTx(txh).getWriteConsistencyLevel().getAstyanax()) .withRetryPolicy(retryPolicy.duplicate()); ColumnListMutation<ByteBuffer> dels = m.withRow(columnFamily, key); dels.setTimestamp(commitTime.getDeletionTime(times)); dels.deleteColumn(b.as(StaticBuffer.BB_FACTORY)); ColumnListMutation<ByteBuffer> upds = m.withRow(columnFamily, key); upds.setTimestamp(commitTime.getAdditionTime(times)); upds.putColumn(e.getColumnAs(StaticBuffer.BB_FACTORY), e.getValueAs(StaticBuffer.BB_FACTORY), ttl); } else { upds.putColumn(e.getColumnAs(StaticBuffer.BB_FACTORY), e.getValueAs(StaticBuffer.BB_FACTORY));
@Override public MutationBatch delete( final ApplicationScope scope, final Id node, final long timestamp ) { ValidationUtils.validateApplicationScope( scope ); ValidationUtils.verifyIdentity( node ); GraphValidation.validateTimestamp( timestamp, "timestamp" ); MutationBatch batch = keyspace.prepareMutationBatch().withConsistencyLevel( fig.getWriteCL() ); batch.withRow( GRAPH_DELETE, ScopedRowKey.fromKey( scope.getApplication(), node ) ).setTimestamp( timestamp ) .deleteColumn( COLUMN_NAME ); return batch; }
@Override public MutationBatch mark( final ApplicationScope scope, final Id node, final long timestamp ) { ValidationUtils.validateApplicationScope( scope ); ValidationUtils.verifyIdentity( node ); GraphValidation.validateTimestamp( timestamp, "timestamp" ); MutationBatch batch = keyspace.prepareMutationBatch().withConsistencyLevel( fig.getWriteCL() ); batch.withRow( GRAPH_DELETE, ScopedRowKey.fromKey( scope.getApplication(), node ) ).setTimestamp( timestamp ) .putColumn( COLUMN_NAME, timestamp ); return batch; }
@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; }
private void deleteRowsForCFPopulation() throws Exception { MutationBatch m = keyspace.prepareMutationBatch(); for (int year = 2001; year <= 2014; year ++) { m.withRow(CF_POPULATION, year).delete(); } m.execute(); }
public C isUnique(K key) throws ConnectionException { C unique = uniqueColumnSupplier.get(); // Phase 1: Write a unique column MutationBatch m = keyspace.prepareMutationBatch().setConsistencyLevel(consistencyLevel); m.withRow(columnFamily, key).putEmptyColumn(unique, ttl); m.execute(); // Phase 2: Read back all columns. There should be only 1 ColumnList<C> result = keyspace.prepareQuery(columnFamily).setConsistencyLevel(consistencyLevel).getKey(key) .execute().getResult(); if (result.size() == 1) { return unique; } if (this.monitor != null) this.monitor.onViolation(key, unique); // Rollback m = keyspace.prepareMutationBatch().setConsistencyLevel(consistencyLevel); m.withRow(columnFamily, key).deleteColumn(unique); m.execute(); return null; } }
if ( keyspace.describeKeyspace().getColumnFamily( "test" ) == null ) { keyspace.createColumnFamily( cf, new HashMap<String, Object>() ); final long timestamp = 100l; MutationBatch batch = keyspace.prepareMutationBatch().withConsistencyLevel( ConsistencyLevel.CL_QUORUM ) .setTimestamp( timestamp ); batch.withRow( cf, rowKey ).putColumn( colName, true ); batch.execute(); .setTimestamp( timestamp ); batch.withRow( cf, rowKey ).deleteColumn( colName ); batch.execute(); .setTimestamp( timestamp ); batch.withRow( cf, rowKey ).putColumn( colName, true ); batch.execute();
if ( keyspace.describeKeyspace().getColumnFamily( CF_NAME ) == null ) { keyspace.createColumnFamily( testCf, null ); MutationBatch batch = keyspace.prepareMutationBatch(); batch.withRow( testCf, key ).setTimestamp( firstUUID.timestamp() ).putColumn( colname, colvalue ); batch.execute(); batch = keyspace.prepareMutationBatch(); batch.withRow( testCf, key ).setTimestamp( firstUUID.timestamp() ).putColumn( colname, colvalue ); batch.withRow( testCf, key ).setTimestamp( firstUUID.timestamp() ).deleteColumn( colname ); batch.execute(); batch.withRow( testCf, key ).setTimestamp( secondUUID.timestamp() ).putColumn( colname, colvalue ); batch.execute(); batch = keyspace.prepareMutationBatch(); batch.withRow( testCf, key ).setTimestamp( firstUUID.timestamp() ).deleteColumn( colname ); batch.execute(); batch = keyspace.prepareMutationBatch(); batch.withRow( testCf, key ).setTimestamp( thirdUUID.timestamp() ).deleteColumn( colname ); batch.execute();
@Override public void release() throws Exception { MutationBatch m = keyspace.prepareMutationBatch().setConsistencyLevel(consistencyLevel); m.withRow(columnFamily, key).deleteColumn(uniqueColumn); m.execute(); }
/** * 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; }
if (context == null) { context = new ThreadContext(); context.mb = keyspace.prepareMutationBatch(); this.context.set(context); ColumnListMutation<C> mbRow = context.mb.withRow(columnFamily, row.getKey()); context.mb.lockCurrentTimestamp(); for (Column<C> column : row.getColumns()) { mbRow.setTimestamp(column.getTimestamp()); mbRow.putColumn(column.getName(), column.getByteBufferValue(), column.getTtl()); if (context.counter == batchSize) { try { context.mb.execute(); context.counter = 0;
public void populateRows(int numRows) throws Exception { MutationBatch mb = keyspace.prepareMutationBatch(); for (int i=0; i<numRows; i++) { Date date = OriginalDate.plusMinutes(i).toDate(); mb.withRow(CF_USER_INFO, "acct_" + i) .putColumn("firstname", "john_" + i, null) .putColumn("lastname", "smith_" + i, null) .putColumn("address", "john smith address " + i, null) .putColumn("age", 30+i, null) .putColumn("ageShort", new Integer(30+i).shortValue(), null) .putColumn("ageLong", new Integer(30+i).longValue(), null) .putColumn("percentile", 30.1) .putColumn("married", true) .putColumn("single", false) .putColumn("birthdate", date) .putColumn("bytes", TestBytes) .putColumn("uuid", TestUUID) .putEmptyColumn("empty"); mb.execute(); mb.discardMutations(); } }
MutationBatch mb = keyspace.prepareMutationBatch(); mb.withRow(CF_COL_TIMESTAMP, 1L) .setTimestamp(1).putColumn(1L, 1L) .setTimestamp(10).putColumn(2L, 2L) mb.execute(); mb = keyspace.prepareMutationBatch(); mb.withRow(CF_COL_TIMESTAMP, 1L) .setTimestamp(result1.getColumnByName(1L).getTimestamp()-1) .deleteColumn(1L) .setTimestamp(result1.getColumnByName(2L).getTimestamp()-1) .deleteColumn(2L) .putEmptyColumn(3L, null); mb.execute(); mb = keyspace.prepareMutationBatch(); mb.withRow(CF_COL_TIMESTAMP, 1L) .setTimestamp(result1.getColumnByName(1L).getTimestamp()+1) .deleteColumn(1L) .setTimestamp(result1.getColumnByName(2L).getTimestamp()+1) .deleteColumn(2L); mb.execute();
rowMutation.deleteColumn(entry); m.withRow(queue.keyIndexColumnFamily, queue.getCompositeKey(queue.getName(), message.getKey())).putEmptyColumn(mostRecentMessageMetadata, queue.metadataDeleteTTL); mostRecentTriggerTime = currMessageTriggerTime; mostRecentMessageMetadata = currMessageEntry.getName(); } else { LOG.warn("Need to discard : " + entry.getMessageId() + " => " + currMessageEntry.getName()); m.withRow(queue.keyIndexColumnFamily, queue.getCompositeKey(queue.getName(), message.getKey())).putEmptyColumn(currMessageEntry.getName(), queue.metadataDeleteTTL); m.withRow(queue.keyIndexColumnFamily, queue.getCompositeKey(queue.getName(), message.getKey())) .putEmptyColumn(MessageMetadataEntry.newMessageId(messageId), queue.metadataDeleteTTL); LOG.debug("Removing from key : " + queue.getCompositeKey(queue.getName(), message.getKey()) + " : " + messageId); if (message.isKeepHistory()) { history.setStatus(MessageStatus.RUNNING); try { m.withRow(queue.historyColumnFamily, message.getKey()).putColumn(entry.getTimestamp(), queue.serializeToString(history) , queue.metadata.getHistoryTtl()); } catch (Exception e) { .putColumn(timeoutEntry, column.getStringValue(), queue.metadata.getRetentionTimeout()); MessageMetadataEntry messageIdEntry = MessageMetadataEntry.newMessageId(queue.getCompositeKey(queue.getShardKey(message), timeoutEntry.getMessageId())); .putEmptyColumn(messageIdEntry, queue.metadata.getRetentionTimeout());
@Override void writeEdge( final MutationBatch batch, final MultiTenantColumnFamily<ScopedRowKey<RowKey>, DirectedEdge> columnFamily, final ApplicationScope scope, final RowKey rowKey, final DirectedEdge edge, final Shard shard, final boolean isDeleted ) { batch.withRow( columnFamily, ScopedRowKey.fromKey( scope.getApplication(), rowKey ) ).putColumn( edge, isDeleted ); } }.createBatch( scope, shards, timestamp );
@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; }
@Override void writeEdge( final MutationBatch batch, final MultiTenantColumnFamily<ScopedRowKey<RowKey>, DirectedEdge> columnFamily, final ApplicationScope scope, final RowKey rowKey, final DirectedEdge edge, final Shard shard, final boolean isDeleted ) { batch.withRow( columnFamily, ScopedRowKey.fromKey( scope.getApplication(), rowKey ) ).deleteColumn( edge ); } }.createBatch( scope, shards, timestamp );
@Override public UpdateRequest deleteSegment(UUID segment, UUID dataId) { _mutation.withRow(CF_DEDUP_DATA, dataId) .delete(); _mutation.withRow(CF_DEDUP_MD, queue) .deleteColumn(segment); return this; }
/** * Do the write on the correct row for the entity id with the operation */ private MutationBatch doWrite( final ApplicationScope applicationScope, final Id entityId, final UUID version, final RowOp op ) { final MutationBatch batch = keyspace.prepareMutationBatch(); final Id applicationId = applicationScope.getApplication(); final ScopedRowKey<Id> rowKey = ScopedRowKey.fromKey( applicationId, entityId ); final long timestamp = version.timestamp(); op.doOp( batch.withRow( CF_ENTITY_DATA, rowKey ).setTimestamp( timestamp ) ); return batch; }