@Override public void preBatchMutate(ObserverContext<RegionCoprocessorEnvironment> c, MiniBatchOperationInProgress<Mutation> miniBatchOp) throws IOException { Mutation mut = miniBatchOp.getOperation(0); if (mut instanceof Delete) { List<Cell> cells = mut.getFamilyCellMap().get(test); Delete[] deletes = new Delete[] { // delete only 2 rows new Delete(row1, cells.get(0).getTimestamp()), new Delete(row2, cells.get(0).getTimestamp()), }; LOG.info("Deleting:" + Arrays.toString(deletes)); miniBatchOp.addOperationsFromCP(0, deletes); } } }
@Override public void preBatchMutate(final ObserverContext<RegionCoprocessorEnvironment> c, final MiniBatchOperationInProgress<Mutation> miniBatchOp) throws IOException { if (ops.incrementAndGet() % 20000 == 0) { LOG.info("Wrote " + ops.get() + " times in region " + regionName); } for (int i = 0; i < miniBatchOp.size(); i++) { miniBatchOp.setOperationStatus(i, new OperationStatus(HConstants.OperationStatusCode.SUCCESS)); } c.bypass(); } }
protected MiniBatchOperationInProgress<Mutation> createMiniBatch(final int lastIndexExclusive, final int readyToWriteCount) { return new MiniBatchOperationInProgress<>(getMutationsForCoprocs(), retCodeDetails, walEditsFromCoprocessors, nextIndexToProcess, lastIndexExclusive, readyToWriteCount); }
private void checkAndMergeCPMutations(final MiniBatchOperationInProgress<Mutation> miniBatchOp, final List<RowLock> acquiredRowLocks, final long timestamp) throws IOException { visitBatchOperations(true, nextIndexToProcess + miniBatchOp.size(), (int i) -> { Mutation[] cpMutations = miniBatchOp.getOperationsFromCoprocessors(i - nextIndexToProcess); if (cpMutations == null) { return true; miniBatchOp.addCellCount(cells.size());
Durability durability = Durability.SKIP_WAL; boolean copyMutations = false; for (int i = 0; i < miniBatchOp.size(); i++) { Mutation m = miniBatchOp.getOperation(i); if (this.builder.isAtomicOp(m)) { miniBatchOp.setOperationStatus(i, IGNORE); continue; Mutation firstMutation = miniBatchOp.getOperation(0); ReplayWrite replayWrite = this.builder.getReplayWrite(firstMutation); boolean resetTimeStamp = replayWrite == null; long now = EnvironmentEdgeManager.currentTimeMillis(); byte[] byteNow = Bytes.toBytes(now); for (int i = 0; i < miniBatchOp.size(); i++) { Mutation m = miniBatchOp.getOperation(i); if (miniBatchOp.getOperationStatus(i) != IGNORE && this.builder.isEnabled(m)) { if (resetTimeStamp) { miniBatchOp.setOperationStatus(i, NOWRITE); WALEdit edit = miniBatchOp.getWalEdit(0); if (edit == null) { edit = new WALEdit(); miniBatchOp.setWalEdit(0, edit); miniBatchOp.addOperationsFromCP(0, localUpdates.toArray(new Mutation[localUpdates.size()]));
new MiniBatchOperationInProgress<>(operations, retCodeDetails, walEditsFromCoprocessors, 0, 5, 5); assertEquals(5, miniBatch.size()); assertTrue(Bytes.equals(Bytes.toBytes(0), miniBatch.getOperation(0).getFirst().getRow())); assertTrue(Bytes.equals(Bytes.toBytes(2), miniBatch.getOperation(2).getFirst().getRow())); assertTrue(Bytes.equals(Bytes.toBytes(4), miniBatch.getOperation(4).getFirst().getRow())); try { miniBatch.getOperation(5); fail("Should throw Exception while accessing out of range"); } catch (ArrayIndexOutOfBoundsException e) { miniBatch.setOperationStatus(1, OperationStatus.FAILURE); assertEquals(OperationStatus.FAILURE, retCodeDetails[1]); try { miniBatch.setOperationStatus(6, OperationStatus.FAILURE); fail("Should throw Exception while accessing out of range"); } catch (ArrayIndexOutOfBoundsException e) { miniBatch.setWalEdit(5, new WALEdit()); fail("Should throw Exception while accessing out of range"); } catch (ArrayIndexOutOfBoundsException e) { miniBatch = new MiniBatchOperationInProgress<>(operations, retCodeDetails, walEditsFromCoprocessors, 7, 10, 3); try { miniBatch.setWalEdit(-1, new WALEdit()); fail("Should throw Exception while accessing out of range"); } catch (ArrayIndexOutOfBoundsException e) {
for (int i = 0; i < miniBatchOp.size(); i++) { Mutation m = miniBatchOp.getOperation(i); CellVisibility cellVisibility = null; try { cellVisibility = m.getCellVisibility(); } catch (DeserializationException de) { miniBatchOp.setOperationStatus(i, new OperationStatus(SANITY_CHECK_FAILURE, de.getMessage())); continue; miniBatchOp.setOperationStatus(i, new OperationStatus(SANITY_CHECK_FAILURE, "Mutation contains cell with reserved type tag")); sanityFailure = true; authCheck); } catch (InvalidLabelException e) { miniBatchOp.setOperationStatus(i, new OperationStatus(SANITY_CHECK_FAILURE, e.getMessage()));
TableName table = c.getEnvironment().getRegion().getRegionInfo().getTable(); User user = getActiveUser(c); for (int i = 0; i < miniBatchOp.size(); i++) { Mutation m = miniBatchOp.getOperation(i); if (m.getAttribute(CHECK_COVERING_PERM) != null) {
@Override public Mutation next() { return miniBatchOp.getOperation(i++); }
new HashMap<ImmutableBytesPtr, MultiMutation>(); boolean durable = false; for (int i = 0; i < miniBatchOp.size(); i++) { WALEdit edit = miniBatchOp.getWalEdit(i); assert kv == BATCH_MARKER : "Expected batch marker from the WALEdit, but got: " + kv; Pair<Mutation, Integer> op = miniBatchOp.getOperation(i); Mutation m = op.getFirst(); WALEdit edit = miniBatchOp.getWalEdit(0);
List<Pair<NonceKey, WALEdit>> walEdits = new ArrayList<>(); visitBatchOperations(true, nextIndexToProcess + miniBatchOp.size(), new Visitor() { private Pair<NonceKey, WALEdit> curWALEditForNonce;
/** * @param index * @return Gets the walEdit for the operation(Mutation) at the specified position. */ public WALEdit getWalEdit(int index) { return this.walEditsFromCoprocessors[getAbsoluteIndex(index)]; }
@Override public Void answer(InvocationOnMock invocation) throws Throwable { MiniBatchOperationInProgress<Mutation> mb = invocation.getArgument(0); mb.addOperationsFromCP(0, new Mutation[]{addPut}); return null; } }).when(mockedCPHost).preBatchMutate(Mockito.isA(MiniBatchOperationInProgress.class));
Durability durability = Durability.SKIP_WAL; boolean copyMutations = false; for (int i = 0; i < miniBatchOp.size(); i++) { Mutation m = miniBatchOp.getOperation(i); if (this.builder.isAtomicOp(m)) { miniBatchOp.setOperationStatus(i, IGNORE); continue; Mutation firstMutation = miniBatchOp.getOperation(0); ReplayWrite replayWrite = this.builder.getReplayWrite(firstMutation); boolean resetTimeStamp = replayWrite == null; long now = EnvironmentEdgeManager.currentTimeMillis(); byte[] byteNow = Bytes.toBytes(now); for (int i = 0; i < miniBatchOp.size(); i++) { Mutation m = miniBatchOp.getOperation(i); if (miniBatchOp.getOperationStatus(i) != IGNORE && this.builder.isEnabled(m)) { if (resetTimeStamp) { miniBatchOp.setOperationStatus(i, NOWRITE); WALEdit edit = miniBatchOp.getWalEdit(0); if (edit == null) { edit = new WALEdit(); miniBatchOp.setWalEdit(0, edit); miniBatchOp.addOperationsFromCP(0, localUpdates.toArray(new Mutation[localUpdates.size()]));
new MiniBatchOperationInProgress<>(operations, retCodeDetails, walEditsFromCoprocessors, 0, 5, 5); assertEquals(5, miniBatch.size()); assertTrue(Bytes.equals(Bytes.toBytes(0), miniBatch.getOperation(0).getFirst().getRow())); assertTrue(Bytes.equals(Bytes.toBytes(2), miniBatch.getOperation(2).getFirst().getRow())); assertTrue(Bytes.equals(Bytes.toBytes(4), miniBatch.getOperation(4).getFirst().getRow())); try { miniBatch.getOperation(5); fail("Should throw Exception while accessing out of range"); } catch (ArrayIndexOutOfBoundsException e) { miniBatch.setOperationStatus(1, OperationStatus.FAILURE); assertEquals(OperationStatus.FAILURE, retCodeDetails[1]); try { miniBatch.setOperationStatus(6, OperationStatus.FAILURE); fail("Should throw Exception while accessing out of range"); } catch (ArrayIndexOutOfBoundsException e) { miniBatch.setWalEdit(5, new WALEdit()); fail("Should throw Exception while accessing out of range"); } catch (ArrayIndexOutOfBoundsException e) { miniBatch = new MiniBatchOperationInProgress<>(operations, retCodeDetails, walEditsFromCoprocessors, 7, 10, 3); try { miniBatch.setWalEdit(-1, new WALEdit()); fail("Should throw Exception while accessing out of range"); } catch (ArrayIndexOutOfBoundsException e) {
for (int i = 0; i < miniBatchOp.size(); i++) { Mutation m = miniBatchOp.getOperation(i); CellVisibility cellVisibility = null; try { cellVisibility = m.getCellVisibility(); } catch (DeserializationException de) { miniBatchOp.setOperationStatus(i, new OperationStatus(SANITY_CHECK_FAILURE, de.getMessage())); continue; miniBatchOp.setOperationStatus(i, new OperationStatus(SANITY_CHECK_FAILURE, "Mutation contains cell with reserved type tag")); sanityFailure = true; authCheck); } catch (InvalidLabelException e) { miniBatchOp.setOperationStatus(i, new OperationStatus(SANITY_CHECK_FAILURE, e.getMessage()));
List<KeyRange> keys = Lists.newArrayListWithExpectedSize(miniBatchOp.size()); List<IndexMaintainer> maintainers = new ArrayList<IndexMaintainer>(); for (int i = 0; i < miniBatchOp.size(); i++) { Mutation m = miniBatchOp.getOperation(i).getFirst(); keys.add(PDataType.VARBINARY.getKeyRange(m.getRow())); maintainers.addAll(getCodec().getIndexMaintainers(m.getAttributesMap()));
public PhoenixIndexMetaData getIndexMetaData(MiniBatchOperationInProgress<Mutation> miniBatchOp) throws IOException { IndexMetaDataCache indexMetaDataCache = getIndexMetaDataCache(env, miniBatchOp.getOperation(0).getAttributesMap()); return new PhoenixIndexMetaData(indexMetaDataCache, miniBatchOp.getOperation(0).getAttributesMap()); }
@Override public boolean hasNext() { return i < miniBatchOp.size(); }
/** * Sets the status code for the operation(Mutation) at the specified position. * By setting this status, {@link org.apache.hadoop.hbase.coprocessor.RegionObserver} * can make HRegion to skip Mutations. * @param index * @param opStatus */ public void setOperationStatus(int index, OperationStatus opStatus) { this.retCodeDetails[getAbsoluteIndex(index)] = opStatus; }