Search in sources :

Example 6 with MutationsRejectedException

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

the class AccumuloTestHelper method populateAccumulo.

public static void populateAccumulo() throws IOException {
    BatchWriterConfig config = new BatchWriterConfig();
    BatchWriter batchwriter = null;
    try {
        batchwriter = con.createBatchWriter("tab1", config);
    } catch (TableNotFoundException e) {
        logger.error("error in test helper");
        DTThrowable.rethrow(e);
    }
    try {
        for (int i = 0; i < 500; ++i) {
            String rowstr = "row" + i;
            Mutation mutation = new Mutation(rowstr.getBytes());
            for (int j = 0; j < 500; ++j) {
                String colstr = "col" + "-" + j;
                String valstr = "val" + "-" + i + "-" + j;
                mutation.put(colfam0_bytes, colstr.getBytes(), System.currentTimeMillis(), valstr.getBytes());
            }
            batchwriter.addMutation(mutation);
        }
        batchwriter.close();
    } catch (MutationsRejectedException e) {
        logger.error("error in test helper");
        DTThrowable.rethrow(e);
    }
}
Also used : TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) BatchWriterConfig(org.apache.accumulo.core.client.BatchWriterConfig) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) MutationsRejectedException(org.apache.accumulo.core.client.MutationsRejectedException)

Example 7 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 8 with MutationsRejectedException

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

the class AccumuloPageSink method appendPage.

@Override
public CompletableFuture<?> appendPage(Page page) {
    // For each position within the page, i.e. row
    for (int position = 0; position < page.getPositionCount(); ++position) {
        Row row = new Row();
        // For each channel within the page, i.e. column
        for (int channel = 0; channel < page.getChannelCount(); ++channel) {
            // Get the type for this channel
            Type type = columns.get(channel).getType();
            // Read the value from the page and append the field to the row
            row.addField(TypeUtils.readNativeValue(type, page.getBlock(channel), position), type);
        }
        try {
            // Convert row to a Mutation, writing and indexing it
            Mutation mutation = toMutation(row, rowIdOrdinal, columns, serializer);
            writer.addMutation(mutation);
            if (indexer.isPresent()) {
                indexer.get().index(mutation);
            }
            ++numRows;
        } catch (MutationsRejectedException e) {
            throw new PrestoException(UNEXPECTED_ACCUMULO_ERROR, "Mutation rejected by server", e);
        }
        // TODO Fix arbitrary flush every 100k rows
        if (numRows % 100_000 == 0) {
            flush();
        }
    }
    return NOT_BLOCKED;
}
Also used : Type(com.facebook.presto.spi.type.Type) VarcharType(com.facebook.presto.spi.type.VarcharType) PrestoException(com.facebook.presto.spi.PrestoException) Row(com.facebook.presto.accumulo.model.Row) Mutation(org.apache.accumulo.core.data.Mutation) MutationsRejectedException(org.apache.accumulo.core.client.MutationsRejectedException)

Example 9 with MutationsRejectedException

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

the class AccumuloStore method deleteByQuery.

@Override
public long deleteByQuery(Query<K, T> query) {
    try {
        Scanner scanner = createScanner(query);
        // add iterator that drops values on the server side
        scanner.addScanIterator(new IteratorSetting(Integer.MAX_VALUE, SortedKeyIterator.class));
        RowIterator iterator = new RowIterator(scanner.iterator());
        long count = 0;
        while (iterator.hasNext()) {
            Iterator<Entry<Key, Value>> row = iterator.next();
            Mutation m = null;
            while (row.hasNext()) {
                Entry<Key, Value> entry = row.next();
                Key key = entry.getKey();
                if (m == null)
                    m = new Mutation(key.getRow());
                // TODO optimize to avoid continually creating column vis? prob does not matter for empty
                m.putDelete(key.getColumnFamily(), key.getColumnQualifier(), new ColumnVisibility(key.getColumnVisibility()), key.getTimestamp());
            }
            getBatchWriter().addMutation(m);
            count++;
        }
        return count;
    } catch (TableNotFoundException e) {
        // TODO return 0?
        LOG.error(e.getMessage(), e);
        return 0;
    } catch (MutationsRejectedException e) {
        LOG.error(e.getMessage(), e);
        return 0;
    } catch (IOException e) {
        LOG.error(e.getMessage(), e);
        return 0;
    }
}
Also used : IsolatedScanner(org.apache.accumulo.core.client.IsolatedScanner) Scanner(org.apache.accumulo.core.client.Scanner) IOException(java.io.IOException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) Entry(java.util.Map.Entry) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) SortedKeyIterator(org.apache.accumulo.core.iterators.SortedKeyIterator) RowIterator(org.apache.accumulo.core.client.RowIterator) Value(org.apache.accumulo.core.data.Value) Mutation(org.apache.accumulo.core.data.Mutation) ColumnVisibility(org.apache.accumulo.core.security.ColumnVisibility) Key(org.apache.accumulo.core.data.Key) MutationsRejectedException(org.apache.accumulo.core.client.MutationsRejectedException)

Example 10 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) {
    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 (IOException e) {
        LOG.error(e.getMessage(), e);
    }
}
Also used : Schema(org.apache.avro.Schema) Text(org.apache.hadoop.io.Text) IOException(java.io.IOException) 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)

Aggregations

MutationsRejectedException (org.apache.accumulo.core.client.MutationsRejectedException)12 Mutation (org.apache.accumulo.core.data.Mutation)8 PrestoException (com.facebook.presto.spi.PrestoException)5 BatchWriter (org.apache.accumulo.core.client.BatchWriter)3 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)3 Value (org.apache.accumulo.core.data.Value)3 IOException (java.io.IOException)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 BatchWriterConfig (org.apache.accumulo.core.client.BatchWriterConfig)2 Key (org.apache.accumulo.core.data.Key)2 ColumnVisibility (org.apache.accumulo.core.security.ColumnVisibility)2 Row (com.facebook.presto.accumulo.model.Row)1 Type (com.facebook.presto.spi.type.Type)1 VarcharType (com.facebook.presto.spi.type.VarcharType)1 Entry (java.util.Map.Entry)1 IsolatedScanner (org.apache.accumulo.core.client.IsolatedScanner)1 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)1 RowIterator (org.apache.accumulo.core.client.RowIterator)1 Scanner (org.apache.accumulo.core.client.Scanner)1 SortedKeyIterator (org.apache.accumulo.core.iterators.SortedKeyIterator)1