Search in sources :

Example 1 with CompactionInfo

use of org.apache.cassandra.db.compaction.CompactionInfo in project cassandra by apache.

the class PendingAntiCompactionTest method testRetries.

@Test
public void testRetries() throws InterruptedException, ExecutionException {
    ColumnFamilyStore cfs = MockSchema.newCFS();
    cfs.addSSTable(MockSchema.sstable(1, true, cfs));
    CountDownLatch cdl = new CountDownLatch(5);
    ExecutorPlus es = executorFactory().sequential("test");
    CompactionInfo.Holder holder = new CompactionInfo.Holder() {

        public CompactionInfo getCompactionInfo() {
            return new CompactionInfo(cfs.metadata(), OperationType.ANTICOMPACTION, 0, 0, UUID.randomUUID(), cfs.getLiveSSTables());
        }

        public boolean isGlobal() {
            return false;
        }
    };
    try {
        PendingAntiCompaction.AntiCompactionPredicate acp = new PendingAntiCompaction.AntiCompactionPredicate(FULL_RANGE, UUID.randomUUID()) {

            @Override
            public boolean apply(SSTableReader sstable) {
                cdl.countDown();
                if (cdl.getCount() > 0)
                    throw new PendingAntiCompaction.SSTableAcquisitionException("blah");
                return true;
            }
        };
        CompactionManager.instance.active.beginCompaction(holder);
        PendingAntiCompaction.AcquisitionCallable acquisitionCallable = new PendingAntiCompaction.AcquisitionCallable(cfs, UUID.randomUUID(), 10, 1, acp);
        Future f = es.submit(acquisitionCallable);
        cdl.await();
        assertNotNull(f.get());
    } finally {
        es.shutdown();
        CompactionManager.instance.active.finishCompaction(holder);
    }
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) ExecutorPlus(org.apache.cassandra.concurrent.ExecutorPlus) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) Future(org.apache.cassandra.utils.concurrent.Future) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) CompactionInfo(org.apache.cassandra.db.compaction.CompactionInfo) AbstractPendingRepairTest(org.apache.cassandra.db.compaction.AbstractPendingRepairTest) Test(org.junit.Test)

Example 2 with CompactionInfo

use of org.apache.cassandra.db.compaction.CompactionInfo in project cassandra by apache.

the class PendingAntiCompactionTest method testRetriesTimeout.

@Test
public void testRetriesTimeout() throws InterruptedException, ExecutionException {
    ColumnFamilyStore cfs = MockSchema.newCFS();
    cfs.addSSTable(MockSchema.sstable(1, true, cfs));
    ExecutorPlus es = executorFactory().sequential("test");
    CompactionInfo.Holder holder = new CompactionInfo.Holder() {

        public CompactionInfo getCompactionInfo() {
            return new CompactionInfo(cfs.metadata(), OperationType.ANTICOMPACTION, 0, 0, UUID.randomUUID(), cfs.getLiveSSTables());
        }

        public boolean isGlobal() {
            return false;
        }
    };
    try {
        PendingAntiCompaction.AntiCompactionPredicate acp = new PendingAntiCompaction.AntiCompactionPredicate(FULL_RANGE, UUID.randomUUID()) {

            @Override
            public boolean apply(SSTableReader sstable) {
                throw new PendingAntiCompaction.SSTableAcquisitionException("blah");
            }
        };
        CompactionManager.instance.active.beginCompaction(holder);
        PendingAntiCompaction.AcquisitionCallable acquisitionCallable = new PendingAntiCompaction.AcquisitionCallable(cfs, UUID.randomUUID(), 2, 1000, acp);
        Future fut = es.submit(acquisitionCallable);
        assertNull(fut.get());
    } finally {
        es.shutdown();
        CompactionManager.instance.active.finishCompaction(holder);
    }
}
Also used : SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) ExecutorPlus(org.apache.cassandra.concurrent.ExecutorPlus) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) Future(org.apache.cassandra.utils.concurrent.Future) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) CompactionInfo(org.apache.cassandra.db.compaction.CompactionInfo) AbstractPendingRepairTest(org.apache.cassandra.db.compaction.AbstractPendingRepairTest) Test(org.junit.Test)

Example 3 with CompactionInfo

use of org.apache.cassandra.db.compaction.CompactionInfo in project cassandra by apache.

the class CompactionStatsTest method testCompactionStats.

@Test
public void testCompactionStats() {
    createTable("CREATE TABLE %s (pk int, ck int, PRIMARY KEY (pk, ck))");
    ColumnFamilyStore cfs = getCurrentColumnFamilyStore();
    long bytesCompacted = 123;
    long bytesTotal = 123456;
    UUID compactionId = UUID.randomUUID();
    List<SSTableReader> sstables = IntStream.range(0, 10).mapToObj(i -> MockSchema.sstable(i, i * 10L, i * 10L + 9, cfs)).collect(Collectors.toList());
    CompactionInfo.Holder compactionHolder = new CompactionInfo.Holder() {

        public CompactionInfo getCompactionInfo() {
            return new CompactionInfo(cfs.metadata(), OperationType.COMPACTION, bytesCompacted, bytesTotal, compactionId, sstables);
        }

        public boolean isGlobal() {
            return false;
        }
    };
    CompactionManager.instance.active.beginCompaction(compactionHolder);
    ToolRunner.ToolResult tool = ToolRunner.invokeNodetool("compactionstats");
    tool.assertOnCleanExit();
    String stdout = tool.getStdout();
    assertThat(stdout).contains("pending tasks: 1");
    Assertions.assertThat(stdout).containsPattern("keyspace\\s+table\\s+task id\\s+completion ratio\\s+kind\\s+progress\\s+sstables\\s+total\\s+unit");
    String expectedStatsPattern = String.format("%s\\s+%s\\s+%s\\s+%.2f%%\\s+%s\\s+%s\\s+%s\\s+%s\\s+%s", CQLTester.KEYSPACE, currentTable(), compactionId, (double) bytesCompacted / bytesTotal * 100, OperationType.COMPACTION, bytesCompacted, sstables.size(), bytesTotal, CompactionInfo.Unit.BYTES);
    Assertions.assertThat(stdout).containsPattern(expectedStatsPattern);
    CompactionManager.instance.active.finishCompaction(compactionHolder);
    tool = ToolRunner.invokeNodetool("compactionstats");
    tool.assertOnCleanExit();
    stdout = tool.getStdout();
    assertThat(stdout).contains("pending tasks: 0");
}
Also used : IntStream(java.util.stream.IntStream) CompactionManager(org.apache.cassandra.db.compaction.CompactionManager) BeforeClass(org.junit.BeforeClass) CQLTester(org.apache.cassandra.cql3.CQLTester) MockSchema(org.apache.cassandra.schema.MockSchema) ToolRunner(org.apache.cassandra.tools.ToolRunner) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.junit.Test) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) CompactionInfo(org.apache.cassandra.db.compaction.CompactionInfo) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) List(java.util.List) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) OperationType(org.apache.cassandra.db.compaction.OperationType) Assertions(org.assertj.core.api.Assertions) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) ToolRunner(org.apache.cassandra.tools.ToolRunner) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) CompactionInfo(org.apache.cassandra.db.compaction.CompactionInfo) UUID(java.util.UUID) Test(org.junit.Test)

Example 4 with CompactionInfo

use of org.apache.cassandra.db.compaction.CompactionInfo in project cassandra by apache.

the class CompactionStatsTest method testCompactionStatsHumanReadable.

@Test
public void testCompactionStatsHumanReadable() {
    createTable("CREATE TABLE %s (pk int, ck int, PRIMARY KEY (pk, ck))");
    ColumnFamilyStore cfs = getCurrentColumnFamilyStore();
    long bytesCompacted = 123;
    long bytesTotal = 123456;
    UUID compactionId = UUID.randomUUID();
    List<SSTableReader> sstables = IntStream.range(0, 10).mapToObj(i -> MockSchema.sstable(i, i * 10L, i * 10L + 9, cfs)).collect(Collectors.toList());
    CompactionInfo.Holder compactionHolder = new CompactionInfo.Holder() {

        public CompactionInfo getCompactionInfo() {
            return new CompactionInfo(cfs.metadata(), OperationType.COMPACTION, bytesCompacted, bytesTotal, compactionId, sstables);
        }

        public boolean isGlobal() {
            return false;
        }
    };
    CompactionManager.instance.active.beginCompaction(compactionHolder);
    ToolRunner.ToolResult tool = ToolRunner.invokeNodetool("compactionstats", "--human-readable");
    tool.assertOnCleanExit();
    String stdout = tool.getStdout();
    assertThat(stdout).contains("pending tasks: 1");
    Assertions.assertThat(stdout).containsPattern("keyspace\\s+table\\s+task id\\s+completion ratio\\s+kind\\s+progress\\s+sstables\\s+total\\s+unit");
    String expectedStatsPattern = String.format("%s\\s+%s\\s+%s\\s+%.2f%%\\s+%s\\s+%s\\s+%s\\s+%s\\s+%s", CQLTester.KEYSPACE, currentTable(), compactionId, (double) bytesCompacted / bytesTotal * 100, OperationType.COMPACTION, "123 bytes", sstables.size(), "120.56 KiB", CompactionInfo.Unit.BYTES);
    Assertions.assertThat(stdout).containsPattern(expectedStatsPattern);
    CompactionManager.instance.active.finishCompaction(compactionHolder);
    tool = ToolRunner.invokeNodetool("compactionstats", "--human-readable");
    tool.assertOnCleanExit();
    stdout = tool.getStdout();
    assertThat(stdout).contains("pending tasks: 0");
}
Also used : IntStream(java.util.stream.IntStream) CompactionManager(org.apache.cassandra.db.compaction.CompactionManager) BeforeClass(org.junit.BeforeClass) CQLTester(org.apache.cassandra.cql3.CQLTester) MockSchema(org.apache.cassandra.schema.MockSchema) ToolRunner(org.apache.cassandra.tools.ToolRunner) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.junit.Test) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) CompactionInfo(org.apache.cassandra.db.compaction.CompactionInfo) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) List(java.util.List) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) OperationType(org.apache.cassandra.db.compaction.OperationType) Assertions(org.assertj.core.api.Assertions) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) ToolRunner(org.apache.cassandra.tools.ToolRunner) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) CompactionInfo(org.apache.cassandra.db.compaction.CompactionInfo) UUID(java.util.UUID) Test(org.junit.Test)

Example 5 with CompactionInfo

use of org.apache.cassandra.db.compaction.CompactionInfo in project cassandra by apache.

the class SSTableTasksTableTest method testSelectAll.

@Test
public void testSelectAll() throws Throwable {
    createTable("CREATE TABLE %s (pk int, ck int, PRIMARY KEY (pk, ck))");
    ColumnFamilyStore cfs = getCurrentColumnFamilyStore();
    long bytesCompacted = 123;
    long bytesTotal = 123456;
    UUID compactionId = UUID.randomUUID();
    List<SSTableReader> sstables = IntStream.range(0, 10).mapToObj(i -> MockSchema.sstable(i, i * 10L, i * 10L + 9, cfs)).collect(Collectors.toList());
    CompactionInfo.Holder compactionHolder = new CompactionInfo.Holder() {

        public CompactionInfo getCompactionInfo() {
            return new CompactionInfo(cfs.metadata(), OperationType.COMPACTION, bytesCompacted, bytesTotal, compactionId, sstables);
        }

        public boolean isGlobal() {
            return false;
        }
    };
    CompactionManager.instance.active.beginCompaction(compactionHolder);
    UntypedResultSet result = execute("SELECT * FROM vts.sstable_tasks");
    assertRows(result, row(CQLTester.KEYSPACE, currentTable(), compactionId, 1.0 * bytesCompacted / bytesTotal, OperationType.COMPACTION.toString().toLowerCase(), bytesCompacted, sstables.size(), bytesTotal, CompactionInfo.Unit.BYTES.toString()));
    CompactionManager.instance.active.finishCompaction(compactionHolder);
    result = execute("SELECT * FROM vts.sstable_tasks");
    assertEmpty(result);
}
Also used : IntStream(java.util.stream.IntStream) CompactionManager(org.apache.cassandra.db.compaction.CompactionManager) BeforeClass(org.junit.BeforeClass) CQLTester(org.apache.cassandra.cql3.CQLTester) MockSchema(org.apache.cassandra.schema.MockSchema) Test(org.junit.Test) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) CompactionInfo(org.apache.cassandra.db.compaction.CompactionInfo) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) OperationType(org.apache.cassandra.db.compaction.OperationType) UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet) Before(org.junit.Before) UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) CompactionInfo(org.apache.cassandra.db.compaction.CompactionInfo) UUID(java.util.UUID) Test(org.junit.Test)

Aggregations

CompactionInfo (org.apache.cassandra.db.compaction.CompactionInfo)8 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)6 SSTableReader (org.apache.cassandra.io.sstable.format.SSTableReader)6 Test (org.junit.Test)5 List (java.util.List)3 UUID (java.util.UUID)3 Collectors (java.util.stream.Collectors)3 IntStream (java.util.stream.IntStream)3 CQLTester (org.apache.cassandra.cql3.CQLTester)3 CompactionManager (org.apache.cassandra.db.compaction.CompactionManager)3 OperationType (org.apache.cassandra.db.compaction.OperationType)3 MockSchema (org.apache.cassandra.schema.MockSchema)3 BeforeClass (org.junit.BeforeClass)3 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 ExecutorPlus (org.apache.cassandra.concurrent.ExecutorPlus)2 AbstractPendingRepairTest (org.apache.cassandra.db.compaction.AbstractPendingRepairTest)2 ToolRunner (org.apache.cassandra.tools.ToolRunner)2 Future (org.apache.cassandra.utils.concurrent.Future)2 Assertions (org.assertj.core.api.Assertions)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2