Search in sources :

Example 26 with CompactionConfig

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

the class KerberosIT method testUserPrivilegesForTable.

@SuppressFBWarnings(value = "PATH_TRAVERSAL_IN", justification = "path provided by test")
@Test
public void testUserPrivilegesForTable() 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 -- cannot contain realm
    kdc.createPrincipal(user1Keytab, user1);
    final String qualifiedUser1 = kdc.qualifyUser(user1);
    // Log in as user1
    UserGroupInformation ugi = UserGroupInformation.loginUserFromKeytabAndReturnUGI(qualifiedUser1, user1Keytab.getAbsolutePath());
    log.info("Logged in as {}", user1);
    ugi.doAs((PrivilegedExceptionAction<Void>) () -> {
        // Indirectly creates this user when we use it
        AccumuloClient client = mac.createAccumuloClient(qualifiedUser1, new KerberosToken());
        log.info("Created client as {}", qualifiedUser1);
        // The new user should have no system permissions
        for (SystemPermission perm : SystemPermission.values()) {
            assertFalse(client.securityOperations().hasSystemPermission(qualifiedUser1, perm));
        }
        return null;
    });
    final String table = testName.getMethodName() + "_user_table";
    final String viz = "viz";
    ugi = UserGroupInformation.loginUserFromKeytabAndReturnUGI(rootUser.getPrincipal(), rootUser.getKeytab().getAbsolutePath());
    ugi.doAs((PrivilegedExceptionAction<Void>) () -> {
        AccumuloClient client = mac.createAccumuloClient(rootUser.getPrincipal(), new KerberosToken());
        client.tableOperations().create(table);
        // Give our unprivileged user permission on the table we made for them
        client.securityOperations().grantTablePermission(qualifiedUser1, table, TablePermission.READ);
        client.securityOperations().grantTablePermission(qualifiedUser1, table, TablePermission.WRITE);
        client.securityOperations().grantTablePermission(qualifiedUser1, table, TablePermission.ALTER_TABLE);
        client.securityOperations().grantTablePermission(qualifiedUser1, table, TablePermission.DROP_TABLE);
        client.securityOperations().changeUserAuthorizations(qualifiedUser1, new Authorizations(viz));
        return null;
    });
    // Switch back to the original user
    ugi = UserGroupInformation.loginUserFromKeytabAndReturnUGI(qualifiedUser1, user1Keytab.getAbsolutePath());
    ugi.doAs((PrivilegedExceptionAction<Void>) () -> {
        AccumuloClient client = mac.createAccumuloClient(qualifiedUser1, new KerberosToken());
        // Make sure we can actually use the table we made
        // Write data
        final long ts = 1000L;
        try (BatchWriter bw = client.createBatchWriter(table)) {
            Mutation m = new Mutation("a");
            m.put("b", "c", new ColumnVisibility(viz.getBytes()), ts, "d");
            bw.addMutation(m);
        }
        // Compact
        client.tableOperations().compact(table, new CompactionConfig().setWait(true).setFlush(true));
        // Alter
        client.tableOperations().setProperty(table, Property.TABLE_BLOOM_ENABLED.getKey(), "true");
        // Read (and proper authorizations)
        try (Scanner s = client.createScanner(table, new Authorizations(viz))) {
            Iterator<Entry<Key, Value>> iter = s.iterator();
            assertTrue("No results from iterator", iter.hasNext());
            Entry<Key, Value> entry = iter.next();
            assertEquals(new Key("a", "b", "c", viz, ts), entry.getKey());
            assertEquals(new Value("d"), entry.getValue());
            assertFalse("Had more results from iterator", iter.hasNext());
            return null;
        }
    });
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) BatchScanner(org.apache.accumulo.core.client.BatchScanner) Scanner(org.apache.accumulo.core.client.Scanner) Authorizations(org.apache.accumulo.core.security.Authorizations) KerberosToken(org.apache.accumulo.core.client.security.tokens.KerberosToken) SystemPermission(org.apache.accumulo.core.security.SystemPermission) Entry(java.util.Map.Entry) CompactionConfig(org.apache.accumulo.core.client.admin.CompactionConfig) Iterator(java.util.Iterator) Value(org.apache.accumulo.core.data.Value) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) ColumnVisibility(org.apache.accumulo.core.security.ColumnVisibility) File(java.io.File) Key(org.apache.accumulo.core.data.Key) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) Test(org.junit.Test) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 27 with CompactionConfig

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

the class CompactionIT method testConfigurer.

@Test
public void testConfigurer() throws Exception {
    String tableName = this.getUniqueNames(1)[0];
    try (AccumuloClient client = Accumulo.newClient().from(getClientProps()).build()) {
        Map<String, String> props = Map.of(Property.TABLE_FILE_COMPRESSION_TYPE.getKey(), "none");
        NewTableConfiguration ntc = new NewTableConfiguration().setProperties(props);
        client.tableOperations().create(tableName, ntc);
        byte[] data = new byte[100000];
        Arrays.fill(data, (byte) 65);
        try (var writer = client.createBatchWriter(tableName)) {
            for (int row = 0; row < 10; row++) {
                Mutation m = new Mutation(row + "");
                m.at().family("big").qualifier("stuff").put(data);
                writer.addMutation(m);
            }
        }
        client.tableOperations().flush(tableName, null, null, true);
        // without compression, expect file to be large
        long sizes = CompactionExecutorIT.getFileSizes(client, tableName);
        assertTrue("Unexpected files sizes : " + sizes, sizes > data.length * 10 && sizes < data.length * 11);
        client.tableOperations().compact(tableName, new CompactionConfig().setWait(true).setConfigurer(new PluginConfig(CompressionConfigurer.class.getName(), Map.of(CompressionConfigurer.LARGE_FILE_COMPRESSION_TYPE, "gz", CompressionConfigurer.LARGE_FILE_COMPRESSION_THRESHOLD, data.length + ""))));
        // after compacting with compression, expect small file
        sizes = CompactionExecutorIT.getFileSizes(client, tableName);
        assertTrue("Unexpected files sizes: data: " + data.length + ", file:" + sizes, sizes < data.length);
        client.tableOperations().compact(tableName, new CompactionConfig().setWait(true));
        // after compacting without compression, expect big files again
        sizes = CompactionExecutorIT.getFileSizes(client, tableName);
        assertTrue("Unexpected files sizes : " + sizes, sizes > data.length * 10 && sizes < data.length * 11);
    }
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) PluginConfig(org.apache.accumulo.core.client.admin.PluginConfig) CompressionConfigurer(org.apache.accumulo.core.client.admin.compaction.CompressionConfigurer) NewTableConfiguration(org.apache.accumulo.core.client.admin.NewTableConfiguration) CompactionConfig(org.apache.accumulo.core.client.admin.CompactionConfig) Mutation(org.apache.accumulo.core.data.Mutation) Test(org.junit.Test)

Example 28 with CompactionConfig

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

the class CompactionIT method testUserCompactionCancellation.

@Test
public void testUserCompactionCancellation() throws Exception {
    final String table1 = this.getUniqueNames(1)[0];
    try (AccumuloClient client = Accumulo.newClient().from(getClientProps()).build()) {
        client.tableOperations().create(table1);
        try (BatchWriter bw = client.createBatchWriter(table1)) {
            for (int i = 1; i <= MAX_DATA; i++) {
                Mutation m = new Mutation(Integer.toString(i));
                m.put("cf", "cq", new Value());
                bw.addMutation(m);
                bw.flush();
                client.tableOperations().flush(table1, null, null, true);
            }
        }
        final AtomicReference<Exception> error = new AtomicReference<>();
        final AtomicBoolean started = new AtomicBoolean(false);
        Thread t = new Thread(() -> {
            try {
                started.set(true);
                IteratorSetting setting = new IteratorSetting(50, "sleepy", SlowIterator.class);
                setting.addOption("sleepTime", "3000");
                setting.addOption("seekSleepTime", "3000");
                client.tableOperations().attachIterator(table1, setting, EnumSet.of(IteratorScope.majc));
                client.tableOperations().compact(table1, new CompactionConfig().setWait(true));
            } catch (AccumuloSecurityException | TableNotFoundException | AccumuloException e) {
                error.set(e);
            }
        });
        t.start();
        while (!started.get()) {
            Thread.sleep(1000);
        }
        client.tableOperations().cancelCompaction(table1);
        t.join();
        Exception e = error.get();
        assertNotNull(e);
        assertEquals(TableOperationsImpl.COMPACTION_CANCELED_MSG, e.getMessage());
    }
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) AccumuloException(org.apache.accumulo.core.client.AccumuloException) AtomicReference(java.util.concurrent.atomic.AtomicReference) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) IOException(java.io.IOException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) Value(org.apache.accumulo.core.data.Value) CompactionConfig(org.apache.accumulo.core.client.admin.CompactionConfig) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) Test(org.junit.Test)

Example 29 with CompactionConfig

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

the class CompactionIT method testTableDeletedDuringUserCompaction.

@Test
public void testTableDeletedDuringUserCompaction() throws Exception {
    final String table1 = this.getUniqueNames(1)[0];
    try (AccumuloClient client = Accumulo.newClient().from(getClientProps()).build()) {
        client.tableOperations().create(table1);
        try (BatchWriter bw = client.createBatchWriter(table1)) {
            for (int i = 1; i <= MAX_DATA; i++) {
                Mutation m = new Mutation(Integer.toString(i));
                m.put("cf", "cq", new Value());
                bw.addMutation(m);
                bw.flush();
                client.tableOperations().flush(table1, null, null, true);
            }
        }
        final AtomicReference<Exception> error = new AtomicReference<>();
        final AtomicBoolean started = new AtomicBoolean(false);
        Thread t = new Thread(() -> {
            try {
                started.set(true);
                IteratorSetting setting = new IteratorSetting(50, "sleepy", SlowIterator.class);
                setting.addOption("sleepTime", "3000");
                setting.addOption("seekSleepTime", "3000");
                client.tableOperations().attachIterator(table1, setting, EnumSet.of(IteratorScope.majc));
                client.tableOperations().compact(table1, new CompactionConfig().setWait(true));
            } catch (AccumuloSecurityException | TableNotFoundException | AccumuloException e) {
                error.set(e);
            }
        });
        t.start();
        while (!started.get()) {
            Thread.sleep(1000);
        }
        client.tableOperations().delete(table1);
        t.join();
        Exception e = error.get();
        assertNotNull(e);
        assertEquals(TableOperationsImpl.COMPACTION_CANCELED_MSG, e.getMessage());
    }
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) AccumuloException(org.apache.accumulo.core.client.AccumuloException) AtomicReference(java.util.concurrent.atomic.AtomicReference) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) IOException(java.io.IOException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) Value(org.apache.accumulo.core.data.Value) CompactionConfig(org.apache.accumulo.core.client.admin.CompactionConfig) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) Test(org.junit.Test)

Example 30 with CompactionConfig

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

the class CompactionIT method testBadSelector.

@Test
public void testBadSelector() throws Exception {
    try (AccumuloClient c = Accumulo.newClient().from(getClientProps()).build()) {
        final String tableName = getUniqueNames(1)[0];
        NewTableConfiguration tc = new NewTableConfiguration();
        // Ensure compactions don't kick off
        tc.setProperties(Map.of(Property.TABLE_MAJC_RATIO.getKey(), "10.0"));
        c.tableOperations().create(tableName, tc);
        // Create multiple RFiles
        try (BatchWriter bw = c.createBatchWriter(tableName)) {
            for (int i = 1; i <= 4; i++) {
                Mutation m = new Mutation(Integer.toString(i));
                m.put("cf", "cq", new Value());
                bw.addMutation(m);
                bw.flush();
                c.tableOperations().flush(tableName, null, null, true);
            }
        }
        List<String> files = FunctionalTestUtils.getRFilePaths(c, tableName);
        assertEquals(4, files.size());
        String subset = files.get(0).substring(files.get(0).lastIndexOf('/') + 1) + "," + files.get(3).substring(files.get(3).lastIndexOf('/') + 1);
        CompactionConfig config = new CompactionConfig().setSelector(new PluginConfig(RandomErrorThrowingSelector.class.getName(), Map.of(RandomErrorThrowingSelector.FILE_LIST_PARAM, subset))).setWait(true);
        c.tableOperations().compact(tableName, config);
        // check that the subset of files selected are compacted, but the others remain untouched
        List<String> filesAfterCompact = FunctionalTestUtils.getRFilePaths(c, tableName);
        assertFalse(filesAfterCompact.contains(files.get(0)));
        assertTrue(filesAfterCompact.contains(files.get(1)));
        assertTrue(filesAfterCompact.contains(files.get(2)));
        assertFalse(filesAfterCompact.contains(files.get(3)));
        List<String> rows = new ArrayList<>();
        c.createScanner(tableName).forEach((k, v) -> rows.add(k.getRow().toString()));
        assertEquals(List.of("1", "2", "3", "4"), rows);
    }
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) PluginConfig(org.apache.accumulo.core.client.admin.PluginConfig) NewTableConfiguration(org.apache.accumulo.core.client.admin.NewTableConfiguration) Value(org.apache.accumulo.core.data.Value) CompactionConfig(org.apache.accumulo.core.client.admin.CompactionConfig) ArrayList(java.util.ArrayList) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) 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