Search in sources :

Example 51 with MutationsRejectedException

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

the class PcjIntegrationTestingUtil 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 PcjException
 *             The provided PCJ table doesn't exist, is missing the PCJ
 *             metadata, or the result could not be written to it.
 */
private static void writeResults(final Connector accumuloConn, final String pcjTableName, final Collection<BindingSet> results) throws PcjException {
    checkNotNull(accumuloConn);
    checkNotNull(pcjTableName);
    checkNotNull(results);
    // Fetch the variable orders from the PCJ table.
    final PcjMetadata metadata = new PcjTables().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 BindingSet result : results) {
            final Set<Mutation> addResultMutations = makeWriteResultMutations(metadata.getVarOrders(), result);
            writer.addMutations(addResultMutations);
        }
    } catch (TableNotFoundException | MutationsRejectedException e) {
        throw new PcjException("Could not add results to the PCJ table named: " + pcjTableName, e);
    } finally {
        if (writer != null) {
            try {
                writer.close();
            } catch (final MutationsRejectedException e) {
                throw new PcjException("Could not add results to a PCJ table because some of the mutations were rejected.", e);
            }
        }
    }
}
Also used : VisibilityBindingSet(org.apache.rya.api.model.VisibilityBindingSet) BindingSet(org.openrdf.query.BindingSet) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) PcjException(org.apache.rya.indexing.pcj.storage.PcjException) BatchWriterConfig(org.apache.accumulo.core.client.BatchWriterConfig) PcjMetadata(org.apache.rya.indexing.pcj.storage.PcjMetadata) PcjTables(org.apache.rya.indexing.pcj.storage.accumulo.PcjTables) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) MutationsRejectedException(org.apache.accumulo.core.client.MutationsRejectedException)

Example 52 with MutationsRejectedException

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

the class PcjTables method updateMockCardinality.

/**
 * Update the cardinality of a PCJ by a {@code delta}.
 *
 * This method updates the PCJ table cardinality using a BatchWriter in the event that
 * the Accumulo Connector is for a MockInstance.  In the event that the cardinality is
 * being updated asynchronously, there are no guarantees that the resulting cardinality
 * will be correct.
 *
 * @param accumuloConn - A connection to a Mock Accumulo Instance 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 updateMockCardinality(final Connector accumuloConn, final String pcjTableName, final long delta) throws PCJStorageException {
    checkNotNull(accumuloConn);
    checkNotNull(pcjTableName);
    BatchWriter batchWriter = null;
    try {
        batchWriter = accumuloConn.createBatchWriter(pcjTableName, new BatchWriterConfig());
        final long cardinality = getPcjMetadata(accumuloConn, pcjTableName).getCardinality();
        final Mutation mutation = new Mutation(PCJ_METADATA_ROW_ID);
        final Value newCardinality = new Value(longLexicoder.encode(cardinality + delta));
        mutation.put(PCJ_METADATA_FAMILY, PCJ_METADATA_CARDINALITY, newCardinality);
        batchWriter.addMutation(mutation);
    } catch (TableNotFoundException | MutationsRejectedException e) {
        throw new PCJStorageException("Could not update the cardinality value of the PCJ Table named: " + pcjTableName, e);
    } finally {
        if (batchWriter != null) {
            try {
                batchWriter.close();
            } catch (final MutationsRejectedException e) {
                throw new PCJStorageException("Could not update the cardinality value of the PCJ Table named: " + pcjTableName, e);
            }
        }
    }
}
Also used : TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) 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) ConditionalMutation(org.apache.accumulo.core.data.ConditionalMutation) PCJStorageException(org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage.PCJStorageException) MutationsRejectedException(org.apache.accumulo.core.client.MutationsRejectedException)

Example 53 with MutationsRejectedException

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

the class PcjTables method purgePcjTable.

/**
 * Deletes all of the rows that are in a PCJ index and sets its cardinality back to 0.
 *
 * @param accumuloConn - Connects to the Accumulo that hosts the PCJ indices. (not null)
 * @param pcjTableName - The name of the PCJ table that will be purged. (not null)
 * @throws PCJStorageException Either the rows could not be dropped from the
 *   PCJ table or the metadata could not be written back to the table.
 */
public void purgePcjTable(final Connector accumuloConn, final String pcjTableName) throws PCJStorageException {
    checkNotNull(accumuloConn);
    checkNotNull(pcjTableName);
    // Fetch the metadaata from the PCJ table.
    final PcjMetadata oldMetadata = getPcjMetadata(accumuloConn, pcjTableName);
    // Delete all of the rows
    try {
        accumuloConn.tableOperations().deleteRows(pcjTableName, null, null);
    } catch (AccumuloException | AccumuloSecurityException | TableNotFoundException e) {
        throw new PCJStorageException("Could not delete the rows of data from PCJ table named: " + pcjTableName, e);
    }
    // Store the new metadata.
    final PcjMetadata newMetadata = new PcjMetadata(oldMetadata.getSparql(), 0L, oldMetadata.getVarOrders());
    final List<Mutation> mutations = makeWriteMetadataMutations(newMetadata);
    BatchWriter writer = null;
    try {
        writer = accumuloConn.createBatchWriter(pcjTableName, new BatchWriterConfig());
        writer.addMutations(mutations);
        writer.flush();
    } catch (final TableNotFoundException | MutationsRejectedException e) {
        throw new PCJStorageException("Could not rewrite the PCJ cardinality for table named '" + pcjTableName + "'. This table will not work anymore.", e);
    } finally {
        if (writer != null) {
            try {
                writer.close();
            } catch (final MutationsRejectedException e) {
                throw new PCJStorageException("Could not close the batch writer.", e);
            }
        }
    }
}
Also used : AccumuloException(org.apache.accumulo.core.client.AccumuloException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) BatchWriterConfig(org.apache.accumulo.core.client.BatchWriterConfig) PcjMetadata(org.apache.rya.indexing.pcj.storage.PcjMetadata) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) PCJStorageException(org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage.PCJStorageException) Mutation(org.apache.accumulo.core.data.Mutation) ConditionalMutation(org.apache.accumulo.core.data.ConditionalMutation) BatchWriter(org.apache.accumulo.core.client.BatchWriter) MutationsRejectedException(org.apache.accumulo.core.client.MutationsRejectedException)

Example 54 with MutationsRejectedException

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

the class AccumuloRyaDAO method flush.

@Override
public void flush() throws RyaDAOException {
    try {
        mt_bw.flush();
        flushIndexers();
    } catch (final MutationsRejectedException e) {
        throw new RyaDAOException(e);
    }
}
Also used : RyaDAOException(org.apache.rya.api.persist.RyaDAOException) MutationsRejectedException(org.apache.accumulo.core.client.MutationsRejectedException)

Example 55 with MutationsRejectedException

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

the class AccumuloRyaDAO method purge.

@Override
public void purge(final RdfCloudTripleStoreConfiguration configuration) {
    for (final String tableName : getTables()) {
        try {
            purge(tableName, configuration.getAuths());
            compact(tableName);
        } catch (final TableNotFoundException e) {
            logger.error(e.getMessage());
        } catch (final MutationsRejectedException e) {
            logger.error(e.getMessage());
        }
    }
    for (final AccumuloIndexer indexer : this.secondaryIndexers) {
        try {
            indexer.purge(configuration);
        } catch (final Exception e) {
            logger.error("Failed to purge indexer", e);
        }
    }
}
Also used : TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) AccumuloIndexer(org.apache.rya.accumulo.experimental.AccumuloIndexer) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) MutationsRejectedException(org.apache.accumulo.core.client.MutationsRejectedException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) IOException(java.io.IOException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) RyaDAOException(org.apache.rya.api.persist.RyaDAOException) MutationsRejectedException(org.apache.accumulo.core.client.MutationsRejectedException)

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