org.apache.accumulo.core.client.MutationsRejectedException Java Examples

The following examples show how to use org.apache.accumulo.core.client.MutationsRejectedException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AccumuloPageSink.java    From presto with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example #2
Source File: AccumuloCacheStore.java    From datawave with Apache License 2.0 6 votes vote down vote up
@Override
public void clear() {
    log.trace("Clearing Accumulo cache for table {}.", tableName);
    try {
        BatchWriterConfig bwCfg = new BatchWriterConfig();
        BatchDeleter deleter = connector.createBatchDeleter(tableName, authorizations, 10, bwCfg);
        try {
            deleter.setRanges(Collections.singletonList(new Range()));
            deleter.delete();
        } finally {
            deleter.close();
        }
    } catch (MutationsRejectedException | TableNotFoundException e) {
        throw new PersistenceException("Unable to clear Accumulo cache for " + tableName, e);
    }
}
 
Example #3
Source File: AccumuloMutationProcessor.java    From aliyun-maxcompute-data-collectors with Apache License 2.0 6 votes vote down vote up
@Override
/**
 * Processes a record by extracting its field map and converting
 * it into a list of Mutations into Accumulo.
 */
public void accept(FieldMappable record)
    throws IOException, ProcessingException {
  Map<String, Object> fields = record.getFieldMap();

  Iterable<Mutation> putList = mutationTransformer.getMutations(fields);
  if (null != putList) {
    for (Mutation m : putList) {
      try {
        this.table.addMutation(m);
      } catch (MutationsRejectedException ex) {
        throw new IOException("Mutation rejected" , ex);
      }
    }
  }
}
 
Example #4
Source File: MockAccumuloRecordWriter.java    From datawave with Apache License 2.0 6 votes vote down vote up
@Override
public void write(Text key, Mutation value) throws IOException, InterruptedException {
    try {
        for (ColumnUpdate update : value.getUpdates()) {
            log.debug("Table: "
                            + key
                            + ", Key: "
                            + new Key(value.getRow(), update.getColumnFamily(), update.getColumnQualifier(), update.getColumnVisibility(), update
                                            .getTimestamp()));
        }
        if (writerMap.get(key) == null) {
            log.error("key had null value: " + key);
        }
        writerMap.get(key).addMutation(value);
    } catch (MutationsRejectedException e) {
        throw new IOException("Error adding mutation", e);
    }
}
 
Example #5
Source File: AccumuloOperations.java    From geowave with Apache License 2.0 6 votes vote down vote up
public boolean deleteAll(
    final String tableName,
    final String columnFamily,
    final String... additionalAuthorizations) {
  BatchDeleter deleter = null;
  try {
    deleter = createBatchDeleter(tableName, additionalAuthorizations);
    deleter.setRanges(Arrays.asList(new Range()));
    deleter.fetchColumnFamily(new Text(columnFamily));
    deleter.delete();
    return true;
  } catch (final TableNotFoundException | MutationsRejectedException e) {
    LOGGER.warn("Unable to delete row from table [" + tableName + "].", e);
    return false;
  } finally {
    if (deleter != null) {
      deleter.close();
    }
  }
}
 
Example #6
Source File: AccumuloOperations.java    From geowave with Apache License 2.0 6 votes vote down vote up
@Override
public boolean deleteAll(
    final String indexName,
    final String typeName,
    final Short adapterId,
    final String... additionalAuthorizations) {
  BatchDeleter deleter = null;
  try {
    deleter = createBatchDeleter(indexName, additionalAuthorizations);

    deleter.setRanges(Arrays.asList(new Range()));
    deleter.fetchColumnFamily(new Text(ByteArrayUtils.shortToString(adapterId)));
    deleter.delete();
    return true;
  } catch (final TableNotFoundException | MutationsRejectedException e) {
    LOGGER.warn("Unable to delete row from table [" + indexName + "].", e);
    return false;
  } finally {
    if (deleter != null) {
      deleter.close();
    }
  }
}
 
Example #7
Source File: AccumuloOperations.java    From geowave with Apache License 2.0 6 votes vote down vote up
public void deleteRowsFromDataIndex(final byte[][] rows, final short adapterId) {
  // to have backwards compatibility before 1.8.0 we can assume BaseScanner is autocloseable
  BatchDeleter deleter = null;
  try {
    deleter = createBatchDeleter(DataIndexUtils.DATA_ID_INDEX.getName());
    deleter.fetchColumnFamily(new Text(ByteArrayUtils.shortToString(adapterId)));
    deleter.setRanges(
        Arrays.stream(rows).map(r -> Range.exact(new Text(r))).collect(Collectors.toList()));

    deleter.delete();
  } catch (final TableNotFoundException | MutationsRejectedException e) {
    LOGGER.warn("Unable to delete from data index", e);
  } finally {
    if (deleter != null) {
      deleter.close();
    }
  }
}
 
Example #8
Source File: DeleteHistoricalLegacyStreamingPropertyValueData.java    From vertexium with Apache License 2.0 6 votes vote down vote up
private void deleteRows(BatchWriter writer, List<Key> rowsToDelete, Options options) throws MutationsRejectedException {
    rowsToDelete.sort(Comparator.comparingLong(Key::getTimestamp));
    int i = 0;
    for (Key key : rowsToDelete) {
        if (i < rowsToDelete.size() - options.getVersionsToKeep()) {
            LOGGER.debug("deleting row: %s", key.getRow().toString());
            if (!options.isDryRun()) {
                Mutation mutation = new Mutation(key.getRow());
                mutation.putDelete(
                    key.getColumnFamily(),
                    key.getColumnQualifier(),
                    key.getColumnVisibilityParsed(),
                    key.getTimestamp()
                );
                writer.addMutation(mutation);
            }
        } else {
            if (options.isDryRun()) {
                LOGGER.debug("skipping row: %s", key.getRow().toString());
            }
        }
        i++;
    }
}
 
Example #9
Source File: AccumuloMetadataWriter.java    From geowave with Apache License 2.0 6 votes vote down vote up
@Override
public void write(final GeoWaveMetadata metadata) {
  final Mutation mutation = new Mutation(new Text(metadata.getPrimaryId()));
  final Text cf = metadataTypeName;
  final Text cq =
      metadata.getSecondaryId() != null ? new Text(metadata.getSecondaryId()) : new Text();
  final byte[] visibility = metadata.getVisibility();
  if (visibility != null) {
    mutation.put(cf, cq, new ColumnVisibility(visibility), new Value(metadata.getValue()));
  } else {
    mutation.put(cf, cq, new Value(metadata.getValue()));
  }
  try {
    writer.addMutation(mutation);
  } catch (final MutationsRejectedException e) {
    LOGGER.error("Unable to write metadata", e);
  }
}
 
Example #10
Source File: AbstractAccumuloOutputOperator.java    From attic-apex-malhar with Apache License 2.0 6 votes vote down vote up
@Override
public void storeAggregate()
{
  try {
    for (T tuple : tuples) {
      Mutation mutation = operationMutation(tuple);
      store.getBatchwriter().addMutation(mutation);
    }
    store.getBatchwriter().flush();

  } catch (MutationsRejectedException e) {
    logger.error("unable to write mutations", e);
    DTThrowable.rethrow(e);
  }
  tuples.clear();
}
 
Example #11
Source File: AccumuloWindowStore.java    From attic-apex-malhar with Apache License 2.0 6 votes vote down vote up
@Override
public void storeCommittedWindowId(String appId, int operatorId,long windowId)
{
  byte[] WindowIdBytes = toBytes(windowId);
  String columnKey = appId + "_" + operatorId + "_" + lastWindowColumnName;
  lastWindowColumnBytes = columnKey.getBytes();
  Mutation mutation = new Mutation(rowBytes);
  mutation.put(columnFamilyBytes, lastWindowColumnBytes, WindowIdBytes);
  try {
    batchwriter.addMutation(mutation);
    batchwriter.flush();
  } catch (MutationsRejectedException e) {
    logger.error("error getting committed window id", e);
    DTThrowable.rethrow(e);
  }
}
 
Example #12
Source File: AccumuloRecordWriter.java    From datawave with Apache License 2.0 6 votes vote down vote up
@Override
public void close(TaskAttemptContext attempt) throws IOException, InterruptedException {
    log.debug("mutations written: " + mutCount + ", values written: " + valCount);
    if (simulate) {
        return;
    }
    
    try {
        mtbw.close();
    } catch (MutationsRejectedException e) {
        if (e.getSecurityErrorCodes().size() >= 0) {
            HashSet<String> tables = new HashSet<>();
            for (TabletId tabletId : e.getSecurityErrorCodes().keySet()) {
                tables.add(tabletId.getTableId().toString());
            }
            
            log.error("Not authorized to write to tables : " + tables);
        }
        
        if (!e.getConstraintViolationSummaries().isEmpty()) {
            log.error("Constraint violations : " + e.getConstraintViolationSummaries());
        }
    } finally {
        returnConnector();
    }
}
 
Example #13
Source File: EdgeKeyVersioningCache.java    From datawave with Apache License 2.0 6 votes vote down vote up
private String seedMetadataTable(Connector connector, long time, int keyVersionNum) throws TableNotFoundException, MutationsRejectedException {
    Value emptyVal = new Value();
    SimpleDateFormat dateFormat = new SimpleDateFormat(DateNormalizer.ISO_8601_FORMAT_STRING);
    String dateString = dateFormat.format(new Date(time));
    try (BatchWriter recordWriter = connector.createBatchWriter(metadataTableName, new BatchWriterConfig())) {
        String normalizedVersionNum = NumericalEncoder.encode(Integer.toString(keyVersionNum));
        String rowID = "edge_key";
        String columnFamily = "version";
        String columnQualifier = normalizedVersionNum + "/" + dateString;
        
        Mutation m = new Mutation(rowID);
        
        m.put(new Text(columnFamily), new Text(columnQualifier), emptyVal);
        
        recordWriter.addMutation(m);
    }
    return dateString;
}
 
Example #14
Source File: WholeColumnFamilyIteratorTest.java    From accumulo-recipes with Apache License 2.0 5 votes vote down vote up
private void persistTestMutations(int numRows, int entriesPerRow) throws TableNotFoundException, MutationsRejectedException {

        BatchWriter writer = connector.createBatchWriter("test", 1000, 1000, 1);

        for (int j = 0; j < numRows; j++) {
            Mutation m = new Mutation(Integer.toString(j));
            for (int i = 0; i < entriesPerRow; i++)
                m.put(new Text(Integer.toString(j)), new Text(String.valueOf(i)), new Value("".getBytes()));

            writer.addMutation(m);
        }
        writer.flush();
    }
 
Example #15
Source File: AccumuloFreeTextIndexer.java    From rya with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public void flush() throws IOException {
    try {
        mtbw.flush();
    } catch (final MutationsRejectedException e) {
        logger.error("error flushing the batch writer", e);
        throw new IOException(e);
    }
}
 
Example #16
Source File: AbstractAccumuloWriter.java    From geowave with Apache License 2.0 5 votes vote down vote up
public void write(final Iterable<Mutation> mutations) {
  try {
    batchWriter.addMutations(mutations);
  } catch (final MutationsRejectedException e) {
    LOGGER.error("Unable to close batch writer", e);
  }
}
 
Example #17
Source File: AbstractAccumuloWriter.java    From geowave with Apache License 2.0 5 votes vote down vote up
@Override
public void flush() {
  try {
    batchWriter.flush();
  } catch (final MutationsRejectedException e) {
    LOGGER.error("Unable to flush batch writer", e);
  }
}
 
Example #18
Source File: AbstractAccumuloWriter.java    From geowave with Apache License 2.0 5 votes vote down vote up
@Override
public void close() {
  try {
    batchWriter.close();
  } catch (final MutationsRejectedException e) {
    LOGGER.error("Unable to close batch writer", e);
  }
}
 
Example #19
Source File: AbstractAccumuloWriter.java    From geowave with Apache License 2.0 5 votes vote down vote up
public void write(final Mutation mutation) {
  try {
    batchWriter.addMutation(mutation);
  } catch (final MutationsRejectedException e) {
    LOGGER.error("Unable to write batch writer", e);
  }
}
 
Example #20
Source File: AccumuloDeleter.java    From geowave with Apache License 2.0 5 votes vote down vote up
@Override
public void close() {
  if (!closed) {
    // make sure delete is only called once
    try {
      ((BatchDeleter) scanner).delete();
    } catch (MutationsRejectedException | TableNotFoundException e) {
      LOGGER.error("Unable to delete row", e);
    }

    closed = true;
  }
  super.close();

}
 
Example #21
Source File: AccumuloTemporalIndexer.java    From rya with Apache License 2.0 5 votes vote down vote up
/**
 * Store a statement in the index if it meets the criterion: Object should be
 * a literal and one of the validPredicates from the configuration.
 * If it does not meet the criteria, it is silently ignored.
 * logs a warning if the object is not parse-able.
 * Attempts to parse with calendarValue = literalValue.calendarValue()
 * if that fails, tries: org.joda.time.DateTime.parse() .
 * T O D O parse an interval using multiple predicates for same subject -- ontology dependent.
 */
private void storeStatement(final Statement statement) throws IOException, IllegalArgumentException {
	Objects.requireNonNull(temporalIndexBatchWriter,"This is not initialized for writing.  Must call setMultiTableBatchWriter() and init().");
    // if the predicate list is empty, accept all predicates.
    // Otherwise, make sure the predicate is on the "valid" list
    final boolean isValidPredicate = validPredicates == null || validPredicates.isEmpty() || validPredicates.contains(statement.getPredicate());
    if (!isValidPredicate || !(statement.getObject() instanceof Literal)) {
        return;
    }

    final DateTime[] indexDateTimes = new DateTime[2]; // 0 begin, 1 end of interval
    extractDateTime(statement, indexDateTimes);
    if (indexDateTimes[0]==null) {
        return;
    }

    if (!this.isInit)
        throw new RuntimeException("Method .init() was not called (or failed) before attempting to store statements.");

    // Add this as an instant, or interval.
    try {
        if (indexDateTimes[1] != null) {
            final TemporalInterval interval = new TemporalInterval(new TemporalInstantRfc3339(indexDateTimes[0]), new TemporalInstantRfc3339(indexDateTimes[1]));
            addInterval(temporalIndexBatchWriter, interval, statement);
        } else {
            final TemporalInstant instant = new TemporalInstantRfc3339(indexDateTimes[0]);
            addInstant(temporalIndexBatchWriter, instant, statement);
        }
    } catch (final MutationsRejectedException e) {
        throw new IOException("While adding interval/instant for statement =" + statement, e);
    }
}
 
Example #22
Source File: FirstNEntriesInRowIteratorIT.java    From accumulo-recipes with Apache License 2.0 5 votes vote down vote up
private void persistTestMutations(int numRows, int entriesPerRow) throws TableNotFoundException, MutationsRejectedException {

        BatchWriter writer = connector.createBatchWriter("test", 1000, 1000, 1);

        for (int j = 0; j < numRows; j++) {
            Mutation m = new Mutation(Integer.toString(j));
            for (int i = 0; i < entriesPerRow; i++)
                m.put(new Text(Integer.toString(i)), new Text(""), new Value("".getBytes()));

            writer.addMutation(m);
        }
        writer.flush();
    }
 
Example #23
Source File: GlobalInstances.java    From AccumuloGraph with Apache License 2.0 5 votes vote down vote up
/**
 * Flush the writer, if autoflush is enabled.
 */
public void checkedFlush() {
  if (config.getAutoFlush()) {
    try {
      mtbw.flush();
    } catch (MutationsRejectedException e) {
      throw new AccumuloGraphException(e);
    }
  }
}
 
Example #24
Source File: ProspectorUtils.java    From rya with Apache License 2.0 5 votes vote down vote up
public static void writeMutations(final Connector connector, final String tableName, final Collection<Mutation> mutations) throws TableNotFoundException, MutationsRejectedException {
    final BatchWriter bw = connector.createBatchWriter(tableName, 10000l, 10000l, 4);
    for(final Mutation mutation : mutations) {
        bw.addMutation(mutation);
    }
    bw.flush();
    bw.close();
}
 
Example #25
Source File: AccumuloPcjIT.java    From rya with Apache License 2.0 5 votes vote down vote up
@Test
public void testEvaluateSingleIndex()
		throws TupleQueryResultHandlerException, QueryEvaluationException,
		MalformedQueryException, RepositoryException, PcjException,
		SailException, MutationsRejectedException, TableNotFoundException {

	final String indexSparqlString = ""//
			+ "SELECT ?e ?l ?c " //
			+ "{" //
			+ "  ?e a ?c . "//
			+ "  ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l "//
			+ "}";//

	PcjIntegrationTestingUtil.createAndPopulatePcj(conn, accCon, tablename + 1,
			indexSparqlString, new String[] { "e", "l", "c" },
			Optional.absent());

	final String queryString = ""//
			+ "SELECT ?e ?c ?l ?o " //
			+ "{" //
			+ "  ?e a ?c . "//
			+ "  ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l . "//
			+ "  ?e <uri:talksTo> ?o . "//
			+ "}";//

	final CountingResultHandler crh1 = new CountingResultHandler();
	final CountingResultHandler crh2 = new CountingResultHandler();

	conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString)
			.evaluate(crh1);

	pcjConn.prepareTupleQuery(QueryLanguage.SPARQL, queryString).evaluate(
			crh2);

	Assert.assertEquals(crh1.getCount(), crh2.getCount());

}
 
Example #26
Source File: AccumuloTemporalIndexer.java    From rya with Apache License 2.0 5 votes vote down vote up
/**
 * Remove an interval instant
 *
 * @param writer
 * @param cv
 * @param instant
 * @throws MutationsRejectedException
 */
public void removeInstant(final BatchWriter writer, final TemporalInstant instant, final Statement statement) throws MutationsRejectedException {
    final KeyParts keyParts = new KeyParts(statement, instant);
    for (final KeyParts  k: keyParts) {
        final Mutation m = new Mutation(k.getStoreKey());
        m.putDelete(k.cf, k.cq);
        writer.addMutation(m);
    }
}
 
Example #27
Source File: AccumuloTemporalIndexer.java    From rya with Apache License 2.0 5 votes vote down vote up
/**
 * Flush the data to the batchwriter.
 * Throws a IOException as required by the flushable interface,
 * wrapping MutationsRejectedException.
 */
@Override
public void flush() throws IOException {
    try {
        mtbw.flush();
    } catch (final MutationsRejectedException e) {
        final String msg = "Error while flushing the batch writer.";
        logger.error(msg, e);
        throw new IOException(msg, e);
    }
}
 
Example #28
Source File: AccumuloFreeTextIndexer.java    From rya with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public void close() throws IOException {
    try {
    	if (mtbw!=null)
    		mtbw.close();
    } catch (final MutationsRejectedException e) {
        logger.error("error closing the batch writer", e);
        throw new IOException(e);
    }
}
 
Example #29
Source File: AccumuloTemporalIndexer.java    From rya with Apache License 2.0 5 votes vote down vote up
/**
 * Close batchwriter.
 * Throws a IOException as required by the flushable interface,
 * wrapping MutationsRejectedException.
 */
@Override
public void close() throws IOException {
    try {
        if (mtbw != null) {
            mtbw.close();
        }

    } catch (final MutationsRejectedException e) {
        final String msg = "Error while closing the batch writer.";
        logger.error(msg, e);
        throw new IOException(msg, e);
    }
}
 
Example #30
Source File: AccumuloTemporalIndexer.java    From rya with Apache License 2.0 5 votes vote down vote up
private void deleteStatement(final Statement statement) throws IOException, IllegalArgumentException {
	Objects.requireNonNull(temporalIndexBatchWriter,"This is not initialized for writing.  Must call setMultiTableBatchWriter() and init().");

    // if the predicate list is empty, accept all predicates.
    // Otherwise, make sure the predicate is on the "valid" list
    final boolean isValidPredicate = validPredicates.isEmpty() || validPredicates.contains(statement.getPredicate());
    if (!isValidPredicate || !(statement.getObject() instanceof Literal)) {
        return;
    }
    final DateTime[] indexDateTimes = new DateTime[2]; // 0 begin, 1 end of interval
    extractDateTime(statement, indexDateTimes);
    if (indexDateTimes[0] == null) {
        return;
    }

    // Remove this as an instant, or interval.
    try {
        if (indexDateTimes[1] != null) {
            final TemporalInterval interval = new TemporalInterval(new TemporalInstantRfc3339(indexDateTimes[0]), new TemporalInstantRfc3339(indexDateTimes[1]));
            removeInterval(temporalIndexBatchWriter, interval, statement);
        } else {
            final TemporalInstant instant = new TemporalInstantRfc3339(indexDateTimes[0]);
            removeInstant(temporalIndexBatchWriter, instant, statement);
        }
    } catch (final MutationsRejectedException e) {
        throw new IOException("While adding interval/instant for statement =" + statement, e);
    }
}