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);
}
}
}
}
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);
}
}
}
}
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);
}
}
}
}
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);
}
}
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);
}
}
}
Aggregations