Search in sources :

Example 66 with Mutation

use of org.apache.accumulo.core.data.Mutation in project accumulo by apache.

the class PluginIT method checkIterator.

@Test
public void checkIterator() throws IOException, AccumuloException, AccumuloSecurityException, TableExistsException, TableNotFoundException {
    String tableName = "checkIterator";
    connector.tableOperations().create(tableName);
    BatchWriter bw = connector.createBatchWriter(tableName, new BatchWriterConfig());
    Mutation m = new Mutation("ROW1");
    m.put("allowed", "CQ1", "V1");
    m.put("denied", "CQ2", "V2");
    m.put("allowed", "CQ3", "V3");
    bw.addMutation(m);
    m = new Mutation("ROW2");
    m.put("allowed", "CQ1", "V1");
    m.put("denied", "CQ2", "V2");
    m.put("allowed", "CQ3", "V3");
    bw.addMutation(m);
    bw.close();
    // check filter
    Scanner scanner = connector.createScanner(tableName, Authorizations.EMPTY);
    IteratorSetting is = new IteratorSetting(5, CustomFilter.class);
    scanner.addScanIterator(is);
    int count = 0;
    for (Entry<Key, Value> entry : scanner) {
        count++;
        assertEquals("allowed", entry.getKey().getColumnFamily().toString());
    }
    assertEquals(4, count);
    // check filter negated
    scanner.clearScanIterators();
    CustomFilter.setNegate(is, true);
    scanner.addScanIterator(is);
    count = 0;
    for (Entry<Key, Value> entry : scanner) {
        count++;
        assertEquals("denied", entry.getKey().getColumnFamily().toString());
    }
    assertEquals(2, count);
    assertTrue(new File("target/accumulo-maven-plugin/" + instance.getInstanceName() + "/testCheckIteratorPassed").createNewFile());
}
Also used : Scanner(org.apache.accumulo.core.client.Scanner) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) 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) File(java.io.File) Key(org.apache.accumulo.core.data.Key) Test(org.junit.Test)

Example 67 with Mutation

use of org.apache.accumulo.core.data.Mutation in project accumulo by apache.

the class DeleterFormatter method next.

/**
 * @return null, because the iteration will provide prompts and handle deletes internally.
 */
@Override
public String next() {
    Entry<Key, Value> next = getScannerIterator().next();
    Key key = next.getKey();
    Mutation m = new Mutation(key.getRow());
    String entryStr = formatEntry(next, isDoTimestamps());
    boolean delete = force;
    try {
        if (!force) {
            shellState.getReader().flush();
            String line = shellState.getReader().readLine("Delete { " + entryStr + " } ? ");
            more = line != null;
            delete = line != null && (line.equalsIgnoreCase("y") || line.equalsIgnoreCase("yes"));
        }
        if (delete) {
            m.putDelete(key.getColumnFamily(), key.getColumnQualifier(), new ColumnVisibility(key.getColumnVisibility()), key.getTimestamp());
            try {
                writer.addMutation(m);
            } catch (MutationsRejectedException e) {
                log.error(e.toString());
                if (Shell.isDebuggingEnabled())
                    for (ConstraintViolationSummary cvs : e.getConstraintViolationSummaries()) log.trace(cvs.toString());
            }
        }
        shellState.getReader().print(String.format("[%s] %s%n", delete ? "DELETED" : "SKIPPED", entryStr));
    } catch (IOException e) {
        log.error("Cannot write to console", e);
        throw new RuntimeException(e);
    }
    return null;
}
Also used : Value(org.apache.accumulo.core.data.Value) ConstraintViolationSummary(org.apache.accumulo.core.data.ConstraintViolationSummary) Mutation(org.apache.accumulo.core.data.Mutation) ColumnVisibility(org.apache.accumulo.core.security.ColumnVisibility) IOException(java.io.IOException) Key(org.apache.accumulo.core.data.Key) MutationsRejectedException(org.apache.accumulo.core.client.MutationsRejectedException)

Example 68 with Mutation

use of org.apache.accumulo.core.data.Mutation in project accumulo by apache.

the class SimpleGarbageCollector method putMarkerDeleteMutation.

private static void putMarkerDeleteMutation(final String delete, final BatchWriter writer) throws MutationsRejectedException {
    Mutation m = new Mutation(MetadataSchema.DeletesSection.getRowPrefix() + delete);
    m.putDelete(EMPTY_TEXT, EMPTY_TEXT);
    writer.addMutation(m);
}
Also used : Mutation(org.apache.accumulo.core.data.Mutation)

Example 69 with Mutation

use of org.apache.accumulo.core.data.Mutation in project accumulo by apache.

the class CloseWriteAheadLogReferences method closeWal.

/**
 * Write a closed {@link Status} mutation for the given {@link Key} using the provided {@link BatchWriter}
 *
 * @param bw
 *          BatchWriter
 * @param k
 *          Key to create close mutation from
 */
protected void closeWal(BatchWriter bw, Key k) throws MutationsRejectedException {
    log.debug("Closing unreferenced WAL ({}) in metadata table", k.toStringNoTruncate());
    Mutation m = new Mutation(k.getRow());
    m.put(k.getColumnFamily(), k.getColumnQualifier(), StatusUtil.fileClosedValue());
    bw.addMutation(m);
}
Also used : Mutation(org.apache.accumulo.core.data.Mutation)

Example 70 with Mutation

use of org.apache.accumulo.core.data.Mutation in project accumulo by apache.

the class LogicalTimeTest method testSetUpdateTimes.

@Test
public void testSetUpdateTimes() {
    List<Mutation> ms = new java.util.ArrayList<>();
    ServerMutation m = createMock(ServerMutation.class);
    ServerMutation m2 = createMock(ServerMutation.class);
    m.setSystemTimestamp(1235L);
    replay(m);
    m2.setSystemTimestamp(1236L);
    replay(m2);
    ms.add(m);
    ms.add(m2);
    long currTime = ltime.setUpdateTimes(ms);
    assertEquals(TIME + 2L, currTime);
    verify(m);
    verify(m2);
}
Also used : ServerMutation(org.apache.accumulo.server.data.ServerMutation) ServerMutation(org.apache.accumulo.server.data.ServerMutation) Mutation(org.apache.accumulo.core.data.Mutation) Test(org.junit.Test)

Aggregations

Mutation (org.apache.accumulo.core.data.Mutation)601 BatchWriter (org.apache.accumulo.core.client.BatchWriter)358 Value (org.apache.accumulo.core.data.Value)341 Test (org.junit.Test)311 Text (org.apache.hadoop.io.Text)303 BatchWriterConfig (org.apache.accumulo.core.client.BatchWriterConfig)223 Key (org.apache.accumulo.core.data.Key)197 Scanner (org.apache.accumulo.core.client.Scanner)161 Connector (org.apache.accumulo.core.client.Connector)150 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)77 Authorizations (org.apache.accumulo.core.security.Authorizations)70 Range (org.apache.accumulo.core.data.Range)61 ArrayList (java.util.ArrayList)60 ColumnVisibility (org.apache.accumulo.core.security.ColumnVisibility)59 Entry (java.util.Map.Entry)57 MutationsRejectedException (org.apache.accumulo.core.client.MutationsRejectedException)55 Map (java.util.Map)53 HashMap (java.util.HashMap)44 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)43 BatchScanner (org.apache.accumulo.core.client.BatchScanner)41