Search in sources :

Example 76 with MutationsRejectedException

use of org.apache.accumulo.core.client.MutationsRejectedException in project presto by prestodb.

the class AccumuloPageSink method finish.

@Override
public CompletableFuture<Collection<Slice>> finish() {
    try {
        // Done serializing rows, so flush and close the writer and indexer
        writer.flush();
        writer.close();
        if (indexer.isPresent()) {
            indexer.get().close();
        }
    } catch (MutationsRejectedException e) {
        throw new PrestoException(UNEXPECTED_ACCUMULO_ERROR, "Mutation rejected by server on flush", e);
    }
    // TODO Look into any use of the metadata for writing out the rows
    return completedFuture(ImmutableList.of());
}
Also used : PrestoException(com.facebook.presto.spi.PrestoException) MutationsRejectedException(org.apache.accumulo.core.client.MutationsRejectedException)

Example 77 with MutationsRejectedException

use of org.apache.accumulo.core.client.MutationsRejectedException in project gora by apache.

the class AccumuloStore method put.

@Override
public void put(K key, T val) throws GoraException {
    try {
        Mutation m = new Mutation(new Text(toBytes(key)));
        Schema schema = val.getSchema();
        List<Field> fields = schema.getFields();
        int count = 0;
        for (int i = 0; i < fields.size(); i++) {
            if (!val.isDirty(i)) {
                continue;
            }
            Field field = fields.get(i);
            Object o = val.get(field.pos());
            Pair<Text, Text> col = mapping.fieldMap.get(field.name());
            if (col == null) {
                throw new GoraException("Please define the gora to accumulo mapping for field " + field.name());
            }
            switch(field.schema().getType()) {
                case MAP:
                    count = putMap(m, count, field.schema().getValueType(), o, col, field.name());
                    break;
                case ARRAY:
                    count = putArray(m, count, o, col, field.name());
                    break;
                case // default value of null acts like union with null
                UNION:
                    Schema effectiveSchema = field.schema().getTypes().get(firstNotNullSchemaTypeIndex(field.schema()));
                    // map and array need to compute qualifier
                    if (effectiveSchema.getType() == Type.ARRAY) {
                        count = putArray(m, count, o, col, field.name());
                        break;
                    } else if (effectiveSchema.getType() == Type.MAP) {
                        count = putMap(m, count, effectiveSchema.getValueType(), o, col, field.name());
                        break;
                    }
                // continue like a regular top-level union
                case RECORD:
                    final SpecificDatumWriter<Object> writer = new SpecificDatumWriter<>(field.schema());
                    final byte[] byteData = IOUtils.serialize(writer, o);
                    m.put(col.getFirst(), col.getSecond(), new Value(byteData));
                    count++;
                    break;
                default:
                    m.put(col.getFirst(), col.getSecond(), new Value(toBytes(o)));
                    count++;
            }
        }
        if (count > 0)
            try {
                getBatchWriter().addMutation(m);
            } catch (MutationsRejectedException e) {
                LOG.error(e.getMessage(), e);
            }
    } catch (GoraException e) {
        throw e;
    } catch (Exception e) {
        throw new GoraException(e);
    }
}
Also used : Schema(org.apache.avro.Schema) Text(org.apache.hadoop.io.Text) TableOfflineException(org.apache.accumulo.core.client.TableOfflineException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) GoraException(org.apache.gora.util.GoraException) MutationsRejectedException(org.apache.accumulo.core.client.MutationsRejectedException) InvocationTargetException(java.lang.reflect.InvocationTargetException) TableExistsException(org.apache.accumulo.core.client.TableExistsException) TableDeletedException(org.apache.accumulo.core.client.TableDeletedException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) IOException(java.io.IOException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) SpecificDatumWriter(org.apache.avro.specific.SpecificDatumWriter) Field(org.apache.avro.Schema.Field) GoraException(org.apache.gora.util.GoraException) Value(org.apache.accumulo.core.data.Value) Mutation(org.apache.accumulo.core.data.Mutation) MutationsRejectedException(org.apache.accumulo.core.client.MutationsRejectedException)

Example 78 with MutationsRejectedException

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

the class InsertCommand method execute.

@Override
public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws AccumuloException, AccumuloSecurityException, TableNotFoundException, IOException, ConstraintViolationException {
    final String tableName = OptUtil.getTableOpt(cl, shellState);
    final Mutation m = new Mutation(new Text(cl.getArgs()[0].getBytes(Shell.CHARSET)));
    final Text colf = new Text(cl.getArgs()[1].getBytes(Shell.CHARSET));
    final Text colq = new Text(cl.getArgs()[2].getBytes(Shell.CHARSET));
    final Value val = new Value(cl.getArgs()[3].getBytes(Shell.CHARSET));
    if (cl.hasOption(insertOptAuths.getOpt())) {
        final ColumnVisibility le = new ColumnVisibility(cl.getOptionValue(insertOptAuths.getOpt()));
        Shell.log.debug("Authorization label will be set to: {}", le);
        if (cl.hasOption(timestampOpt.getOpt()))
            m.put(colf, colq, le, Long.parseLong(cl.getOptionValue(timestampOpt.getOpt())), val);
        else
            m.put(colf, colq, le, val);
    } else if (cl.hasOption(timestampOpt.getOpt()))
        m.put(colf, colq, Long.parseLong(cl.getOptionValue(timestampOpt.getOpt())), val);
    else
        m.put(colf, colq, val);
    final BatchWriterConfig cfg = new BatchWriterConfig().setMaxMemory(Math.max(m.estimatedMemoryUsed(), 1024)).setMaxWriteThreads(1).setTimeout(getTimeout(cl), TimeUnit.MILLISECONDS);
    if (cl.hasOption(durabilityOption.getOpt())) {
        String userDurability = cl.getOptionValue(durabilityOption.getOpt());
        switch(userDurability) {
            case "sync":
                cfg.setDurability(Durability.SYNC);
                break;
            case "flush":
                cfg.setDurability(Durability.FLUSH);
                break;
            case "none":
                cfg.setDurability(Durability.NONE);
                break;
            case "log":
                cfg.setDurability(Durability.NONE);
                break;
            default:
                throw new IllegalArgumentException("Unknown durability: " + userDurability);
        }
    }
    final BatchWriter bw = shellState.getAccumuloClient().createBatchWriter(tableName, cfg);
    bw.addMutation(m);
    try {
        bw.close();
    } catch (MutationsRejectedException e) {
        final ArrayList<String> lines = new ArrayList<>();
        if (!e.getSecurityErrorCodes().isEmpty()) {
            lines.add("\tAuthorization Failures:");
        }
        for (Entry<TabletId, Set<SecurityErrorCode>> entry : e.getSecurityErrorCodes().entrySet()) {
            lines.add("\t\t" + entry);
        }
        if (!e.getConstraintViolationSummaries().isEmpty()) {
            lines.add("\tConstraint Failures:");
        }
        for (ConstraintViolationSummary cvs : e.getConstraintViolationSummaries()) {
            lines.add("\t\t" + cvs);
        }
        if (lines.isEmpty() || e.getUnknownExceptions() > 0) {
            // must always print something
            lines.add(" " + e.getClass().getName() + " : " + e.getMessage());
            if (e.getCause() != null)
                lines.add("   Caused by : " + e.getCause().getClass().getName() + " : " + e.getCause().getMessage());
        }
        shellState.printLines(lines.iterator(), false);
        return 1;
    }
    return 0;
}
Also used : SecurityErrorCode(org.apache.accumulo.core.client.security.SecurityErrorCode) ArrayList(java.util.ArrayList) Text(org.apache.hadoop.io.Text) Entry(java.util.Map.Entry) Value(org.apache.accumulo.core.data.Value) BatchWriterConfig(org.apache.accumulo.core.client.BatchWriterConfig) ConstraintViolationSummary(org.apache.accumulo.core.data.ConstraintViolationSummary) Mutation(org.apache.accumulo.core.data.Mutation) ColumnVisibility(org.apache.accumulo.core.security.ColumnVisibility) BatchWriter(org.apache.accumulo.core.client.BatchWriter) MutationsRejectedException(org.apache.accumulo.core.client.MutationsRejectedException)

Example 79 with MutationsRejectedException

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

the class TestMultiTableIngest method main.

public static void main(String[] args) throws Exception {
    ArrayList<String> tableNames = new ArrayList<>();
    Opts opts = new Opts();
    opts.parseArgs(TestMultiTableIngest.class.getName(), args);
    // create the test table within accumulo
    try (AccumuloClient client = Accumulo.newClient().from(opts.getClientProps()).build()) {
        for (int i = 0; i < opts.tables; i++) {
            tableNames.add(String.format(opts.prefix + "%04d", i));
        }
        if (!opts.readonly) {
            for (String table : tableNames) client.tableOperations().create(table);
            MultiTableBatchWriter b;
            try {
                b = client.createMultiTableBatchWriter();
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
            // populate
            for (int i = 0; i < opts.count; i++) {
                Mutation m = new Mutation(new Text(String.format("%06d", i)));
                m.put("col" + ((i % 3) + 1), "qual", "junk");
                b.getBatchWriter(tableNames.get(i % tableNames.size())).addMutation(m);
            }
            try {
                b.close();
            } catch (MutationsRejectedException e) {
                throw new RuntimeException(e);
            }
        }
        try {
            readBack(opts, client, tableNames);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) MultiTableBatchWriter(org.apache.accumulo.core.client.MultiTableBatchWriter) ClientOpts(org.apache.accumulo.core.cli.ClientOpts) ArrayList(java.util.ArrayList) Text(org.apache.hadoop.io.Text) MutationsRejectedException(org.apache.accumulo.core.client.MutationsRejectedException) Mutation(org.apache.accumulo.core.data.Mutation) MutationsRejectedException(org.apache.accumulo.core.client.MutationsRejectedException)

Example 80 with MutationsRejectedException

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

the class MultiTableBatchWriterIT method testTableDelete.

@Test
public void testTableDelete() throws Exception {
    boolean mutationsRejected = false;
    try {
        final String[] names = getUniqueNames(2);
        final String table1 = names[0], table2 = names[1];
        TableOperations tops = accumuloClient.tableOperations();
        tops.create(table1);
        tops.create(table2);
        BatchWriter bw1 = mtbw.getBatchWriter(table1), bw2 = mtbw.getBatchWriter(table2);
        Mutation m1 = new Mutation("foo");
        m1.put("col1", "", "val1");
        m1.put("col2", "", "val2");
        bw1.addMutation(m1);
        bw2.addMutation(m1);
        tops.delete(table1);
        tops.delete(table2);
        Mutation m2 = new Mutation("bar");
        m2.put("col1", "", "val1");
        m2.put("col2", "", "val2");
        try {
            bw1.addMutation(m2);
            bw2.addMutation(m2);
        } catch (MutationsRejectedException e) {
            // Pass - Mutations might flush immediately
            mutationsRejected = true;
        }
    } finally {
        if (mtbw != null) {
            try {
                // Mutations might have flushed before the table offline occurred
                mtbw.close();
            } catch (MutationsRejectedException e) {
                // Pass
                mutationsRejected = true;
            }
        }
    }
    assertTrue("Expected mutations to be rejected.", mutationsRejected);
}
Also used : TableOperations(org.apache.accumulo.core.client.admin.TableOperations) MultiTableBatchWriter(org.apache.accumulo.core.client.MultiTableBatchWriter) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) MutationsRejectedException(org.apache.accumulo.core.client.MutationsRejectedException) Test(org.junit.Test)

Aggregations

MutationsRejectedException (org.apache.accumulo.core.client.MutationsRejectedException)91 Mutation (org.apache.accumulo.core.data.Mutation)62 BatchWriter (org.apache.accumulo.core.client.BatchWriter)52 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)31 Text (org.apache.hadoop.io.Text)31 Value (org.apache.accumulo.core.data.Value)30 BatchWriterConfig (org.apache.accumulo.core.client.BatchWriterConfig)23 Key (org.apache.accumulo.core.data.Key)21 IOException (java.io.IOException)20 HashMap (java.util.HashMap)15 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)13 AccumuloException (org.apache.accumulo.core.client.AccumuloException)12 ConstraintViolationSummary (org.apache.accumulo.core.data.ConstraintViolationSummary)10 ColumnVisibility (org.apache.accumulo.core.security.ColumnVisibility)10 ArrayList (java.util.ArrayList)9 Scanner (org.apache.accumulo.core.client.Scanner)9 Set (java.util.Set)8 Test (org.junit.Test)8 List (java.util.List)7 Entry (java.util.Map.Entry)7