Search in sources :

Example 21 with Condition

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

the class ConditionalWriterIT method testBatchErrors.

@Test
public void testBatchErrors() throws Exception {
    Connector conn = getConnector();
    String tableName = getUniqueNames(1)[0];
    conn.tableOperations().create(tableName);
    conn.tableOperations().addConstraint(tableName, AlphaNumKeyConstraint.class.getName());
    conn.tableOperations().clone(tableName, tableName + "_clone", true, new HashMap<>(), new HashSet<>());
    conn.securityOperations().changeUserAuthorizations(getAdminPrincipal(), new Authorizations("A", "B"));
    ColumnVisibility cvaob = new ColumnVisibility("A|B");
    ColumnVisibility cvaab = new ColumnVisibility("A&B");
    switch((new Random()).nextInt(3)) {
        case 1:
            conn.tableOperations().addSplits(tableName, nss("6"));
            break;
        case 2:
            conn.tableOperations().addSplits(tableName, nss("2", "95"));
            break;
    }
    ArrayList<ConditionalMutation> mutations = new ArrayList<>();
    ConditionalMutation cm0 = new ConditionalMutation("99006", new Condition("tx", "seq").setVisibility(cvaob));
    cm0.put("name+", "last", cvaob, "doe");
    cm0.put("name", "first", cvaob, "john");
    cm0.put("tx", "seq", cvaob, "1");
    mutations.add(cm0);
    ConditionalMutation cm1 = new ConditionalMutation("59056", new Condition("tx", "seq").setVisibility(cvaab));
    cm1.put("name", "last", cvaab, "doe");
    cm1.put("name", "first", cvaab, "jane");
    cm1.put("tx", "seq", cvaab, "1");
    mutations.add(cm1);
    ConditionalMutation cm2 = new ConditionalMutation("19059", new Condition("tx", "seq").setVisibility(cvaob));
    cm2.put("name", "last", cvaob, "doe");
    cm2.put("name", "first", cvaob, "jack");
    cm2.put("tx", "seq", cvaob, "1");
    mutations.add(cm2);
    ConditionalMutation cm3 = new ConditionalMutation("90909", new Condition("tx", "seq").setVisibility(cvaob).setValue("1"));
    cm3.put("name", "last", cvaob, "doe");
    cm3.put("name", "first", cvaob, "john");
    cm3.put("tx", "seq", cvaob, "2");
    mutations.add(cm3);
    try (ConditionalWriter cw = conn.createConditionalWriter(tableName, new ConditionalWriterConfig().setAuthorizations(new Authorizations("A")));
        Scanner scanner = conn.createScanner(tableName, new Authorizations("A"))) {
        Iterator<Result> results = cw.write(mutations.iterator());
        HashSet<String> rows = new HashSet<>();
        while (results.hasNext()) {
            Result result = results.next();
            String row = new String(result.getMutation().getRow());
            if (row.equals("19059")) {
                Assert.assertEquals(Status.ACCEPTED, result.getStatus());
            } else if (row.equals("59056")) {
                Assert.assertEquals(Status.INVISIBLE_VISIBILITY, result.getStatus());
            } else if (row.equals("99006")) {
                Assert.assertEquals(Status.VIOLATED, result.getStatus());
            } else if (row.equals("90909")) {
                Assert.assertEquals(Status.REJECTED, result.getStatus());
            }
            rows.add(row);
        }
        Assert.assertEquals(4, rows.size());
        scanner.fetchColumn(new Text("tx"), new Text("seq"));
        Entry<Key, Value> entry = Iterables.getOnlyElement(scanner);
        Assert.assertEquals("1", entry.getValue().toString());
    }
}
Also used : Condition(org.apache.accumulo.core.data.Condition) Connector(org.apache.accumulo.core.client.Connector) IsolatedScanner(org.apache.accumulo.core.client.IsolatedScanner) Scanner(org.apache.accumulo.core.client.Scanner) Authorizations(org.apache.accumulo.core.security.Authorizations) ArrayList(java.util.ArrayList) Text(org.apache.hadoop.io.Text) AlphaNumKeyConstraint(org.apache.accumulo.test.constraints.AlphaNumKeyConstraint) Result(org.apache.accumulo.core.client.ConditionalWriter.Result) ConditionalWriter(org.apache.accumulo.core.client.ConditionalWriter) ConditionalMutation(org.apache.accumulo.core.data.ConditionalMutation) Random(java.util.Random) Value(org.apache.accumulo.core.data.Value) ConditionalWriterConfig(org.apache.accumulo.core.client.ConditionalWriterConfig) ColumnVisibility(org.apache.accumulo.core.security.ColumnVisibility) Key(org.apache.accumulo.core.data.Key) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 22 with Condition

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

the class SessionDurabilityIT method conditionWriteSome.

private void conditionWriteSome(String tableName, int n, ConditionalWriterConfig cfg) throws Exception {
    Connector c = getConnector();
    ConditionalWriter cw = c.createConditionalWriter(tableName, cfg);
    for (int i = 0; i < n; i++) {
        ConditionalMutation m = new ConditionalMutation(i + "", new Condition("", ""));
        m.put("", "", "X");
        assertEquals(Status.ACCEPTED, cw.write(m).getStatus());
    }
}
Also used : Condition(org.apache.accumulo.core.data.Condition) Connector(org.apache.accumulo.core.client.Connector) ConditionalWriter(org.apache.accumulo.core.client.ConditionalWriter) ConditionalMutation(org.apache.accumulo.core.data.ConditionalMutation)

Example 23 with Condition

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

the class ConditionalWriterImpl method convertConditions.

private List<TCondition> convertConditions(ConditionalMutation cm, CompressedIterators compressedIters) {
    List<TCondition> conditions = new ArrayList<>(cm.getConditions().size());
    // sort conditions inorder to get better lookup performance. Sort on client side so tserver does not have to do it.
    Condition[] ca = cm.getConditions().toArray(new Condition[cm.getConditions().size()]);
    Arrays.sort(ca, CONDITION_COMPARATOR);
    for (Condition cond : ca) {
        long ts = 0;
        boolean hasTs = false;
        if (cond.getTimestamp() != null) {
            ts = cond.getTimestamp();
            hasTs = true;
        }
        ByteBuffer iters = compressedIters.compress(cond.getIterators());
        TCondition tc = new TCondition(ByteBufferUtil.toByteBuffers(cond.getFamily()), ByteBufferUtil.toByteBuffers(cond.getQualifier()), ByteBufferUtil.toByteBuffers(cond.getVisibility()), ts, hasTs, ByteBufferUtil.toByteBuffers(cond.getValue()), iters);
        conditions.add(tc);
    }
    return conditions;
}
Also used : TCondition(org.apache.accumulo.core.data.thrift.TCondition) Condition(org.apache.accumulo.core.data.Condition) TCondition(org.apache.accumulo.core.data.thrift.TCondition) ArrayList(java.util.ArrayList) ByteBuffer(java.nio.ByteBuffer)

Aggregations

Condition (org.apache.accumulo.core.data.Condition)23 ConditionalMutation (org.apache.accumulo.core.data.ConditionalMutation)21 ConditionalWriter (org.apache.accumulo.core.client.ConditionalWriter)20 ConditionalWriterConfig (org.apache.accumulo.core.client.ConditionalWriterConfig)19 Connector (org.apache.accumulo.core.client.Connector)17 Test (org.junit.Test)17 IsolatedScanner (org.apache.accumulo.core.client.IsolatedScanner)11 Scanner (org.apache.accumulo.core.client.Scanner)11 Value (org.apache.accumulo.core.data.Value)11 Result (org.apache.accumulo.core.client.ConditionalWriter.Result)10 Status (org.apache.accumulo.core.client.ConditionalWriter.Status)10 Key (org.apache.accumulo.core.data.Key)9 Range (org.apache.accumulo.core.data.Range)8 Authorizations (org.apache.accumulo.core.security.Authorizations)7 Text (org.apache.hadoop.io.Text)7 AccumuloException (org.apache.accumulo.core.client.AccumuloException)5 ColumnVisibility (org.apache.accumulo.core.security.ColumnVisibility)5 AlphaNumKeyConstraint (org.apache.accumulo.test.constraints.AlphaNumKeyConstraint)5 ArrayList (java.util.ArrayList)4 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)4