ByteBuffer keyKey = CassandraUtils.hashKeyBytes((indexName + "~" + term.text()).getBytes("UTF-8"),
CassandraUtils.delimeterBytes, "keys".getBytes("UTF-8"));
ByteBuffer keyCol = ByteBuffer.wrap(term.text().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)
{
ByteBuffer idCol = col.getSubColumns().iterator().next().name();
Long id = Long.valueOf(ByteBufferUtil.string(idCol));
int shard = CassandraIndexManager.getShardFromDocId(id);
int sid = CassandraIndexManager.getShardedDocId(id);
ByteBuffer sidName = ByteBuffer.wrap(String.valueOf(sid).getBytes("UTF-8"));
String subIndex = indexName + "~" + shard;
// Delete all terms/fields/etc
writer.deleteDocuments(subIndex, term, false);
// Delete key -> docId lookup
RowMutation rm = new RowMutation(CassandraUtils.keySpace, keyKey);
rm.delete(new QueryPath(CassandraUtils.schemaInfoColumnFamily, keyCol), System.currentTimeMillis());
// Delete docId so it can be reused
// TODO: update shard info with this docid
ByteBuffer idKey = CassandraUtils.hashKeyBytes(subIndex.getBytes("UTF-8"),
CassandraUtils.delimeterBytes, "ids".getBytes("UTF-8"));
RowMutation rm2 = new RowMutation(CassandraUtils.keySpace, idKey);
rm2.delete(new QueryPath(CassandraUtils.schemaInfoColumnFamily, sidName),
System.currentTimeMillis());
CassandraUtils.robustInsert(ConsistencyLevel.QUORUM, rm, rm2);
// Notify readers