org.apache.accumulo.core.data.Condition Java Examples
The following examples show how to use
org.apache.accumulo.core.data.Condition.
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: PcjTables.java From rya with Apache License 2.0 | 6 votes |
/** * Creates a {@link ConditionalMutation} that only updates the cardinality * of the PCJ table if the old value has not changed by the time this mutation * is committed to Accumulo. * * @param current - The current cardinality value. * @param delta - How much the cardinality will change. * @return The mutation that will perform the conditional update. */ private static ConditionalMutation makeUpdateCardinalityMutation(final long current, final long delta) { // Try to update the cardinality by the delta. final ConditionalMutation mutation = new ConditionalMutation(PCJ_METADATA_ROW_ID); final Condition lastCardinalityStillCurrent = new Condition( PCJ_METADATA_FAMILY, PCJ_METADATA_CARDINALITY); // Require the old cardinality to be the value we just read. final byte[] currentCardinalityBytes = longLexicoder.encode( current ); lastCardinalityStillCurrent.setValue( currentCardinalityBytes ); mutation.addCondition(lastCardinalityStillCurrent); // If that is the case, then update to the new value. final Value newCardinality = new Value( longLexicoder.encode(current + delta) ); mutation.put(PCJ_METADATA_FAMILY, PCJ_METADATA_CARDINALITY, newCardinality); return mutation; }
Example #2
Source File: TransactionImpl.java From fluo with Apache License 2.0 | 6 votes |
@Override public Collection<ConditionalMutation> createMutations(CommitData cd) { long commitTs = getStats().getCommitTs(); IteratorSetting iterConf = new IteratorSetting(10, PrewriteIterator.class); PrewriteIterator.setSnaptime(iterConf, startTs); boolean isTrigger = isTriggerRow(cd.prow) && cd.pcol.equals(notification.getColumn()); Condition lockCheck = new FluoCondition(env, cd.pcol).setIterators(iterConf).setValue(LockValue.encode(cd.prow, cd.pcol, isWrite(cd.pval), isDelete(cd.pval), isTrigger, getTransactorID())); final ConditionalMutation delLockMutation = new ConditionalFlutation(env, cd.prow, lockCheck); ColumnUtil.commitColumn(env, isTrigger, true, cd.pcol, isWrite(cd.pval), isDelete(cd.pval), isReadLock(cd.pval), startTs, commitTs, observedColumns, delLockMutation); return Collections.singletonList(delLockMutation); }
Example #3
Source File: TransactionImpl.java From fluo with Apache License 2.0 | 5 votes |
private ConditionalFlutation prewrite(ConditionalFlutation cm, Bytes row, Column col, Bytes val, Bytes primaryRow, Column primaryColumn, boolean isTriggerRow) { IteratorSetting iterConf = new IteratorSetting(10, PrewriteIterator.class); PrewriteIterator.setSnaptime(iterConf, startTs); boolean isTrigger = isTriggerRow && col.equals(notification.getColumn()); if (isTrigger) { PrewriteIterator.enableAckCheck(iterConf, notification.getTimestamp()); } if (isReadLock(val)) { PrewriteIterator.setReadlock(iterConf); } Condition cond = new FluoCondition(env, col).setIterators(iterConf); if (cm == null) { cm = new ConditionalFlutation(env, row, cond); } else { cm.addCondition(cond); } if (isWrite(val) && !isDelete(val)) { cm.put(col, ColumnType.DATA.encode(startTs), val.toArray()); } if (isReadLock(val)) { cm.put(col, ColumnType.RLOCK.encode(ReadLockUtil.encodeTs(startTs, false)), ReadLockValue.encode(primaryRow, primaryColumn, getTransactorID())); } else { cm.put(col, ColumnType.LOCK.encode(startTs), LockValue.encode(primaryRow, primaryColumn, isWrite(val), isDelete(val), isTriggerRow, getTransactorID())); } return cm; }
Example #4
Source File: ARS.java From accumulo-examples with Apache License 2.0 | 4 votes |
public void cancel(String what, String when, String who) throws Exception { String row = what + ":" + when; // Even though this method is only deleting a column, its important to use a conditional writer. // By updating the seq # when deleting a reservation, it // will cause any concurrent reservations to retry. If this delete were done using a batch // writer, then a concurrent reservation could report WAIT_LISTED // when it actually got the reservation. // its important to use an isolated scanner so that only whole mutations are seen try ( ConditionalWriter cwriter = client.createConditionalWriter(rTable, new ConditionalWriterConfig()); Scanner scanner = new IsolatedScanner(client.createScanner(rTable, Authorizations.EMPTY))) { while (true) { scanner.setRange(new Range(row)); int seq = -1; String reservation = null; for (Entry<Key,Value> entry : scanner) { String cf = entry.getKey().getColumnFamilyData().toString(); String cq = entry.getKey().getColumnQualifierData().toString(); String val = entry.getValue().toString(); // EXCERCISE avoid linear scan if (cf.equals("tx") && cq.equals("seq")) { seq = Integer.parseInt(val); } else if (cf.equals("res") && val.equals(who)) { reservation = cq; } } if (reservation != null) { ConditionalMutation update = new ConditionalMutation(row, new Condition("tx", "seq").setValue(seq + "")); update.putDelete("res", reservation); update.put("tx", "seq", (seq + 1) + ""); Status status = cwriter.write(update).getStatus(); switch (status) { case ACCEPTED: // successfully canceled reservation return; case REJECTED: case UNKNOWN: // retry // EXCERCISE exponential back-off could be used here break; default: throw new RuntimeException("Unexpected status " + status); } } else { // not reserved, nothing to do break; } } } }
Example #5
Source File: AccumuloRyaInstanceDetailsRepository.java From rya with Apache License 2.0 | 4 votes |
@Override public void update(final RyaDetails oldDetails, final RyaDetails newDetails) throws NotInitializedException, ConcurrentUpdateException, RyaDetailsRepositoryException { // Preconditions. requireNonNull(oldDetails); requireNonNull(newDetails); if(!newDetails.getRyaInstanceName().equals( instanceName )) { throw new RyaDetailsRepositoryException("The instance name that was in the provided 'newDetails' does not match " + "the instance name that this repository is connected to. Make sure you're connected to the" + "correct Rya instance."); } if(!isInitialized()) { throw new NotInitializedException("Could not update the details for the Rya instanced named '" + instanceName + "' because it has not been initialized yet."); } // Use a conditional writer so that we can detect when the old details // are no longer the currently stored ones. ConditionalWriter writer = null; try { // Setup the condition that ensures the details have not changed since the edits were made. final byte[] oldDetailsBytes = serializer.serialize(oldDetails); final Condition condition = new Condition(COL_FAMILY, COL_QUALIFIER); condition.setValue( oldDetailsBytes ); // Create the mutation that only performs the update if the details haven't changed. final ConditionalMutation mutation = new ConditionalMutation(ROW_ID); mutation.addCondition( condition ); final byte[] newDetailsBytes = serializer.serialize(newDetails); mutation.put(COL_FAMILY, COL_QUALIFIER, new Value(newDetailsBytes)); // Do the write. writer = connector.createConditionalWriter(detailsTableName, new ConditionalWriterConfig()); final Result result = writer.write(mutation); switch(result.getStatus()) { case REJECTED: case VIOLATED: throw new ConcurrentUpdateException("Could not update the details for the Rya instance named '" + instanceName + "' because the old value is out of date."); case UNKNOWN: case INVISIBLE_VISIBILITY: throw new RyaDetailsRepositoryException("Could not update the details for the Rya instance named '" + instanceName + "'."); } } catch (final TableNotFoundException | AccumuloException | AccumuloSecurityException e) { throw new RyaDetailsRepositoryException("Could not update the details for the Rya instance named '" + instanceName + "'."); } finally { if(writer != null) { writer.close(); } } }
Example #6
Source File: ConditionalFlutation.java From fluo with Apache License 2.0 | 4 votes |
public ConditionalFlutation(Environment env, Bytes row, Condition condition) { super(ByteUtil.toByteSequence(row), condition); this.env = env; }