@Test public void testCleanupWithIndexes() throws IOException, ExecutionException, InterruptedException { Keyspace keyspace = Keyspace.open(KEYSPACE1); ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(CF1); List<Row> rows; // insert data and verify we get it back w/ range query fillCF(cfs, LOOPS); rows = Util.getRangeSlice(cfs); assertEquals(LOOPS, rows.size()); SecondaryIndex index = cfs.indexManager.getIndexForColumn(COLUMN); long start = System.nanoTime(); while (!index.isIndexBuilt(COLUMN) && System.nanoTime() - start < TimeUnit.SECONDS.toNanos(10)) Thread.sleep(10); // verify we get it back w/ index query too IndexExpression expr = new IndexExpression(COLUMN, IndexExpression.Operator.EQ, VALUE); List<IndexExpression> clause = Arrays.asList(expr); IDiskAtomFilter filter = new IdentityQueryFilter(); IPartitioner p = StorageService.getPartitioner(); Range<RowPosition> range = Util.range("", ""); rows = keyspace.getColumnFamilyStore(CF1).search(range, clause, filter, Integer.MAX_VALUE); assertEquals(LOOPS, rows.size()); // we don't allow cleanup when the local host has no range to avoid wipping up all data when a // node has not join the ring. // So to make sure cleanup erase everything here, we give the localhost the tiniest possible // range. TokenMetadata tmd = StorageService.instance.getTokenMetadata(); byte[] tk1 = new byte[1], tk2 = new byte[1]; tk1[0] = 2; tk2[0] = 1; tmd.updateNormalToken(new BytesToken(tk1), InetAddress.getByName("127.0.0.1")); tmd.updateNormalToken(new BytesToken(tk2), InetAddress.getByName("127.0.0.2")); CompactionManager.instance.performCleanup(cfs, new CounterId.OneShotRenewer()); // row data should be gone rows = Util.getRangeSlice(cfs); assertEquals(0, rows.size()); // not only should it be gone but there should be no data on disk, not even tombstones assert cfs.getSSTables().isEmpty(); // 2ary indexes should result in no results, too (although tombstones won't be gone until // compacted) rows = cfs.search(range, clause, filter, Integer.MAX_VALUE); assertEquals(0, rows.size()); }
private IndexExpression highestSelectivityPredicate(List<IndexExpression> clause) { IndexExpression best = null; int bestMeanCount = Integer.MAX_VALUE; for (IndexExpression expression : clause) { // skip columns belonging to a different index type if (!columns.contains(expression.column_name)) continue; SecondaryIndex index = indexManager.getIndexForColumn(expression.column_name); if (index == null || (expression.op != IndexOperator.EQ)) continue; int columns = index.getIndexCfs().getMeanColumns(); if (columns < bestMeanCount) { best = expression; bestMeanCount = columns; } } return best; }