Search in sources :

Example 21 with CompactionConfig

use of org.apache.accumulo.core.client.admin.CompactionConfig in project accumulo by apache.

the class CompactCommand method execute.

@Override
public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws Exception {
    if (cl.hasOption(cancelOpt.getLongOpt())) {
        cancel = true;
        if (cl.getOptions().length > 2) {
            throw new IllegalArgumentException("Can not specify other options with cancel");
        }
    } else {
        cancel = false;
    }
    compactionConfig = new CompactionConfig();
    compactionConfig.setFlush(!cl.hasOption(noFlushOption.getOpt()));
    compactionConfig.setWait(cl.hasOption(waitOpt.getOpt()));
    compactionConfig.setStartRow(OptUtil.getStartRow(cl));
    compactionConfig.setEndRow(OptUtil.getEndRow(cl));
    if (cl.hasOption(profileOpt.getOpt())) {
        List<IteratorSetting> iterators = shellState.iteratorProfiles.get(cl.getOptionValue(profileOpt.getOpt()));
        if (iterators == null) {
            Shell.log.error("Profile {} does not exist", cl.getOptionValue(profileOpt.getOpt()));
            return -1;
        }
        compactionConfig.setIterators(new ArrayList<>(iterators));
    }
    setupConfigurableCompaction(cl, compactionConfig);
    if (cl.hasOption(strategyOpt.getOpt())) {
        if (cl.hasOption(selectorOpt.getLongOpt()) || cl.hasOption(configurerOpt.getLongOpt())) {
            throw new IllegalArgumentException("Can not specify a strategy with a selector or configurer");
        }
        configureCompactionStrat(cl);
    } else {
        if (cl.hasOption(selectorOpt.getLongOpt())) {
            compactionConfig.setSelector(new PluginConfig(cl.getOptionValue(selectorOpt.getLongOpt()), ShellUtil.parseMapOpt(cl, selectorConfigOpt)));
        }
        if (cl.hasOption(configurerOpt.getLongOpt())) {
            compactionConfig.setConfigurer(new PluginConfig(cl.getOptionValue(configurerOpt.getLongOpt()), ShellUtil.parseMapOpt(cl, configurerConfigOpt)));
        }
    }
    if (cl.hasOption(hintsOption.getLongOpt())) {
        compactionConfig.setExecutionHints(ShellUtil.parseMapOpt(cl, hintsOption));
    }
    return super.execute(fullCommand, cl, shellState);
}
Also used : PluginConfig(org.apache.accumulo.core.client.admin.PluginConfig) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) CompactionConfig(org.apache.accumulo.core.client.admin.CompactionConfig)

Example 22 with CompactionConfig

use of org.apache.accumulo.core.client.admin.CompactionConfig in project accumulo by apache.

the class SummaryIT method compactionSelectorTest.

@Test
public void compactionSelectorTest() throws Exception {
    // Create a compaction config that will filter out foos if there are too many. Uses summary
    // data to know if there are too many foos.
    PluginConfig csc = new PluginConfig(FooSelector.class.getName());
    CompactionConfig compactConfig = new CompactionConfig().setSelector(csc);
    compactionTest(compactConfig);
}
Also used : PluginConfig(org.apache.accumulo.core.client.admin.PluginConfig) CompactionConfig(org.apache.accumulo.core.client.admin.CompactionConfig) Test(org.junit.Test)

Example 23 with CompactionConfig

use of org.apache.accumulo.core.client.admin.CompactionConfig in project accumulo by apache.

the class SummaryIT method tooLargeTest.

@Test
public void tooLargeTest() throws Exception {
    final String table = getUniqueNames(1)[0];
    try (AccumuloClient c = Accumulo.newClient().from(getClientProps()).build()) {
        NewTableConfiguration ntc = new NewTableConfiguration();
        SummarizerConfiguration sc1 = SummarizerConfiguration.builder(BigSummarizer.class).build();
        ntc.enableSummarization(sc1);
        c.tableOperations().create(table, ntc);
        try (BatchWriter bw = c.createBatchWriter(table)) {
            write(bw, "a_large", "f1", "q1", "v1");
            write(bw, "v_small", "f1", "q1", "v2");
        }
        c.tableOperations().flush(table, null, null, true);
        Summary summary = c.tableOperations().summaries(table).retrieve().get(0);
        assertEquals(1, summary.getFileStatistics().getLarge());
        assertEquals(0, summary.getFileStatistics().getMissing());
        assertEquals(0, summary.getFileStatistics().getExtra());
        assertEquals(0, summary.getFileStatistics().getDeleted());
        assertEquals(1, summary.getFileStatistics().getInaccurate());
        assertEquals(1, summary.getFileStatistics().getTotal());
        assertEquals(Collections.emptyMap(), summary.getStatistics());
        // create situation where one tablet has summary data and one does not because the summary
        // data
        // was too large
        c.tableOperations().addSplits(table, new TreeSet<>(Collections.singleton(new Text("m"))));
        c.tableOperations().compact(table, new CompactionConfig().setWait(true));
        summary = c.tableOperations().summaries(table).retrieve().get(0);
        assertEquals(1, summary.getFileStatistics().getLarge());
        assertEquals(0, summary.getFileStatistics().getMissing());
        assertEquals(0, summary.getFileStatistics().getExtra());
        assertEquals(0, summary.getFileStatistics().getDeleted());
        assertEquals(1, summary.getFileStatistics().getInaccurate());
        assertEquals(2, summary.getFileStatistics().getTotal());
        HashMap<String, Long> expected = new HashMap<>();
        for (int i = 0; i < 10; i++) {
            expected.put(String.format("%09x", i), i * 19L);
        }
        assertEquals(expected, summary.getStatistics());
    }
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) HashMap(java.util.HashMap) Text(org.apache.hadoop.io.Text) NewTableConfiguration(org.apache.accumulo.core.client.admin.NewTableConfiguration) CompactionConfig(org.apache.accumulo.core.client.admin.CompactionConfig) CounterSummary(org.apache.accumulo.core.client.summary.CounterSummary) Summary(org.apache.accumulo.core.client.summary.Summary) BatchWriter(org.apache.accumulo.core.client.BatchWriter) SummarizerConfiguration(org.apache.accumulo.core.client.summary.SummarizerConfiguration) Test(org.junit.Test)

Example 24 with CompactionConfig

use of org.apache.accumulo.core.client.admin.CompactionConfig in project accumulo by apache.

the class SummaryIT method compactionStrategyTest.

@SuppressWarnings("removal")
@Test
public void compactionStrategyTest() throws Exception {
    var csc = new org.apache.accumulo.core.client.admin.CompactionStrategyConfig(FooCS.class.getName());
    CompactionConfig compactConfig = new CompactionConfig().setCompactionStrategy(csc);
    compactionTest(compactConfig);
}
Also used : CompactionConfig(org.apache.accumulo.core.client.admin.CompactionConfig) Test(org.junit.Test)

Example 25 with CompactionConfig

use of org.apache.accumulo.core.client.admin.CompactionConfig in project accumulo by apache.

the class SummaryIT method basicSummaryTest.

@Test
public void basicSummaryTest() throws Exception {
    final String table = getUniqueNames(1)[0];
    try (AccumuloClient c = Accumulo.newClient().from(getClientProps()).build()) {
        NewTableConfiguration ntc = new NewTableConfiguration();
        SummarizerConfiguration sc1 = SummarizerConfiguration.builder(BasicSummarizer.class.getName()).build();
        ntc.enableSummarization(sc1);
        c.tableOperations().create(table, ntc);
        BatchWriter bw = writeData(table, c);
        Collection<Summary> summaries = c.tableOperations().summaries(table).flush(false).retrieve();
        assertEquals(0, summaries.size());
        LongSummaryStatistics stats = getTimestampStats(table, c);
        summaries = c.tableOperations().summaries(table).flush(true).retrieve();
        checkSummaries(summaries, sc1, 1, 0, 0, TOTAL_STAT, 100_000L, MIN_TIMESTAMP_STAT, stats.getMin(), MAX_TIMESTAMP_STAT, stats.getMax(), DELETES_STAT, 0L);
        Mutation m = new Mutation(String.format("r%09x", 999));
        m.put("f1", "q1", "999-0");
        m.putDelete("f1", "q2");
        bw.addMutation(m);
        bw.flush();
        c.tableOperations().flush(table, null, null, true);
        stats = getTimestampStats(table, c);
        summaries = c.tableOperations().summaries(table).retrieve();
        checkSummaries(summaries, sc1, 2, 0, 0, TOTAL_STAT, 100_002L, MIN_TIMESTAMP_STAT, stats.getMin(), MAX_TIMESTAMP_STAT, stats.getMax(), DELETES_STAT, 1L);
        bw.close();
        c.tableOperations().compact(table, new CompactionConfig().setWait(true));
        summaries = c.tableOperations().summaries(table).retrieve();
        checkSummaries(summaries, sc1, 1, 0, 0, TOTAL_STAT, 100_000L, MIN_TIMESTAMP_STAT, stats.getMin(), MAX_TIMESTAMP_STAT, stats.getMax(), DELETES_STAT, 0L);
        // split tablet into two
        String sp1 = String.format("r%09x", 50_000);
        addSplits(table, c, sp1);
        summaries = c.tableOperations().summaries(table).retrieve();
        checkSummaries(summaries, sc1, 1, 0, 0, TOTAL_STAT, 100_000L, MIN_TIMESTAMP_STAT, stats.getMin(), MAX_TIMESTAMP_STAT, stats.getMax(), DELETES_STAT, 0L);
        // compact 2nd tablet
        c.tableOperations().compact(table, new CompactionConfig().setStartRow(new Text(sp1)).setWait(true));
        summaries = c.tableOperations().summaries(table).retrieve();
        checkSummaries(summaries, sc1, 2, 0, 1, TOTAL_STAT, 113_999L, MIN_TIMESTAMP_STAT, stats.getMin(), MAX_TIMESTAMP_STAT, stats.getMax(), DELETES_STAT, 0L);
        // get summaries for first tablet
        stats = getTimestampStats(table, c, sp1, null);
        summaries = c.tableOperations().summaries(table).startRow(sp1).retrieve();
        checkSummaries(summaries, sc1, 1, 0, 0, TOTAL_STAT, 49_999L, MIN_TIMESTAMP_STAT, stats.getMin(), MAX_TIMESTAMP_STAT, stats.getMax(), DELETES_STAT, 0L);
        // compact all tablets and regenerate all summaries
        c.tableOperations().compact(table, new CompactionConfig());
        summaries = c.tableOperations().summaries(table).retrieve();
        stats = getTimestampStats(table, c);
        checkSummaries(summaries, sc1, 2, 0, 0, TOTAL_STAT, 100_000L, MIN_TIMESTAMP_STAT, stats.getMin(), MAX_TIMESTAMP_STAT, stats.getMax(), DELETES_STAT, 0L);
        summaries = c.tableOperations().summaries(table).startRow(String.format("r%09x", 75_000)).endRow(String.format("r%09x", 80_000)).retrieve();
        Summary summary = Iterables.getOnlyElement(summaries);
        assertEquals(1, summary.getFileStatistics().getTotal());
        assertEquals(1, summary.getFileStatistics().getExtra());
        long total = summary.getStatistics().get(TOTAL_STAT);
        assertTrue("Total " + total + " out of expected range", total > 0 && total <= 10_000);
        // test adding and removing
        c.tableOperations().removeSummarizers(table, sc -> sc.getClassName().contains("foo"));
        List<SummarizerConfiguration> summarizers = c.tableOperations().listSummarizers(table);
        assertEquals(1, summarizers.size());
        assertTrue(summarizers.contains(sc1));
        c.tableOperations().removeSummarizers(table, sc -> sc.getClassName().equals(BasicSummarizer.class.getName()));
        summarizers = c.tableOperations().listSummarizers(table);
        assertEquals(0, summarizers.size());
        c.tableOperations().compact(table, new CompactionConfig().setWait(true));
        summaries = c.tableOperations().summaries(table).retrieve();
        assertEquals(0, summaries.size());
        c.tableOperations().addSummarizers(table, sc1);
        c.tableOperations().compact(table, new CompactionConfig().setWait(true));
        summaries = c.tableOperations().summaries(table).retrieve();
        checkSummaries(summaries, sc1, 2, 0, 0, TOTAL_STAT, 100_000L, MIN_TIMESTAMP_STAT, stats.getMin(), MAX_TIMESTAMP_STAT, stats.getMax(), DELETES_STAT, 0L);
    }
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) Text(org.apache.hadoop.io.Text) LongSummaryStatistics(java.util.LongSummaryStatistics) NewTableConfiguration(org.apache.accumulo.core.client.admin.NewTableConfiguration) CompactionConfig(org.apache.accumulo.core.client.admin.CompactionConfig) CounterSummary(org.apache.accumulo.core.client.summary.CounterSummary) Summary(org.apache.accumulo.core.client.summary.Summary) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) SummarizerConfiguration(org.apache.accumulo.core.client.summary.SummarizerConfiguration) Test(org.junit.Test)

Aggregations

CompactionConfig (org.apache.accumulo.core.client.admin.CompactionConfig)57 Test (org.junit.Test)36 AccumuloClient (org.apache.accumulo.core.client.AccumuloClient)32 Mutation (org.apache.accumulo.core.data.Mutation)21 BatchWriter (org.apache.accumulo.core.client.BatchWriter)20 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)17 Value (org.apache.accumulo.core.data.Value)14 PluginConfig (org.apache.accumulo.core.client.admin.PluginConfig)12 Scanner (org.apache.accumulo.core.client.Scanner)11 CompactionStrategyConfig (org.apache.accumulo.core.client.admin.CompactionStrategyConfig)11 NewTableConfiguration (org.apache.accumulo.core.client.admin.NewTableConfiguration)11 Text (org.apache.hadoop.io.Text)10 AccumuloException (org.apache.accumulo.core.client.AccumuloException)9 Connector (org.apache.accumulo.core.client.Connector)9 Key (org.apache.accumulo.core.data.Key)9 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)6 File (java.io.File)5 IOException (java.io.IOException)5 HashMap (java.util.HashMap)5 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)5