@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); }
List<Row> rows = CassandraUtils.robustRead(keyKey, new QueryPath(CassandraUtils.schemaInfoColumnFamily, CassandraUtils.cachedColBytes), Arrays .asList(CassandraUtils.cachedColBytes), ConsistencyLevel.QUORUM);
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()); } }
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); }
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());
public Long checkForUpdate(String indexName, String key) throws IOException { ByteBuffer keyCol = ByteBuffer.wrap(key.getBytes("UTF-8")); ByteBuffer keyKey = CassandraUtils.hashKeyBytes((indexName + "~" + key).getBytes("UTF-8"), CassandraUtils.delimeterBytes, "keys".getBytes("UTF-8")); List<Row> rows = CassandraUtils.robustRead(keyKey, new QueryPath(CassandraUtils.schemaInfoColumnFamily), Arrays.asList(keyCol), ConsistencyLevel.QUORUM); if (rows.size() == 1) { Row row = rows.get(0); if (row.cf != null) { IColumn col = row.cf.getColumn(keyCol); if (col != null) { Collection<IColumn> subCols = col.getSubColumns(); if (subCols != null && !subCols.isEmpty()) { ByteBuffer idVal = col.getSubColumns().iterator().next().name(); Long id = Long.valueOf(ByteBufferUtil.string(idVal)); return id; } } } } return null; }
ByteBuffer resourceNameBytes = ByteBufferUtil.bytes(resourceName); QueryPath queryPath = new QueryPath( CassandraUtils.schemaInfoColumnFamily, coreNameBytes,
ByteBuffer resourceNameBytes = ByteBufferUtil.bytes(resourceName); QueryPath queryPath = new QueryPath( CassandraUtils.schemaInfoColumnFamily, coreNameBytes);
ByteBuffer keyCol = ByteBuffer.wrap(term.text().getBytes("UTF-8")); List<Row> rows = CassandraUtils.robustRead(keyKey, new QueryPath(CassandraUtils.schemaInfoColumnFamily), Arrays.asList(keyCol), ConsistencyLevel.QUORUM); rm.delete(new QueryPath(CassandraUtils.schemaInfoColumnFamily, keyCol), System.currentTimeMillis()); CassandraUtils.delimeterBytes, "ids".getBytes("UTF-8")); RowMutation rm2 = new RowMutation(CassandraUtils.keySpace, idKey); rm2.delete(new QueryPath(CassandraUtils.schemaInfoColumnFamily, sidName), System.currentTimeMillis());
ByteBuffer off = id; rm.add(new QueryPath(CassandraUtils.schemaInfoColumnFamily, id, ByteBuffer.wrap(myToken .getBytes("UTF-8"))), off, System.currentTimeMillis(), expirationTime); List<Row> rows = CassandraUtils.robustRead(key, new QueryPath( CassandraUtils.schemaInfoColumnFamily), Arrays.asList(id), ConsistencyLevel.QUORUM); rm.add(new QueryPath(CassandraUtils.schemaInfoColumnFamily, id, ByteBuffer.wrap(myToken .getBytes("UTF-8"))), off, System.currentTimeMillis());
SliceByNamesReadCommand readCommand = new SliceByNamesReadCommand(ks, rKey, new QueryPath(cf, null, null), cols); readCommand.setDigestQuery(false); commands.add(readCommand);
@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, ""); }