Search in sources :

Example 16 with CompactionConfig

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

the class ConcurrentDeleteTableIT method testConcurrentFateOpsWithDelete.

@Test
public void testConcurrentFateOpsWithDelete() throws Exception {
    final Connector c = getConnector();
    String[] tables = getUniqueNames(2);
    TreeSet<Text> splits = createSplits();
    int numOperations = 8;
    ExecutorService es = Executors.newFixedThreadPool(numOperations);
    int count = 0;
    for (final String table : tables) {
        c.tableOperations().create(table);
        c.tableOperations().addSplits(table, splits);
        writeData(c, table);
        if (count == 1) {
            c.tableOperations().flush(table, null, null, true);
        }
        count++;
        // increment this for each test
        final CountDownLatch cdl = new CountDownLatch(numOperations);
        List<Future<?>> futures = new ArrayList<>();
        futures.add(es.submit(new Runnable() {

            @Override
            public void run() {
                try {
                    cdl.countDown();
                    cdl.await();
                    c.tableOperations().delete(table);
                } catch (TableNotFoundException | TableOfflineException e) {
                // expected
                } catch (InterruptedException | AccumuloException | AccumuloSecurityException e) {
                    throw new RuntimeException(e);
                }
            }
        }));
        futures.add(es.submit(new DelayedTableOp(cdl) {

            @Override
            protected void doTableOp() throws Exception {
                c.tableOperations().compact(table, new CompactionConfig());
            }
        }));
        futures.add(es.submit(new DelayedTableOp(cdl) {

            @Override
            protected void doTableOp() throws Exception {
                c.tableOperations().merge(table, null, null);
            }
        }));
        futures.add(es.submit(new DelayedTableOp(cdl) {

            @Override
            protected void doTableOp() throws Exception {
                Map<String, String> m = Collections.emptyMap();
                Set<String> s = Collections.emptySet();
                c.tableOperations().clone(table, table + "_clone", true, m, s);
            }
        }));
        futures.add(es.submit(new DelayedTableOp(cdl) {

            @Override
            protected void doTableOp() throws Exception {
                c.tableOperations().deleteRows(table, null, null);
            }
        }));
        futures.add(es.submit(new DelayedTableOp(cdl) {

            @Override
            protected void doTableOp() throws Exception {
                c.tableOperations().cancelCompaction(table);
            }
        }));
        futures.add(es.submit(new DelayedTableOp(cdl) {

            @Override
            protected void doTableOp() throws Exception {
                c.tableOperations().rename(table, table + "_renamed");
            }
        }));
        futures.add(es.submit(new DelayedTableOp(cdl) {

            @Override
            protected void doTableOp() throws Exception {
                c.tableOperations().offline(table);
            }
        }));
        Assert.assertEquals(numOperations, futures.size());
        for (Future<?> future : futures) {
            future.get();
        }
        try {
            c.createScanner(table, Authorizations.EMPTY);
            Assert.fail("Expected table " + table + " to be gone.");
        } catch (TableNotFoundException tnfe) {
        // expected
        }
        FunctionalTestUtils.assertNoDanglingFateLocks(getConnector().getInstance(), getCluster());
    }
    es.shutdown();
}
Also used : Connector(org.apache.accumulo.core.client.Connector) TableOfflineException(org.apache.accumulo.core.client.TableOfflineException) ArrayList(java.util.ArrayList) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) CompactionConfig(org.apache.accumulo.core.client.admin.CompactionConfig) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) Text(org.apache.hadoop.io.Text) CountDownLatch(java.util.concurrent.CountDownLatch) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) Test(org.junit.Test)

Example 17 with CompactionConfig

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

the class KerberosIT method testUserPrivilegesThroughGrant.

@Test
public void testUserPrivilegesThroughGrant() throws Exception {
    String user1 = testName.getMethodName();
    final File user1Keytab = new File(kdc.getKeytabDir(), user1 + ".keytab");
    if (user1Keytab.exists() && !user1Keytab.delete()) {
        log.warn("Unable to delete {}", user1Keytab);
    }
    // Create some new users
    kdc.createPrincipal(user1Keytab, user1);
    final String qualifiedUser1 = kdc.qualifyUser(user1);
    // Log in as user1
    UserGroupInformation ugi = UserGroupInformation.loginUserFromKeytabAndReturnUGI(user1, user1Keytab.getAbsolutePath());
    log.info("Logged in as {}", user1);
    ugi.doAs(new PrivilegedExceptionAction<Void>() {

        @Override
        public Void run() throws Exception {
            // Indirectly creates this user when we use it
            Connector conn = mac.getConnector(qualifiedUser1, new KerberosToken());
            log.info("Created connector as {}", qualifiedUser1);
            // The new user should have no system permissions
            for (SystemPermission perm : SystemPermission.values()) {
                assertFalse(conn.securityOperations().hasSystemPermission(qualifiedUser1, perm));
            }
            return null;
        }
    });
    ugi = UserGroupInformation.loginUserFromKeytabAndReturnUGI(rootUser.getPrincipal(), rootUser.getKeytab().getAbsolutePath());
    ugi.doAs(new PrivilegedExceptionAction<Void>() {

        @Override
        public Void run() throws Exception {
            Connector conn = mac.getConnector(rootUser.getPrincipal(), new KerberosToken());
            conn.securityOperations().grantSystemPermission(qualifiedUser1, SystemPermission.CREATE_TABLE);
            return null;
        }
    });
    // Switch back to the original user
    ugi = UserGroupInformation.loginUserFromKeytabAndReturnUGI(user1, user1Keytab.getAbsolutePath());
    ugi.doAs(new PrivilegedExceptionAction<Void>() {

        @Override
        public Void run() throws Exception {
            Connector conn = mac.getConnector(qualifiedUser1, new KerberosToken());
            // Shouldn't throw an exception since we granted the create table permission
            final String table = testName.getMethodName() + "_user_table";
            conn.tableOperations().create(table);
            // Make sure we can actually use the table we made
            BatchWriter bw = conn.createBatchWriter(table, new BatchWriterConfig());
            Mutation m = new Mutation("a");
            m.put("b", "c", "d");
            bw.addMutation(m);
            bw.close();
            conn.tableOperations().compact(table, new CompactionConfig().setWait(true).setFlush(true));
            return null;
        }
    });
}
Also used : Connector(org.apache.accumulo.core.client.Connector) KerberosToken(org.apache.accumulo.core.client.security.tokens.KerberosToken) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) TableExistsException(org.apache.accumulo.core.client.TableExistsException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) SystemPermission(org.apache.accumulo.core.security.SystemPermission) CompactionConfig(org.apache.accumulo.core.client.admin.CompactionConfig) BatchWriterConfig(org.apache.accumulo.core.client.BatchWriterConfig) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) File(java.io.File) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) Test(org.junit.Test)

Example 18 with CompactionConfig

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

the class SummaryIT method compactionTest.

@Test
public void compactionTest() throws Exception {
    final String table = getUniqueNames(1)[0];
    Connector c = getConnector();
    NewTableConfiguration ntc = new NewTableConfiguration();
    SummarizerConfiguration sc1 = SummarizerConfiguration.builder(FooCounter.class.getName()).build();
    ntc.enableSummarization(sc1);
    c.tableOperations().create(table, ntc);
    try (BatchWriter bw = c.createBatchWriter(table, new BatchWriterConfig())) {
        write(bw, "bar1", "f1", "q1", "v1");
        write(bw, "bar2", "f1", "q1", "v2");
        write(bw, "foo1", "f1", "q1", "v3");
    }
    // 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.
    CompactionStrategyConfig csc = new CompactionStrategyConfig(FooCS.class.getName());
    List<IteratorSetting> iterators = Collections.singletonList(new IteratorSetting(100, FooFilter.class));
    CompactionConfig compactConfig = new CompactionConfig().setFlush(true).setCompactionStrategy(csc).setIterators(iterators).setWait(true);
    // this compaction should make no changes because there are less foos than bars
    c.tableOperations().compact(table, compactConfig);
    try (Scanner scanner = c.createScanner(table, Authorizations.EMPTY)) {
        Stream<Entry<Key, Value>> stream = StreamSupport.stream(scanner.spliterator(), false);
        Map<String, Long> counts = // convert to row
        stream.map(e -> e.getKey().getRowData().toString()).map(// strip numbers off row
        r -> r.replaceAll("[0-9]+", "")).collect(// count different row types
        groupingBy(identity(), counting()));
        Assert.assertEquals(1l, (long) counts.getOrDefault("foo", 0l));
        Assert.assertEquals(2l, (long) counts.getOrDefault("bar", 0l));
        Assert.assertEquals(2, counts.size());
    }
    try (BatchWriter bw = c.createBatchWriter(table, new BatchWriterConfig())) {
        write(bw, "foo2", "f1", "q1", "v4");
        write(bw, "foo3", "f1", "q1", "v5");
        write(bw, "foo4", "f1", "q1", "v6");
    }
    // this compaction should remove all foos because there are more foos than bars
    c.tableOperations().compact(table, compactConfig);
    try (Scanner scanner = c.createScanner(table, Authorizations.EMPTY)) {
        Stream<Entry<Key, Value>> stream = StreamSupport.stream(scanner.spliterator(), false);
        Map<String, Long> counts = // convert to row
        stream.map(e -> e.getKey().getRowData().toString()).map(// strip numbers off row
        r -> r.replaceAll("[0-9]+", "")).collect(// count different row types
        groupingBy(identity(), counting()));
        Assert.assertEquals(0l, (long) counts.getOrDefault("foo", 0l));
        Assert.assertEquals(2l, (long) counts.getOrDefault("bar", 0l));
        Assert.assertEquals(1, counts.size());
    }
}
Also used : Arrays(java.util.Arrays) TableOfflineException(org.apache.accumulo.core.client.TableOfflineException) SortedSet(java.util.SortedSet) Collectors.counting(java.util.stream.Collectors.counting) DELETES_IGNORED_STAT(org.apache.accumulo.core.client.summary.CountingSummarizer.DELETES_IGNORED_STAT) TOO_MANY_STAT(org.apache.accumulo.core.client.summary.CountingSummarizer.TOO_MANY_STAT) AccumuloServerException(org.apache.accumulo.core.client.impl.AccumuloServerException) Text(org.apache.hadoop.io.Text) Random(java.util.Random) Mutation(org.apache.accumulo.core.data.Mutation) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) MIN_TIMESTAMP_STAT(org.apache.accumulo.test.functional.BasicSummarizer.MIN_TIMESTAMP_STAT) BatchWriterConfig(org.apache.accumulo.core.client.BatchWriterConfig) Summarizer(org.apache.accumulo.core.client.summary.Summarizer) TOTAL_STAT(org.apache.accumulo.test.functional.BasicSummarizer.TOTAL_STAT) Map(java.util.Map) Value(org.apache.accumulo.core.data.Value) PatternSyntaxException(java.util.regex.PatternSyntaxException) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) TOO_LONG_STAT(org.apache.accumulo.core.client.summary.CountingSummarizer.TOO_LONG_STAT) Collection(java.util.Collection) MutationsRejectedException(org.apache.accumulo.core.client.MutationsRejectedException) Set(java.util.Set) SecurityErrorCode(org.apache.accumulo.core.client.security.SecurityErrorCode) CompactionStrategyConfig(org.apache.accumulo.core.client.admin.CompactionStrategyConfig) List(java.util.List) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) Filter(org.apache.accumulo.core.iterators.Filter) Stream(java.util.stream.Stream) FamilySummarizer(org.apache.accumulo.core.client.summary.summarizers.FamilySummarizer) DELETES_STAT(org.apache.accumulo.test.functional.BasicSummarizer.DELETES_STAT) Function.identity(java.util.function.Function.identity) Entry(java.util.Map.Entry) Scanner(org.apache.accumulo.core.client.Scanner) ZooKeeperInstance(org.apache.accumulo.core.client.ZooKeeperInstance) SEEN_STAT(org.apache.accumulo.core.client.summary.CountingSummarizer.SEEN_STAT) CompactionPlan(org.apache.accumulo.tserver.compaction.CompactionPlan) Iterables(com.google.common.collect.Iterables) VisibilitySummarizer(org.apache.accumulo.core.client.summary.summarizers.VisibilitySummarizer) SummarizerConfiguration(org.apache.accumulo.core.client.summary.SummarizerConfiguration) UtilWaitThread(org.apache.accumulo.fate.util.UtilWaitThread) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) FileStatistics(org.apache.accumulo.core.client.summary.Summary.FileStatistics) HashMap(java.util.HashMap) CompactionConfig(org.apache.accumulo.core.client.admin.CompactionConfig) TreeSet(java.util.TreeSet) Connector(org.apache.accumulo.core.client.Connector) Builder(com.google.common.collect.ImmutableMap.Builder) NewTableConfiguration(org.apache.accumulo.core.client.admin.NewTableConfiguration) AccumuloClusterHarness(org.apache.accumulo.harness.AccumuloClusterHarness) TablePermission(org.apache.accumulo.core.security.TablePermission) Lists(com.google.common.collect.Lists) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) Key(org.apache.accumulo.core.data.Key) EMITTED_STAT(org.apache.accumulo.core.client.summary.CountingSummarizer.EMITTED_STAT) MAX_TIMESTAMP_STAT(org.apache.accumulo.test.functional.BasicSummarizer.MAX_TIMESTAMP_STAT) StreamSupport(java.util.stream.StreamSupport) CounterSummary(org.apache.accumulo.core.client.summary.CounterSummary) LongSummaryStatistics(java.util.LongSummaryStatistics) Summary(org.apache.accumulo.core.client.summary.Summary) MajorCompactionRequest(org.apache.accumulo.tserver.compaction.MajorCompactionRequest) IOException(java.io.IOException) Test(org.junit.Test) Authorizations(org.apache.accumulo.core.security.Authorizations) AccumuloException(org.apache.accumulo.core.client.AccumuloException) Range(org.apache.accumulo.core.data.Range) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) BatchWriter(org.apache.accumulo.core.client.BatchWriter) CompactionStrategy(org.apache.accumulo.tserver.compaction.CompactionStrategy) Assert(org.junit.Assert) Collections(java.util.Collections) Connector(org.apache.accumulo.core.client.Connector) Scanner(org.apache.accumulo.core.client.Scanner) CompactionStrategyConfig(org.apache.accumulo.core.client.admin.CompactionStrategyConfig) Entry(java.util.Map.Entry) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) NewTableConfiguration(org.apache.accumulo.core.client.admin.NewTableConfiguration) CompactionConfig(org.apache.accumulo.core.client.admin.CompactionConfig) BatchWriterConfig(org.apache.accumulo.core.client.BatchWriterConfig) BatchWriter(org.apache.accumulo.core.client.BatchWriter) SummarizerConfiguration(org.apache.accumulo.core.client.summary.SummarizerConfiguration) Test(org.junit.Test)

Aggregations

CompactionConfig (org.apache.accumulo.core.client.admin.CompactionConfig)18 Connector (org.apache.accumulo.core.client.Connector)14 Test (org.junit.Test)12 BatchWriter (org.apache.accumulo.core.client.BatchWriter)9 BatchWriterConfig (org.apache.accumulo.core.client.BatchWriterConfig)7 CompactionStrategyConfig (org.apache.accumulo.core.client.admin.CompactionStrategyConfig)7 AccumuloException (org.apache.accumulo.core.client.AccumuloException)6 Mutation (org.apache.accumulo.core.data.Mutation)6 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)5 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)5 Text (org.apache.hadoop.io.Text)5 Scanner (org.apache.accumulo.core.client.Scanner)4 File (java.io.File)3 HashMap (java.util.HashMap)3 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)3 Key (org.apache.accumulo.core.data.Key)3 Value (org.apache.accumulo.core.data.Value)3 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)2 LongSummaryStatistics (java.util.LongSummaryStatistics)2 Entry (java.util.Map.Entry)2