Search in sources :

Example 81 with BatchWriterConfig

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

the class DeleteManyCommand method execute.

@Override
public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws Exception {
    final String tableName = OptUtil.getTableOpt(cl, shellState);
    final ScanInterpreter interpeter = getInterpreter(cl, tableName, shellState);
    // handle first argument, if present, the authorizations list to
    // scan with
    final Authorizations auths = getAuths(cl, shellState);
    final Scanner scanner = shellState.getAccumuloClient().createScanner(tableName, auths);
    scanner.addScanIterator(new IteratorSetting(Integer.MAX_VALUE, "NOVALUE", SortedKeyIterator.class));
    // handle session-specific scan iterators
    addScanIterators(shellState, cl, scanner, tableName);
    // handle remaining optional arguments
    scanner.setRange(getRange(cl, interpeter));
    scanner.setTimeout(getTimeout(cl), TimeUnit.MILLISECONDS);
    // handle columns
    fetchColumns(cl, scanner, interpeter);
    // output / delete the records
    final BatchWriter writer = shellState.getAccumuloClient().createBatchWriter(tableName, new BatchWriterConfig().setTimeout(getTimeout(cl), TimeUnit.MILLISECONDS));
    FormatterConfig config = new FormatterConfig();
    config.setPrintTimestamps(cl.hasOption(timestampOpt.getOpt()));
    shellState.printLines(new DeleterFormatter(writer, scanner, config, shellState, cl.hasOption(forceOpt.getOpt())), false);
    return 0;
}
Also used : ScanInterpreter(org.apache.accumulo.core.util.interpret.ScanInterpreter) Scanner(org.apache.accumulo.core.client.Scanner) Authorizations(org.apache.accumulo.core.security.Authorizations) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) FormatterConfig(org.apache.accumulo.core.util.format.FormatterConfig) SortedKeyIterator(org.apache.accumulo.core.iterators.SortedKeyIterator) BatchWriterConfig(org.apache.accumulo.core.client.BatchWriterConfig) BatchWriter(org.apache.accumulo.core.client.BatchWriter) DeleterFormatter(org.apache.accumulo.shell.format.DeleterFormatter)

Example 82 with BatchWriterConfig

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

the class CleanUpIT method run.

@SuppressWarnings("deprecation")
@Test
public void run() throws Exception {
    // CleanUp for Connectors will not work if there are active AccumuloClients
    assertEquals(0, SingletonManager.getReservationCount());
    // CleanUp was created to clean up after connectors. This test intentionally creates a connector
    // instead of an AccumuloClient
    org.apache.accumulo.core.client.Connector conn = new org.apache.accumulo.core.client.ZooKeeperInstance(getCluster().getInstanceName(), getCluster().getZooKeepers()).getConnector(getPrincipal(), getToken());
    String tableName = getUniqueNames(1)[0];
    conn.tableOperations().create(tableName);
    BatchWriter bw = conn.createBatchWriter(tableName, new BatchWriterConfig());
    Mutation m1 = new Mutation("r1");
    m1.put("cf1", "cq1", 1, "5");
    bw.addMutation(m1);
    bw.flush();
    try (Scanner scanner = conn.createScanner(tableName, new Authorizations())) {
        int count = 0;
        for (Entry<Key, Value> entry : scanner) {
            count++;
            if (!entry.getValue().toString().equals("5")) {
                fail("Unexpected value " + entry.getValue());
            }
        }
        assertEquals("Unexpected count", 1, count);
        int threadCount = countThreads();
        if (threadCount < 2) {
            printThreadNames();
            fail("Not seeing expected threads. Saw " + threadCount);
        }
        org.apache.accumulo.core.util.CleanUp.shutdownNow(conn);
        Mutation m2 = new Mutation("r2");
        m2.put("cf1", "cq1", 1, "6");
        bw.addMutation(m1);
        assertThrows(MutationsRejectedException.class, bw::flush);
        // expect this to fail also, want to clean up batch writer threads
        assertThrows(MutationsRejectedException.class, bw::close);
        assertThrows(IllegalStateException.class, () -> Iterables.size(scanner));
        threadCount = countThreads();
        if (threadCount > 0) {
            printThreadNames();
            fail("Threads did not go away. Saw " + threadCount);
        }
    }
}
Also used : Scanner(org.apache.accumulo.core.client.Scanner) Authorizations(org.apache.accumulo.core.security.Authorizations) Value(org.apache.accumulo.core.data.Value) BatchWriterConfig(org.apache.accumulo.core.client.BatchWriterConfig) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) Key(org.apache.accumulo.core.data.Key) Test(org.junit.Test)

Example 83 with BatchWriterConfig

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

the class UnusedWALIT method writeSomeData.

private void writeSomeData(AccumuloClient client, String table, int startRow, int rowCount, int startCol, int colCount) throws Exception {
    BatchWriterConfig config = new BatchWriterConfig();
    config.setMaxMemory(10 * 1024 * 1024);
    BatchWriter bw = client.createBatchWriter(table, config);
    for (int r = startRow; r < startRow + rowCount; r++) {
        Mutation m = new Mutation(Integer.toHexString(r));
        for (int c = startCol; c < startCol + colCount; c++) {
            m.put("", Integer.toHexString(c), "");
        }
        bw.addMutation(m);
    }
    bw.close();
}
Also used : BatchWriterConfig(org.apache.accumulo.core.client.BatchWriterConfig) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation)

Example 84 with BatchWriterConfig

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

the class BatchWriterFlushIT method runLatencyTest.

private void runLatencyTest(AccumuloClient client, String tableName) throws Exception {
    // should automatically flush after 2 seconds
    try (BatchWriter bw = client.createBatchWriter(tableName, new BatchWriterConfig().setMaxLatency(1000, TimeUnit.MILLISECONDS));
        Scanner scanner = client.createScanner(tableName, Authorizations.EMPTY)) {
        Mutation m = new Mutation(new Text(String.format("r_%10d", 1)));
        m.put("cf", "cq", "1");
        bw.addMutation(m);
        sleepUninterruptibly(500, TimeUnit.MILLISECONDS);
        int count = Iterators.size(scanner.iterator());
        if (count != 0) {
            throw new Exception("Flushed too soon");
        }
        sleepUninterruptibly(1500, TimeUnit.MILLISECONDS);
        count = Iterators.size(scanner.iterator());
        if (count != 1) {
            throw new Exception("Did not flush");
        }
    }
}
Also used : Scanner(org.apache.accumulo.core.client.Scanner) BatchWriterConfig(org.apache.accumulo.core.client.BatchWriterConfig) Text(org.apache.hadoop.io.Text) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) MutationsRejectedException(org.apache.accumulo.core.client.MutationsRejectedException)

Example 85 with BatchWriterConfig

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

the class MetricsIT method doWorkToGenerateMetrics.

private void doWorkToGenerateMetrics() throws Exception {
    try (AccumuloClient client = Accumulo.newClient().from(getClientProperties()).build()) {
        String tableName = this.getClass().getSimpleName();
        client.tableOperations().create(tableName);
        BatchWriterConfig config = new BatchWriterConfig().setMaxMemory(0);
        try (BatchWriter writer = client.createBatchWriter(tableName, config)) {
            Mutation m = new Mutation("row");
            m.put("cf", "cq", new Value("value"));
            writer.addMutation(m);
        }
        client.tableOperations().flush(tableName);
        try (BatchWriter writer = client.createBatchWriter(tableName, config)) {
            Mutation m = new Mutation("row");
            m.put("cf", "cq", new Value("value"));
            writer.addMutation(m);
        }
        client.tableOperations().compact(tableName, new CompactionConfig());
        client.tableOperations().delete(tableName);
        while (client.tableOperations().exists(tableName)) {
            Thread.sleep(1000);
        }
    }
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) Value(org.apache.accumulo.core.data.Value) 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)

Aggregations

BatchWriterConfig (org.apache.accumulo.core.client.BatchWriterConfig)182 BatchWriter (org.apache.accumulo.core.client.BatchWriter)135 Mutation (org.apache.accumulo.core.data.Mutation)131 Value (org.apache.accumulo.core.data.Value)88 Text (org.apache.hadoop.io.Text)60 Key (org.apache.accumulo.core.data.Key)59 Test (org.junit.Test)58 Scanner (org.apache.accumulo.core.client.Scanner)57 Connector (org.apache.accumulo.core.client.Connector)38 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)33 MutationsRejectedException (org.apache.accumulo.core.client.MutationsRejectedException)28 AccumuloException (org.apache.accumulo.core.client.AccumuloException)26 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)24 Authorizations (org.apache.accumulo.core.security.Authorizations)22 Range (org.apache.accumulo.core.data.Range)20 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)19 PasswordToken (org.apache.accumulo.core.client.security.tokens.PasswordToken)19 ColumnVisibility (org.apache.accumulo.core.security.ColumnVisibility)19 Entry (java.util.Map.Entry)18 IOException (java.io.IOException)14