Search in sources :

Example 81 with BatchWriter

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

the class ZookeeperRestartIT method test.

@Test
public void test() throws Exception {
    Connector c = getConnector();
    c.tableOperations().create("test_ingest");
    BatchWriter bw = c.createBatchWriter("test_ingest", null);
    Mutation m = new Mutation("row");
    m.put("cf", "cq", "value");
    bw.addMutation(m);
    bw.close();
    // kill zookeeper
    for (ProcessReference proc : cluster.getProcesses().get(ServerType.ZOOKEEPER)) cluster.killProcess(ServerType.ZOOKEEPER, proc);
    // give the servers time to react
    sleepUninterruptibly(1, TimeUnit.SECONDS);
    // start zookeeper back up
    cluster.start();
    // use the tservers
    try (Scanner s = c.createScanner("test_ingest", Authorizations.EMPTY)) {
        Iterator<Entry<Key, Value>> i = s.iterator();
        assertTrue(i.hasNext());
        assertEquals("row", i.next().getKey().getRow().toString());
        assertFalse(i.hasNext());
        // use the master
        c.tableOperations().delete("test_ingest");
    }
}
Also used : Connector(org.apache.accumulo.core.client.Connector) Scanner(org.apache.accumulo.core.client.Scanner) ProcessReference(org.apache.accumulo.minicluster.impl.ProcessReference) Entry(java.util.Map.Entry) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) Test(org.junit.Test)

Example 82 with BatchWriter

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

the class CloseWriteAheadLogReferencesIT method partiallyReplicatedReferencedWalsAreNotClosed.

@Test
public void partiallyReplicatedReferencedWalsAreNotClosed() throws Exception {
    String file = "file:/accumulo/wal/tserver+port/12345";
    Set<String> wals = Collections.singleton(file);
    BatchWriter bw = ReplicationTable.getBatchWriter(conn);
    Mutation m = new Mutation(file);
    StatusSection.add(m, Table.ID.of("1"), ProtobufUtil.toValue(StatusUtil.ingestedUntil(1000)));
    bw.addMutation(m);
    bw.close();
    refs.updateReplicationEntries(conn, wals);
    try (Scanner s = ReplicationTable.getScanner(conn)) {
        Entry<Key, Value> entry = Iterables.getOnlyElement(s);
        Status status = Status.parseFrom(entry.getValue().get());
        Assert.assertFalse(status.getClosed());
    }
}
Also used : Status(org.apache.accumulo.server.replication.proto.Replication.Status) Scanner(org.apache.accumulo.core.client.Scanner) Value(org.apache.accumulo.core.data.Value) 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 BatchWriter

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

the class CloseWriteAheadLogReferencesIT method closedWalsUpdateStatus.

@Test
public void closedWalsUpdateStatus() throws Exception {
    String file = "file:/accumulo/wal/tserver+port/12345";
    Set<String> wals = Collections.singleton(file);
    BatchWriter bw = conn.createBatchWriter(MetadataTable.NAME, new BatchWriterConfig());
    Mutation m = new Mutation(ReplicationSection.getRowPrefix() + file);
    m.put(ReplicationSection.COLF, new Text("1"), StatusUtil.fileCreatedValue(System.currentTimeMillis()));
    bw.addMutation(m);
    bw.close();
    refs.updateReplicationEntries(conn, wals);
    try (Scanner s = conn.createScanner(MetadataTable.NAME, Authorizations.EMPTY)) {
        s.fetchColumnFamily(ReplicationSection.COLF);
        Entry<Key, Value> entry = Iterables.getOnlyElement(s);
        Status status = Status.parseFrom(entry.getValue().get());
        Assert.assertTrue(status.getClosed());
    }
}
Also used : Status(org.apache.accumulo.server.replication.proto.Replication.Status) Scanner(org.apache.accumulo.core.client.Scanner) 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) Key(org.apache.accumulo.core.data.Key) Test(org.junit.Test)

Example 84 with BatchWriter

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

the class RowDeleteIT method run.

@Test
public void run() throws Exception {
    Connector c = getConnector();
    String tableName = getUniqueNames(1)[0];
    c.tableOperations().create(tableName);
    Map<String, Set<Text>> groups = new HashMap<>();
    groups.put("lg1", Collections.singleton(new Text("foo")));
    groups.put("dg", Collections.emptySet());
    c.tableOperations().setLocalityGroups(tableName, groups);
    IteratorSetting setting = new IteratorSetting(30, RowDeletingIterator.class);
    c.tableOperations().attachIterator(tableName, setting, EnumSet.of(IteratorScope.majc));
    c.tableOperations().setProperty(tableName, Property.TABLE_MAJC_RATIO.getKey(), "100");
    BatchWriter bw = c.createBatchWriter(tableName, new BatchWriterConfig());
    bw.addMutation(nm("r1", "foo", "cf1", "v1"));
    bw.addMutation(nm("r1", "bar", "cf1", "v2"));
    bw.flush();
    c.tableOperations().flush(tableName, null, null, true);
    checkRFiles(c, tableName, 1, 1, 1, 1);
    int count;
    try (Scanner scanner = c.createScanner(tableName, Authorizations.EMPTY)) {
        count = Iterators.size(scanner.iterator());
        assertEquals("count == " + count, 2, count);
        bw.addMutation(nm("r1", "", "", RowDeletingIterator.DELETE_ROW_VALUE));
        bw.flush();
        c.tableOperations().flush(tableName, null, null, true);
        checkRFiles(c, tableName, 1, 1, 2, 2);
    }
    try (Scanner scanner = c.createScanner(tableName, Authorizations.EMPTY)) {
        count = Iterators.size(scanner.iterator());
        assertEquals("count == " + count, 3, count);
        c.tableOperations().compact(tableName, null, null, false, true);
        checkRFiles(c, tableName, 1, 1, 0, 0);
    }
    try (Scanner scanner = c.createScanner(tableName, Authorizations.EMPTY)) {
        count = Iterators.size(scanner.iterator());
        assertEquals("count == " + count, 0, count);
        bw.close();
    }
}
Also used : Connector(org.apache.accumulo.core.client.Connector) Scanner(org.apache.accumulo.core.client.Scanner) Set(java.util.Set) EnumSet(java.util.EnumSet) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) HashMap(java.util.HashMap) BatchWriterConfig(org.apache.accumulo.core.client.BatchWriterConfig) Text(org.apache.hadoop.io.Text) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Test(org.junit.Test)

Example 85 with BatchWriter

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

the class ScanIteratorIT method writeTestMutation.

private void writeTestMutation(Connector userC) throws TableNotFoundException, MutationsRejectedException {
    BatchWriter batchWriter = userC.createBatchWriter(tableName, new BatchWriterConfig());
    Mutation m = new Mutation("1");
    m.put(new Text("2"), new Text("3"), new Value("".getBytes()));
    batchWriter.addMutation(m);
    batchWriter.flush();
    batchWriter.close();
}
Also used : 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)

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