Search in sources :

Example 21 with TableNotFoundException

use of org.apache.accumulo.core.client.TableNotFoundException in project incubator-rya by apache.

the class PcjTables method updateCardinality.

/**
 * Update the cardinality of a PCJ by a {@code delta}.
 *
 * @param accumuloConn - A connection to the Accumulo that hosts the PCJ table. (not null)
 * @param pcjTableName - The name of the PCJ table that will have its cardinality updated. (not null)
 * @param delta - How much the cardinality will change.
 * @throws PCJStorageException The cardinality could not be updated.
 */
private void updateCardinality(final Connector accumuloConn, final String pcjTableName, final long delta) throws PCJStorageException {
    checkNotNull(accumuloConn);
    checkNotNull(pcjTableName);
    ConditionalWriter conditionalWriter = null;
    try {
        conditionalWriter = accumuloConn.createConditionalWriter(pcjTableName, new ConditionalWriterConfig());
        boolean updated = false;
        while (!updated) {
            // Write the conditional update request to Accumulo.
            final long cardinality = getPcjMetadata(accumuloConn, pcjTableName).getCardinality();
            final ConditionalMutation mutation = makeUpdateCardinalityMutation(cardinality, delta);
            final ConditionalWriter.Result result = conditionalWriter.write(mutation);
            // Interpret the result.
            switch(result.getStatus()) {
                case ACCEPTED:
                    updated = true;
                    break;
                case REJECTED:
                    break;
                case UNKNOWN:
                    // We do not know if the mutation succeeded. At best, we
                    // can hope the metadata hasn't been updated
                    // since we originally fetched it and try again.
                    // Otherwise, continue forwards as if it worked. It's
                    // okay if this number is slightly off.
                    final long newCardinality = getPcjMetadata(accumuloConn, pcjTableName).getCardinality();
                    if (newCardinality != cardinality) {
                        updated = true;
                    }
                    break;
                case VIOLATED:
                    throw new PCJStorageException("The cardinality could not be updated because the commit violated a table constraint.");
                case INVISIBLE_VISIBILITY:
                    throw new PCJStorageException("The condition contains a visibility the updater can not satisfy.");
            }
        }
    } catch (AccumuloException | AccumuloSecurityException | TableNotFoundException e) {
        throw new PCJStorageException("Could not update the cardinality value of the PCJ Table named: " + pcjTableName, e);
    } finally {
        if (conditionalWriter != null) {
            conditionalWriter.close();
        }
    }
}
Also used : ConditionalWriter(org.apache.accumulo.core.client.ConditionalWriter) AccumuloException(org.apache.accumulo.core.client.AccumuloException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) ConditionalMutation(org.apache.accumulo.core.data.ConditionalMutation) ConditionalWriterConfig(org.apache.accumulo.core.client.ConditionalWriterConfig) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) PCJStorageException(org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage.PCJStorageException)

Example 22 with TableNotFoundException

use of org.apache.accumulo.core.client.TableNotFoundException in project incubator-rya by apache.

the class PcjTables method writeResults.

/**
 * Add a collection of results to a specific PCJ table.
 *
 * @param accumuloConn - A connection to the Accumulo that hosts the PCJ table. (not null)
 * @param pcjTableName - The name of the PCJ table that will receive the results. (not null)
 * @param results - Binding sets that will be written to the PCJ table. (not null)
 * @throws PCJStorageException The provided PCJ table doesn't exist, is missing the
 *   PCJ metadata, or the result could not be written to it.
 */
private void writeResults(final Connector accumuloConn, final String pcjTableName, final Collection<VisibilityBindingSet> results) throws PCJStorageException {
    checkNotNull(accumuloConn);
    checkNotNull(pcjTableName);
    checkNotNull(results);
    // Fetch the variable orders from the PCJ table.
    final PcjMetadata metadata = getPcjMetadata(accumuloConn, pcjTableName);
    // Write each result formatted using each of the variable orders.
    BatchWriter writer = null;
    try {
        writer = accumuloConn.createBatchWriter(pcjTableName, new BatchWriterConfig());
        for (final VisibilityBindingSet result : results) {
            final Set<Mutation> addResultMutations = makeWriteResultMutations(metadata.getVarOrders(), result);
            writer.addMutations(addResultMutations);
        }
    } catch (TableNotFoundException | MutationsRejectedException e) {
        throw new PCJStorageException("Could not add results to the PCJ table named: " + pcjTableName, e);
    } finally {
        if (writer != null) {
            try {
                writer.close();
            } catch (final MutationsRejectedException e) {
                throw new PCJStorageException("Could not add results to a PCJ table because some of the mutations were rejected.", e);
            }
        }
    }
}
Also used : TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) BatchWriterConfig(org.apache.accumulo.core.client.BatchWriterConfig) PcjMetadata(org.apache.rya.indexing.pcj.storage.PcjMetadata) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) ConditionalMutation(org.apache.accumulo.core.data.ConditionalMutation) PCJStorageException(org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage.PCJStorageException) MutationsRejectedException(org.apache.accumulo.core.client.MutationsRejectedException)

Example 23 with TableNotFoundException

use of org.apache.accumulo.core.client.TableNotFoundException in project incubator-rya by apache.

the class PcjTables method listResults.

/**
 * Get an {@link Iterator} over the {@link BindingSet}s that are stored in the PCJ table.
 *
 * @param accumuloConn - A connection to the Accumulo that hsots the PCJ table. (not null)
 * @param pcjTableName - The name of the PCJ table that will be scanned. (not null)
 * @param auths - the user's authorizations that will be used to scan the table. (not null)
 * @return An iterator over all of the {@link BindingSet}s that are stored as
 *   results for the PCJ.
 * @throws PCJStorageException The binding sets could not be fetched.
 */
public CloseableIterator<BindingSet> listResults(final Connector accumuloConn, final String pcjTableName, final Authorizations auths) throws PCJStorageException {
    requireNonNull(pcjTableName);
    // Fetch the Variable Orders for the binding sets and choose one of them. It
    // doesn't matter which one we choose because they all result in the same output.
    final PcjMetadata metadata = getPcjMetadata(accumuloConn, pcjTableName);
    final VariableOrder varOrder = metadata.getVarOrders().iterator().next();
    try {
        // Fetch only the Binding Sets whose Variable Order matches the selected one.
        final Scanner scanner = accumuloConn.createScanner(pcjTableName, auths);
        scanner.fetchColumnFamily(new Text(varOrder.toString()));
        // Return an Iterator that uses that scanner.
        return new ScannerBindingSetIterator(scanner, varOrder);
    } catch (final TableNotFoundException e) {
        throw new PCJStorageException(String.format("PCJ Table does not exist for name '%s'.", pcjTableName), e);
    }
}
Also used : Scanner(org.apache.accumulo.core.client.Scanner) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) PcjMetadata(org.apache.rya.indexing.pcj.storage.PcjMetadata) Text(org.apache.hadoop.io.Text) PCJStorageException(org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage.PCJStorageException)

Example 24 with TableNotFoundException

use of org.apache.accumulo.core.client.TableNotFoundException in project incubator-rya by apache.

the class AccumuloDocIdIndexer method runQuery.

private BatchScanner runQuery(final StarQuery query, Collection<Range> ranges) throws QueryEvaluationException {
    try {
        if (ranges.size() == 0) {
            final String rangeText = query.getCommonVarValue();
            Range r;
            if (rangeText != null) {
                r = new Range(new Text(query.getCommonVarValue()));
            } else {
                r = new Range();
            }
            ranges = Collections.singleton(r);
        }
        final Connector accCon = ConfigUtils.getConnector(conf);
        final IteratorSetting is = new IteratorSetting(30, "fii", DocumentIndexIntersectingIterator.class);
        DocumentIndexIntersectingIterator.setColumnFamilies(is, query.getColumnCond());
        if (query.hasContext()) {
            DocumentIndexIntersectingIterator.setContext(is, query.getContextURI());
        }
        final Authorizations auths;
        final String authsStr = conf.get(ConfigUtils.CLOUDBASE_AUTHS);
        if (authsStr == null || authsStr.isEmpty()) {
            auths = new Authorizations();
        } else {
            auths = new Authorizations(authsStr);
        }
        bs = accCon.createBatchScanner(EntityCentricIndex.getTableName(conf), auths, 15);
        bs.addScanIterator(is);
        bs.setRanges(ranges);
        return bs;
    } catch (TableNotFoundException | AccumuloException | AccumuloSecurityException e) {
        throw new QueryEvaluationException(e);
    }
}
Also used : Connector(org.apache.accumulo.core.client.Connector) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) Authorizations(org.apache.accumulo.core.security.Authorizations) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) Text(org.apache.hadoop.io.Text) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) Range(org.apache.accumulo.core.data.Range)

Example 25 with TableNotFoundException

use of org.apache.accumulo.core.client.TableNotFoundException in project incubator-rya by apache.

the class EntityLocalityGroupSetter method getPredicates.

private Iterator<String> getPredicates() {
    String auths = conf.get(ConfigUtils.CLOUDBASE_AUTHS);
    BatchScanner bs = null;
    try {
        bs = conn.createBatchScanner(tablePrefix + "prospects", new Authorizations(auths), 10);
    } catch (TableNotFoundException e) {
        e.printStackTrace();
        throw new Error("Attempting to scan missing table: " + tablePrefix + "prospects", e);
    }
    bs.setRanges(Collections.singleton(Range.prefix(new Text("predicate" + "\u0000"))));
    final Iterator<Entry<Key, Value>> iter = bs.iterator();
    return new Iterator<String>() {

        private String next = null;

        private boolean hasNextCalled = false;

        private boolean isEmpty = false;

        @Override
        public boolean hasNext() {
            if (!hasNextCalled && !isEmpty) {
                while (iter.hasNext()) {
                    Entry<Key, Value> temp = iter.next();
                    String row = temp.getKey().getRow().toString();
                    String[] rowArray = row.split("\u0000");
                    next = rowArray[1];
                    hasNextCalled = true;
                    return true;
                }
                isEmpty = true;
                return false;
            } else if (isEmpty) {
                return false;
            } else {
                return true;
            }
        }

        @Override
        public String next() {
            if (hasNextCalled) {
                hasNextCalled = false;
                return next;
            } else if (isEmpty) {
                throw new NoSuchElementException();
            } else {
                if (this.hasNext()) {
                    hasNextCalled = false;
                    return next;
                } else {
                    throw new NoSuchElementException();
                }
            }
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException("Cannot delete from iterator!");
        }
    };
}
Also used : Authorizations(org.apache.accumulo.core.security.Authorizations) BatchScanner(org.apache.accumulo.core.client.BatchScanner) Text(org.apache.hadoop.io.Text) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) Entry(java.util.Map.Entry) Iterator(java.util.Iterator) Value(org.apache.accumulo.core.data.Value) Key(org.apache.accumulo.core.data.Key) NoSuchElementException(java.util.NoSuchElementException)

Aggregations

TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)160 AccumuloException (org.apache.accumulo.core.client.AccumuloException)100 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)89 Text (org.apache.hadoop.io.Text)51 Value (org.apache.accumulo.core.data.Value)46 Key (org.apache.accumulo.core.data.Key)42 Scanner (org.apache.accumulo.core.client.Scanner)36 IOException (java.io.IOException)34 BatchWriter (org.apache.accumulo.core.client.BatchWriter)31 BatchWriterConfig (org.apache.accumulo.core.client.BatchWriterConfig)31 Connector (org.apache.accumulo.core.client.Connector)30 Mutation (org.apache.accumulo.core.data.Mutation)29 Range (org.apache.accumulo.core.data.Range)28 Authorizations (org.apache.accumulo.core.security.Authorizations)26 ArrayList (java.util.ArrayList)25 Entry (java.util.Map.Entry)25 TableExistsException (org.apache.accumulo.core.client.TableExistsException)25 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)23 MutationsRejectedException (org.apache.accumulo.core.client.MutationsRejectedException)23 HashMap (java.util.HashMap)19