use of org.apache.cassandra.index.internal.CollatedViewIndexBuilder in project cassandra by apache.
the class CompactionAllocationTest method testIndexingWidePartitions.
private static void testIndexingWidePartitions(String name, int numSSTable, int sstablePartitions, IndexDef... indexes) throws Throwable {
String ksname = "ks_" + name.toLowerCase();
SchemaLoader.createKeyspace(ksname, KeyspaceParams.simple(1), CreateTableStatement.parse("CREATE TABLE tbl (k text, c text, v1 text, v2 text, v3 text, v4 text, PRIMARY KEY (k, c))", ksname).build());
ColumnFamilyStore cfs = Schema.instance.getColumnFamilyStoreInstance(Schema.instance.getTableMetadata(ksname, "tbl").id);
Assert.assertNotNull(cfs);
cfs.disableAutoCompaction();
int rowWidth = 100;
int rowsPerPartition = 1000;
measure(new Workload() {
@SuppressWarnings("UnstableApiUsage")
public void setup() {
cfs.disableAutoCompaction();
String insert = String.format("INSERT INTO %s.%s (k, c, v1, v2, v3, v4) VALUES (?, ?, ?, ?, ?, ?)", ksname, "tbl");
for (int f = 0; f < numSSTable; f++) {
for (int p = 0; p < sstablePartitions; p++) {
String key = String.format("%08d", (f * sstablePartitions) + p);
for (int r = 0; r < rowsPerPartition; r++) {
QueryProcessor.executeInternal(insert, key, makeRandomString(6, -1), makeRandomString(rowWidth >> 2), makeRandomString(rowWidth >> 2), makeRandomString(rowWidth >> 2), makeRandomString(rowWidth >> 2));
}
}
cfs.forceBlockingFlush();
}
for (IndexDef index : indexes) {
QueryProcessor.executeInternal(String.format(index.cql, index.name, ksname, "tbl"));
while (!cfs.indexManager.getBuiltIndexNames().contains(index.name)) Uninterruptibles.sleepUninterruptibly(100, TimeUnit.MILLISECONDS);
}
Assert.assertEquals(numSSTable, cfs.getLiveSSTables().size());
}
public ColumnFamilyStore getCfs() {
return cfs;
}
public List<Runnable> getReads() {
return new ArrayList<>();
}
public String name() {
return name;
}
public int executeReads() {
// return 1 to avoid divide by zero error
return 1;
}
public void executeCompactions() {
logger.info("Starting index re-build");
try (ColumnFamilyStore.RefViewFragment viewFragment = cfs.selectAndReference(View.selectFunction(SSTableSet.CANONICAL));
Refs<SSTableReader> sstables = viewFragment.refs) {
Set<Index> indexes = new HashSet<>(cfs.indexManager.listIndexes());
SecondaryIndexBuilder builder = new CollatedViewIndexBuilder(cfs, indexes, new ReducingKeyIterator(sstables), ImmutableSet.copyOf(sstables));
builder.build();
}
logger.info("Index re-build complete");
}
public int[] getSSTableStats() {
int numPartitions = cfs.getLiveSSTables().stream().mapToInt(sstable -> Ints.checkedCast(sstable.getSSTableMetadata().estimatedPartitionSize.count())).sum();
int numRows = cfs.getLiveSSTables().stream().mapToInt(sstable -> Ints.checkedCast(sstable.getSSTableMetadata().totalRows)).sum();
return new int[] { numPartitions, numRows };
}
});
}
use of org.apache.cassandra.index.internal.CollatedViewIndexBuilder in project cassandra by apache.
the class CancelCompactionsTest method testIndexRebuild.
/**
* Make sure index rebuilds get cancelled
*/
@Test
public void testIndexRebuild() throws ExecutionException, InterruptedException {
ColumnFamilyStore cfs = MockSchema.newCFS();
List<SSTableReader> sstables = createSSTables(cfs, 5, 0);
Index idx = new StubIndex(cfs, null);
CountDownLatch indexBuildStarted = new CountDownLatch(1);
CountDownLatch indexBuildRunning = new CountDownLatch(1);
CountDownLatch compactionsStopped = new CountDownLatch(1);
ReducingKeyIterator reducingKeyIterator = new ReducingKeyIterator(sstables) {
@Override
public boolean hasNext() {
indexBuildStarted.countDown();
try {
indexBuildRunning.await();
} catch (InterruptedException e) {
throw new RuntimeException();
}
return false;
}
};
Future<?> f = CompactionManager.instance.submitIndexBuild(new CollatedViewIndexBuilder(cfs, Collections.singleton(idx), reducingKeyIterator, ImmutableSet.copyOf(sstables)));
// wait for hasNext to get called
indexBuildStarted.await();
assertEquals(1, getActiveCompactionsForTable(cfs).size());
boolean foundCompaction = false;
for (CompactionInfo.Holder holder : getActiveCompactionsForTable(cfs)) {
if (holder.getCompactionInfo().getSSTables().equals(new HashSet<>(sstables))) {
assertFalse(holder.isStopRequested());
foundCompaction = true;
}
}
assertTrue(foundCompaction);
cfs.runWithCompactionsDisabled(() -> {
compactionsStopped.countDown();
return null;
}, (sstable) -> true, false, false, true);
// wait for the runWithCompactionsDisabled callable
compactionsStopped.await();
assertEquals(1, getActiveCompactionsForTable(cfs).size());
foundCompaction = false;
for (CompactionInfo.Holder holder : getActiveCompactionsForTable(cfs)) {
if (holder.getCompactionInfo().getSSTables().equals(new HashSet<>(sstables))) {
assertTrue(holder.isStopRequested());
foundCompaction = true;
}
}
assertTrue(foundCompaction);
// signal that the index build should be finished
indexBuildRunning.countDown();
f.get();
assertTrue(getActiveCompactionsForTable(cfs).isEmpty());
}
Aggregations