Search in sources :

Example 36 with AccumuloClient

use of org.apache.accumulo.core.client.AccumuloClient in project accumulo by apache.

the class CompactionExecutorIT method testIncorrectConfigurerType.

@Test
public void testIncorrectConfigurerType() throws Exception {
    String tableName = "tict";
    try (AccumuloClient client = Accumulo.newClient().from(getClientProps()).build()) {
        client.tableOperations().create(tableName);
        addFiles(client, tableName, 5);
        var msg = assertThrows(AccumuloException.class, () -> {
            client.tableOperations().compact(tableName, new CompactionConfig().setConfigurer(new PluginConfig(TooManyDeletesSelector.class.getName())).setWait(true));
        }).getMessage();
        assertTrue("Unexpected message : " + msg, msg.contains("TabletServer could not load CompactionConfigurer"));
    }
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) PluginConfig(org.apache.accumulo.core.client.admin.PluginConfig) AccumuloException(org.apache.accumulo.core.client.AccumuloException) TooManyDeletesSelector(org.apache.accumulo.core.client.admin.compaction.TooManyDeletesSelector) CompactionConfig(org.apache.accumulo.core.client.admin.CompactionConfig) Test(org.junit.Test)

Example 37 with AccumuloClient

use of org.apache.accumulo.core.client.AccumuloClient in project accumulo by apache.

the class CompactionExecutorIT method testIteratorsWithRange.

@Test
public void testIteratorsWithRange() throws Exception {
    String tableName = "tiwr";
    try (AccumuloClient client = Accumulo.newClient().from(getClientProps()).build()) {
        SortedSet<Text> splits = new TreeSet<>();
        for (String s : List.of("f", "m", "r", "t")) splits.add(new Text(s));
        NewTableConfiguration ntc = new NewTableConfiguration().withSplits(splits);
        client.tableOperations().create(tableName, ntc);
        Map<String, String> expected = new TreeMap<>();
        try (var writer = client.createBatchWriter(tableName)) {
            int v = 0;
            for (String row : List.of("a", "h", "o", "s", "x")) {
                Mutation m = new Mutation(row);
                for (int q = 0; q < 10; q++) {
                    String qual = String.format("%03d", q);
                    String val = "v" + v++;
                    m.at().family("f").qualifier(qual).put(val);
                    expected.put(row + ":f:" + qual, val);
                }
                writer.addMutation(m);
            }
        }
        IteratorSetting iterSetting = new IteratorSetting(20, "rf", RegExFilter.class.getName());
        RegExFilter.setRegexs(iterSetting, null, null, "004|007", null, false);
        RegExFilter.setNegate(iterSetting, true);
        client.tableOperations().compact(tableName, new CompactionConfig().setStartRow(new Text("b")).setEndRow(new Text("m")).setIterators(List.of(iterSetting)).setWait(true).setFlush(true));
        for (String row : List.of("a", "h")) {
            assertTrue(expected.remove(row + ":f:004") != null);
            assertTrue(expected.remove(row + ":f:007") != null);
        }
        Map<String, String> actual = scanTable(client, tableName);
        assertEquals(expected, actual);
        iterSetting = new IteratorSetting(20, "rf", RegExFilter.class.getName());
        RegExFilter.setRegexs(iterSetting, null, null, "002|005|009", null, false);
        RegExFilter.setNegate(iterSetting, true);
        client.tableOperations().compact(tableName, new CompactionConfig().setStartRow(new Text("m")).setEndRow(new Text("u")).setIterators(List.of(iterSetting)).setWait(true));
        for (String row : List.of("o", "s", "x")) {
            assertTrue(expected.remove(row + ":f:002") != null);
            assertTrue(expected.remove(row + ":f:005") != null);
            assertTrue(expected.remove(row + ":f:009") != null);
        }
        actual = scanTable(client, tableName);
        assertEquals(expected, actual);
        iterSetting = new IteratorSetting(20, "rf", RegExFilter.class.getName());
        RegExFilter.setRegexs(iterSetting, null, null, "00[18]", null, false);
        RegExFilter.setNegate(iterSetting, true);
        client.tableOperations().compact(tableName, new CompactionConfig().setIterators(List.of(iterSetting)).setWait(true));
        for (String row : List.of("a", "h", "o", "s", "x")) {
            assertTrue(expected.remove(row + ":f:001") != null);
            assertTrue(expected.remove(row + ":f:008") != null);
        }
        actual = scanTable(client, tableName);
        assertEquals(expected, actual);
        // add all data back and force a compaction to ensure iters do not run again
        try (var writer = client.createBatchWriter(tableName)) {
            int v = 1000;
            for (String row : List.of("a", "h", "o", "s", "x")) {
                Mutation m = new Mutation(row);
                for (int q = 0; q < 10; q++) {
                    String qual = String.format("%03d", q);
                    String val = "v" + v++;
                    m.at().family("f").qualifier(qual).put(val);
                    expected.put(row + ":f:" + qual, val);
                }
                writer.addMutation(m);
            }
        }
        client.tableOperations().compact(tableName, new CompactionConfig().setWait(true).setFlush(true));
        actual = scanTable(client, tableName);
        assertEquals(expected, actual);
    }
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) Text(org.apache.hadoop.io.Text) TreeMap(java.util.TreeMap) RegExFilter(org.apache.accumulo.core.iterators.user.RegExFilter) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) TreeSet(java.util.TreeSet) 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 38 with AccumuloClient

use of org.apache.accumulo.core.client.AccumuloClient in project accumulo by apache.

the class BadIteratorMincIT method test.

@Test
public void test() throws Exception {
    try (AccumuloClient c = Accumulo.newClient().from(getClientProps()).build()) {
        String tableName = getUniqueNames(1)[0];
        c.tableOperations().create(tableName);
        IteratorSetting is = new IteratorSetting(30, BadIterator.class);
        c.tableOperations().attachIterator(tableName, is, EnumSet.of(IteratorScope.minc));
        try (BatchWriter bw = c.createBatchWriter(tableName)) {
            Mutation m = new Mutation(new Text("r1"));
            m.put("acf", tableName, "1");
            bw.addMutation(m);
        }
        c.tableOperations().flush(tableName, null, null, false);
        sleepUninterruptibly(1, TimeUnit.SECONDS);
        // minc should fail, so there should be no files
        FunctionalTestUtils.checkRFiles(c, tableName, 1, 1, 0, 0);
        // try to scan table
        try (Scanner scanner = c.createScanner(tableName, Authorizations.EMPTY)) {
            int count = Iterators.size(scanner.iterator());
            assertEquals("Did not see expected # entries " + count, 1, count);
            // remove the bad iterator
            c.tableOperations().removeIterator(tableName, BadIterator.class.getSimpleName(), EnumSet.of(IteratorScope.minc));
            sleepUninterruptibly(5, TimeUnit.SECONDS);
            // minc should complete
            FunctionalTestUtils.checkRFiles(c, tableName, 1, 1, 1, 1);
            count = Iterators.size(scanner.iterator());
            if (count != 1)
                throw new Exception("Did not see expected # entries " + count);
            // now try putting bad iterator back and deleting the table
            c.tableOperations().attachIterator(tableName, is, EnumSet.of(IteratorScope.minc));
            try (BatchWriter bw = c.createBatchWriter(tableName)) {
                Mutation m = new Mutation(new Text("r2"));
                m.put("acf", tableName, "1");
                bw.addMutation(m);
            }
            // make sure property is given time to propagate
            sleepUninterruptibly(500, TimeUnit.MILLISECONDS);
            c.tableOperations().flush(tableName, null, null, false);
            // make sure the flush has time to start
            sleepUninterruptibly(1, TimeUnit.SECONDS);
            // this should not hang
            c.tableOperations().delete(tableName);
        }
    }
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) Scanner(org.apache.accumulo.core.client.Scanner) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) Text(org.apache.hadoop.io.Text) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) Test(org.junit.Test)

Example 39 with AccumuloClient

use of org.apache.accumulo.core.client.AccumuloClient in project accumulo by apache.

the class BalanceAfterCommsFailureIT method test.

@Test
public void test() throws Exception {
    try (AccumuloClient c = Accumulo.newClient().from(getClientProperties()).build()) {
        c.tableOperations().create("test");
        Collection<ProcessReference> tservers = getCluster().getProcesses().get(ServerType.TABLET_SERVER);
        ArrayList<Integer> tserverPids = new ArrayList<>(tservers.size());
        for (ProcessReference tserver : tservers) {
            Process p = tserver.getProcess();
            if (!p.getClass().getName().equals("java.lang.UNIXProcess")) {
                log.info("Found process that was not UNIXProcess, exiting test");
                return;
            }
            Field f = p.getClass().getDeclaredField("pid");
            f.setAccessible(true);
            tserverPids.add(f.getInt(p));
        }
        for (int pid : tserverPids) {
            assertEquals(0, Runtime.getRuntime().exec(new String[] { "kill", "-SIGSTOP", Integer.toString(pid) }).waitFor());
        }
        UtilWaitThread.sleep(20_000);
        for (int pid : tserverPids) {
            assertEquals(0, Runtime.getRuntime().exec(new String[] { "kill", "-SIGCONT", Integer.toString(pid) }).waitFor());
        }
        SortedSet<Text> splits = new TreeSet<>();
        for (String split : "a b c d e f g h i j k l m n o p q r s t u v w x y z".split(" ")) {
            splits.add(new Text(split));
        }
        c.tableOperations().addSplits("test", splits);
        // Ensure all of the tablets are actually assigned
        assertEquals(0, Iterables.size(c.createScanner("test", Authorizations.EMPTY)));
        UtilWaitThread.sleep(30_000);
        checkBalance(c);
    }
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) ProcessReference(org.apache.accumulo.miniclusterImpl.ProcessReference) ArrayList(java.util.ArrayList) Text(org.apache.hadoop.io.Text) Field(java.lang.reflect.Field) TreeSet(java.util.TreeSet) Test(org.junit.Test)

Example 40 with AccumuloClient

use of org.apache.accumulo.core.client.AccumuloClient in project accumulo by apache.

the class BatchWriterFlushIT method run.

@Test
public void run() throws Exception {
    try (AccumuloClient c = Accumulo.newClient().from(getClientProps()).build()) {
        String[] tableNames = getUniqueNames(2);
        String bwft = tableNames[0];
        c.tableOperations().create(bwft);
        String bwlt = tableNames[1];
        c.tableOperations().create(bwlt);
        runFlushTest(c, bwft);
        runLatencyTest(c, bwlt);
    }
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) Test(org.junit.Test)

Aggregations

AccumuloClient (org.apache.accumulo.core.client.AccumuloClient)500 Test (org.junit.Test)411 BatchWriter (org.apache.accumulo.core.client.BatchWriter)149 Text (org.apache.hadoop.io.Text)143 Mutation (org.apache.accumulo.core.data.Mutation)138 Scanner (org.apache.accumulo.core.client.Scanner)122 Value (org.apache.accumulo.core.data.Value)118 Key (org.apache.accumulo.core.data.Key)108 NewTableConfiguration (org.apache.accumulo.core.client.admin.NewTableConfiguration)91 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)64 HashMap (java.util.HashMap)61 Range (org.apache.accumulo.core.data.Range)51 TreeSet (java.util.TreeSet)50 ArrayList (java.util.ArrayList)47 Entry (java.util.Map.Entry)41 Path (org.apache.hadoop.fs.Path)39 CompactionConfig (org.apache.accumulo.core.client.admin.CompactionConfig)34 Authorizations (org.apache.accumulo.core.security.Authorizations)34 BatchScanner (org.apache.accumulo.core.client.BatchScanner)32 HashSet (java.util.HashSet)31