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