Search in sources :

Example 91 with BatchWriter

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

the class AccumuloFileOutputFormatIT method setup.

@Before
public void setup() throws Exception {
    PREFIX = testName.getMethodName() + "_";
    BAD_TABLE = PREFIX + "_mapreduce_bad_table";
    TEST_TABLE = PREFIX + "_mapreduce_test_table";
    EMPTY_TABLE = PREFIX + "_mapreduce_empty_table";
    Connector c = getConnector();
    c.tableOperations().create(EMPTY_TABLE);
    c.tableOperations().create(TEST_TABLE);
    c.tableOperations().create(BAD_TABLE);
    BatchWriter bw = c.createBatchWriter(TEST_TABLE, new BatchWriterConfig());
    Mutation m = new Mutation("Key");
    m.put("", "", "");
    bw.addMutation(m);
    bw.close();
    bw = c.createBatchWriter(BAD_TABLE, new BatchWriterConfig());
    m = new Mutation("r1");
    m.put("cf1", "cq1", "A&B");
    m.put("cf1", "cq1", "A&B");
    m.put("cf1", "cq2", "A&");
    bw.addMutation(m);
    bw.close();
}
Also used : Connector(org.apache.accumulo.core.client.Connector) BatchWriterConfig(org.apache.accumulo.core.client.BatchWriterConfig) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) Before(org.junit.Before)

Example 92 with BatchWriter

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

the class AccumuloInputFormatIT method testMapWithBatchScanner.

@Test
public void testMapWithBatchScanner() throws Exception {
    final String TEST_TABLE_2 = getUniqueNames(1)[0];
    Connector c = getConnector();
    c.tableOperations().create(TEST_TABLE_2);
    BatchWriter bw = c.createBatchWriter(TEST_TABLE_2, new BatchWriterConfig());
    for (int i = 0; i < 100; i++) {
        Mutation m = new Mutation(new Text(String.format("%09x", i + 1)));
        m.put(new Text(), new Text(), new Value(String.format("%09x", i).getBytes()));
        bw.addMutation(m);
    }
    bw.close();
    Assert.assertEquals(0, MRTester.main(new String[] { TEST_TABLE_2, AccumuloInputFormat.class.getName(), "True", "False" }));
    assertEquals(1, assertionErrors.get(TEST_TABLE_2 + "_map").size());
    assertEquals(1, assertionErrors.get(TEST_TABLE_2 + "_cleanup").size());
}
Also used : Connector(org.apache.accumulo.core.client.Connector) Value(org.apache.accumulo.core.data.Value) 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) Test(org.junit.Test)

Example 93 with BatchWriter

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

the class AccumuloRowInputFormatIT method test.

@Test
public void test() throws Exception {
    final Connector conn = getConnector();
    String tableName = getUniqueNames(1)[0];
    conn.tableOperations().create(tableName);
    BatchWriter writer = null;
    try {
        writer = conn.createBatchWriter(tableName, new BatchWriterConfig());
        insertList(writer, row1);
        insertList(writer, row2);
        insertList(writer, row3);
    } finally {
        if (writer != null) {
            writer.close();
        }
    }
    MRTester.main(new String[] { tableName });
    assertNull(e1);
    assertNull(e2);
}
Also used : Connector(org.apache.accumulo.core.client.Connector) BatchWriterConfig(org.apache.accumulo.core.client.BatchWriterConfig) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Test(org.junit.Test)

Example 94 with BatchWriter

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

the class SessionBlockVerifyIT method run.

@Test
public void run() throws Exception {
    Connector c = getConnector();
    String tableName = getUniqueNames(1)[0];
    c.tableOperations().create(tableName);
    BatchWriter bw = c.createBatchWriter(tableName, new BatchWriterConfig());
    for (int i = 0; i < 1000; i++) {
        Mutation m = new Mutation(new Text(String.format("%08d", i)));
        for (int j = 0; j < 3; j++) m.put(new Text("cf1"), new Text("cq" + j), new Value((i + "_" + j).getBytes(UTF_8)));
        bw.addMutation(m);
    }
    bw.close();
    try (Scanner scanner = c.createScanner(tableName, new Authorizations())) {
        scanner.setReadaheadThreshold(20000);
        scanner.setRange(new Range(String.format("%08d", 0), String.format("%08d", 1000)));
        // test by making a slow iterator and then a couple of fast ones.
        // when then checking we shouldn't have any running except the slow iterator
        IteratorSetting setting = new IteratorSetting(21, SlowIterator.class);
        SlowIterator.setSeekSleepTime(setting, Long.MAX_VALUE);
        SlowIterator.setSleepTime(setting, Long.MAX_VALUE);
        scanner.addScanIterator(setting);
        final Iterator<Entry<Key, Value>> slow = scanner.iterator();
        final List<Future<Boolean>> callables = new ArrayList<>();
        final CountDownLatch latch = new CountDownLatch(10);
        for (int i = 0; i < 10; i++) {
            Future<Boolean> callable = service.submit(new Callable<Boolean>() {

                public Boolean call() {
                    latch.countDown();
                    while (slow.hasNext()) {
                        slow.next();
                    }
                    return slow.hasNext();
                }
            });
            callables.add(callable);
        }
        latch.await();
        log.info("Starting SessionBlockVerifyIT");
        // let's add more for good measure.
        for (int i = 0; i < 2; i++) {
            try (Scanner scanner2 = c.createScanner(tableName, new Authorizations())) {
                scanner2.setRange(new Range(String.format("%08d", 0), String.format("%08d", 1000)));
                scanner2.setBatchSize(1);
                Iterator<Entry<Key, Value>> iter = scanner2.iterator();
                // call super's verify mechanism
                verify(iter, 0, 1000);
            }
        }
        int sessionsFound = 0;
        // we have configured 1 tserver, so we can grab the one and only
        String tserver = Iterables.getOnlyElement(c.instanceOperations().getTabletServers());
        final List<ActiveScan> scans = c.instanceOperations().getActiveScans(tserver);
        for (ActiveScan scan : scans) {
            if (tableName.equals(scan.getTable()) && scan.getSsiList().size() > 0) {
                assertEquals("Not the expected iterator", 1, scan.getSsiList().size());
                assertTrue("Not the expected iterator", scan.getSsiList().iterator().next().contains("SlowIterator"));
                sessionsFound++;
            }
        }
        /**
         * The message below indicates the problem that we experience within ACCUMULO-3509. The issue manifests as a blockage in the Scanner synchronization that
         * prevent us from making the close call against it. Since the close blocks until a read is finished, we ultimately have a block within the sweep of
         * SessionManager. As a result never reap subsequent idle sessions AND we will orphan the sessionsToCleanup in the sweep, leading to an inaccurate count
         * within sessionsFound.
         */
        assertEquals("Must have ten sessions. Failure indicates a synchronization block within the sweep mechanism", 10, sessionsFound);
        for (Future<Boolean> callable : callables) {
            callable.cancel(true);
        }
    }
    service.shutdown();
}
Also used : Connector(org.apache.accumulo.core.client.Connector) Scanner(org.apache.accumulo.core.client.Scanner) Authorizations(org.apache.accumulo.core.security.Authorizations) ActiveScan(org.apache.accumulo.core.client.admin.ActiveScan) ArrayList(java.util.ArrayList) Text(org.apache.hadoop.io.Text) Range(org.apache.accumulo.core.data.Range) CountDownLatch(java.util.concurrent.CountDownLatch) Entry(java.util.Map.Entry) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) Value(org.apache.accumulo.core.data.Value) BatchWriterConfig(org.apache.accumulo.core.client.BatchWriterConfig) Future(java.util.concurrent.Future) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) Test(org.junit.Test)

Example 95 with BatchWriter

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

the class SessionDurabilityIT method writeSome.

private void writeSome(String tableName, int n, BatchWriterConfig cfg) throws Exception {
    Connector c = getConnector();
    BatchWriter bw = c.createBatchWriter(tableName, cfg);
    for (int i = 0; i < n; i++) {
        Mutation m = new Mutation(i + "");
        m.put("", "", "");
        bw.addMutation(m);
    }
    bw.close();
}
Also used : Connector(org.apache.accumulo.core.client.Connector) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) ConditionalMutation(org.apache.accumulo.core.data.ConditionalMutation)

Aggregations

BatchWriter (org.apache.accumulo.core.client.BatchWriter)402 Mutation (org.apache.accumulo.core.data.Mutation)360 Test (org.junit.Test)264 Value (org.apache.accumulo.core.data.Value)250 BatchWriterConfig (org.apache.accumulo.core.client.BatchWriterConfig)246 Text (org.apache.hadoop.io.Text)194 Key (org.apache.accumulo.core.data.Key)179 Scanner (org.apache.accumulo.core.client.Scanner)174 Connector (org.apache.accumulo.core.client.Connector)169 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)81 Authorizations (org.apache.accumulo.core.security.Authorizations)68 Range (org.apache.accumulo.core.data.Range)61 Entry (java.util.Map.Entry)51 Map (java.util.Map)50 BatchScanner (org.apache.accumulo.core.client.BatchScanner)46 MutationsRejectedException (org.apache.accumulo.core.client.MutationsRejectedException)44 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)40 HashMap (java.util.HashMap)38 ArrayList (java.util.ArrayList)36 Status (org.apache.accumulo.server.replication.proto.Replication.Status)32