public RowMutation getIdMutation(String indexName, String key, Long id) throws IOException { int shard = getShardFromDocId(id); ByteBuffer idCol = ByteBufferUtil.bytes(String.valueOf(getShardedDocId(id))); ByteBuffer keyCol = ByteBuffer.wrap(key.getBytes("UTF-8")); // Permanently mark the id as taken ByteBuffer idKey = CassandraUtils.hashKeyBytes((indexName + "~" + shard).getBytes("UTF-8"), CassandraUtils.delimeterBytes, "ids".getBytes("UTF-8")); RowMutation rm = new RowMutation(CassandraUtils.keySpace, idKey); rm.add(new QueryPath(CassandraUtils.schemaInfoColumnFamily, idCol, ByteBuffer .wrap(getToken().getBytes("UTF-8"))), keyCol, System.currentTimeMillis()); return rm; }
public static void addMutations(Map<ByteBuffer, RowMutation> mutationList, String columnFamily, ByteBuffer column, ByteBuffer key, ByteBuffer value) { // Find or create row mutation RowMutation rm = mutationList.get(key); if (rm == null) { rm = new RowMutation(CassandraUtils.keySpace, key); mutationList.put(key, rm); } if (value == null) { // remove if (column != null) { rm.delete(new QueryPath(columnFamily, null, column), System.currentTimeMillis()-1); } else { rm.delete(new QueryPath(columnFamily), System.currentTimeMillis()-1); } } else { // insert rm.add(new QueryPath(columnFamily, null, column), value, System.currentTimeMillis()); } }
RowMutation rm = new RowMutation(CassandraUtils.keySpace, keyKey); rm.delete(new QueryPath(CassandraUtils.schemaInfoColumnFamily, keyCol), System.currentTimeMillis()); RowMutation rm2 = new RowMutation(CassandraUtils.keySpace, idKey); rm2.delete(new QueryPath(CassandraUtils.schemaInfoColumnFamily, sidName), System.currentTimeMillis());
public List<LogEntry> writePending(ConsistencyLevel consistencyLevel, RowMutation rowMutation) throws Throwable { List<String> columnNames = new ArrayList<String>(); for (ColumnFamily cf : rowMutation.getColumnFamilies()) { for (ByteBuffer b : cf.getColumnNames()) { columnNames.add(ByteBufferUtil.string(b)); } } String keyspace = rowMutation.getTable(); ByteBuffer rowKey = rowMutation.key(); List<LogEntry> entries = new ArrayList<LogEntry>(); for (Integer cfId : rowMutation.getColumnFamilyIds()) { ColumnFamily columnFamily = rowMutation.getColumnFamily(cfId); String path = keyspace + ":" + columnFamily.metadata().cfName; List<Trigger> triggers = TriggerStore.getStore().getTriggers().get(path); if (triggers != null && triggers.size() > 0) { String hostName = LogEntryStore.getHostName(); LogEntry entry = new LogEntry(keyspace, columnFamily, rowKey, consistencyLevel, hostName, System.currentTimeMillis(), columnNames); entries.add(entry); write(entry, PENDING_PRIORITY); } } return entries; }
final RowMutation rm = new RowMutation(CassandraUtils.keySpace, idKey); workingMutations.put(idKey, rm);
@Override public void collect(int docNumber) throws IOException { deleteLucandraDocument(indexName, docNumber, autoCommit); numRemoved.incrementAndGet(); //delete the id reference rm.delete(new QueryPath(CassandraUtils.schemaInfoColumnFamily, ByteBufferUtil.bytes(Integer.toString(docNumber))), System.currentTimeMillis()-1); }
private List<LogEntry> writePending(ConsistencyLevel consistencyLevel, List<IMutation> mutations) throws Throwable { List<LogEntry> logEntries = new ArrayList<LogEntry>(); for (IMutation mutation : mutations) { if (mutation instanceof RowMutation) { RowMutation rowMutation = (RowMutation) mutation; logger.debug("Mutation for [" + rowMutation.getTable() + "] with consistencyLevel [" + consistencyLevel + "]"); if (!rowMutation.getTable().equals(CommitLog.KEYSPACE)) { logEntries.addAll(CommitLog.getCommitLog().writePending(consistencyLevel, rowMutation)); } } } return logEntries; }
public void flush(String core) throws IOException { // Make sure all writes are in for this core writer.commit(core, true); ByteBuffer cacheKey = CassandraUtils.hashKeyBytes((core).getBytes("UTF-8"), CassandraUtils.delimeterBytes, "cache".getBytes("UTF-8")); RowMutation rm = new RowMutation(CassandraUtils.keySpace, cacheKey); rm.add(new QueryPath(CassandraUtils.schemaInfoColumnFamily, CassandraUtils.cachedColBytes, CassandraUtils.cachedColBytes), ByteBufferUtil.EMPTY_BYTE_BUFFER, System.currentTimeMillis()); CassandraUtils.robustInsert(ConsistencyLevel.QUORUM, rm); // also directly notify the local readers SolandraComponent.cacheCheck.put(core, System.currentTimeMillis() - CassandraUtils.cacheInvalidationInterval - 1); }
rm = new RowMutation(keySpaceName, key.asByteBuffer()); rowMutations.put(key, rm); rm.add(columnFamily, e.getColumnAs(StaticBuffer.BB_FACTORY), e.getValueAs(StaticBuffer.BB_FACTORY), commitTime.getAdditionTime(times.getUnit()), ttl); } else { rm.add(columnFamily, e.getColumnAs(StaticBuffer.BB_FACTORY), e.getValueAs(StaticBuffer.BB_FACTORY), commitTime.getAdditionTime(times.getUnit())); rm.delete(columnFamily, col.as(StaticBuffer.BB_FACTORY), commitTime.getDeletionTime(times.getUnit()));
RowMutation rm = new RowMutation(CassandraUtils.keySpace, shardKey); rm.add(new QueryPath(CassandraUtils.schemaInfoColumnFamily, ByteBuffer.wrap(String.valueOf(shard).getBytes( "UTF-8")), ByteBuffer.wrap(myToken.getBytes("UTF-8"))), ByteBuffer.wrap(String.valueOf(offset).getBytes("UTF-8")), System.currentTimeMillis());
CassandraUtils.delimeterBytes, "resources".getBytes("UTF-8")); RowMutation rm = new RowMutation(CassandraUtils.keySpace, coreKey); resourceNameBytes); rm.add( queryPath, ByteBufferUtil.bytes(resourceValue),
CassandraUtils.delimeterBytes, "ids".getBytes("UTF-8")); RowMutation rm = new RowMutation(CassandraUtils.keySpace, idKey); rm.add(new QueryPath(CassandraUtils.schemaInfoColumnFamily, idCol, ByteBuffer.wrap(myToken .getBytes("UTF-8"))), keyCol, System.currentTimeMillis()); RowMutation rm2 = new RowMutation(CassandraUtils.keySpace, keyKey); rm2.add(new QueryPath(CassandraUtils.schemaInfoColumnFamily, keyCol, idVal), CassandraUtils.finalTokenBytes, System.currentTimeMillis());
RowMutation rm = new RowMutation(CassandraUtils.keySpace, key); rm.add(new QueryPath(CassandraUtils.schemaInfoColumnFamily, id, ByteBuffer.wrap(myToken .getBytes("UTF-8"))), off, System.currentTimeMillis(), expirationTime); rm = new RowMutation(CassandraUtils.keySpace, key); rm.add(new QueryPath(CassandraUtils.schemaInfoColumnFamily, id, ByteBuffer.wrap(myToken .getBytes("UTF-8"))), off, System.currentTimeMillis());
@Override public ResponseData batchMutate(Object key, Map<?, ?> nv) throws OperationException { ByteBuffer rKey = kser.toByteBuffer(key); RowMutation change = new RowMutation(ks, rKey); for (Map.Entry entry : nv.entrySet()) { ByteBuffer name = colser.toByteBuffer(entry.getKey()); ByteBuffer val = valser.toByteBuffer(entry.getValue()); ColumnPath cp = new ColumnPath(cf).setColumn(name); change.add(new QueryPath(cp), val, System.currentTimeMillis()); } try { StorageProxy.mutate(Arrays.asList(change), wConsistecy); } catch (Exception e) { throw new OperationException(e); } return new ResponseData("", 0, ""); }
@Override public ResponseData put(Object key, Object colName, Object value) throws OperationException { ByteBuffer rKey = kser.toByteBuffer(key); ByteBuffer name = colser.toByteBuffer(colName); ByteBuffer val = valser.toByteBuffer(value); RowMutation change = new RowMutation(ks, rKey); ColumnPath cp = new ColumnPath(cf).setColumn(name); change.add(new QueryPath(cp), val, System.currentTimeMillis()); try { StorageProxy.mutate(Arrays.asList(change), wConsistecy); } catch (Exception e) { throw new OperationException(e); } return new ResponseData("", 0, ""); }