@Override public void preGetOp(ObserverContext<RegionCoprocessorEnvironment> c, Get get, List<Cell> result) throws IOException { c.bypass(); }
@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(); } }
@Override public void preCompactSelection(ObserverContext<RegionCoprocessorEnvironment> c, Store store, List<? extends StoreFile> candidates, CompactionLifeCycleTracker tracker) throws IOException { int count = candidates.size(); if (count >= 2) { for (int i = 0; i < count - 2; i++) { candidates.remove(0); } c.bypass(); } } }
@Override public void prePut(final ObserverContext<RegionCoprocessorEnvironment> e, final Put put, final WALEdit edit, final Durability durability) throws IOException { PREPUT_INVOCATIONS.incrementAndGet(); Map<byte[], List<Cell>> familyMap = put.getFamilyCellMap(); if (familyMap.containsKey(test)) { PREPUT_BYPASSES.incrementAndGet(); e.bypass(); } } }
@Override public void preWALRestore(ObserverContext<? extends RegionCoprocessorEnvironment> env, RegionInfo info, WALKey logKey, WALEdit logEdit) throws IOException { String tableName = logKey.getTableName().getNameAsString(); if (tableName.equals(TABLE_SKIPPED)) { // skip recovery of TABLE_SKIPPED for testing purpose env.bypass(); return; } ctPreWALRestore.incrementAndGet(); }
@Override public void preGetOp(final ObserverContext<RegionCoprocessorEnvironment> c, final Get get, final List<Cell> result) throws IOException { if (get.getAttribute("count") != null) { result.clear(); // order is important! result.add(new KeyValue(count, count, delete, Bytes.toBytes(nDelete))); result.add(new KeyValue(count, count, put, Bytes.toBytes(nCount))); c.bypass(); } } }
ctx.bypass();
@Override public void prePut(final ObserverContext<RegionCoprocessorEnvironment> c, final Put put, final WALEdit edit, final Durability durability) throws IOException { if (put.getAttribute("ttl") != null) { Cell cell = put.getFamilyCellMap().values().stream().findFirst().get().get(0); ttls.put( TableName.valueOf(Bytes.toString(cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength())), Bytes.toLong(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength())); c.bypass(); } else if (put.getAttribute("versions") != null) { Cell cell = put.getFamilyCellMap().values().stream().findFirst().get().get(0); versions.put( TableName.valueOf(Bytes.toString(cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength())), Bytes.toInt(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength())); c.bypass(); } }
@Override public Result preIncrement(ObserverContext<RegionCoprocessorEnvironment> c, Increment increment) throws IOException { byte[] row = increment.getRow(); Put put = new Put(row); long ts = getUniqueTimestamp(row); for (Map.Entry<byte[], List<Cell>> entry : increment.getFamilyCellMap().entrySet()) { for (Cell cell : entry.getValue()) { put.add(CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY).setRow(row) .setFamily(cell.getFamilyArray(), cell.getFamilyOffset(), cell.getFamilyLength()) .setQualifier(cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength()) .setValue(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength()) .setType(Cell.Type.Put).setTimestamp(ts).build()); } } c.getEnvironment().getRegion().put(put); c.bypass(); return Result.EMPTY_RESULT; }
@Override public void prePut(ObserverContext<RegionCoprocessorEnvironment> e, Put put, WALEdit edit, Durability durability) throws IOException { Region region = e.getEnvironment().getRegion(); if (!region.getRegionInfo().isMetaRegion() && !region.getRegionInfo().getTable().isSystemTable()) { if (put.getAttribute(TEST_ATR_KEY) != null) { LOG.debug("allow any put to happen " + region.getRegionInfo().getRegionNameAsString()); } else { e.bypass(); } } } }
@Override public void preGetOp(ObserverContext<RegionCoprocessorEnvironment> e, Get get, List<Cell> results) throws IOException { LOG.debug("Got preGet for row: " + Bytes.toStringBinary(get.getRow())); // vv RegionObserverWithBypassExample if (Bytes.equals(get.getRow(), FIXED_ROW)) { long time = System.currentTimeMillis(); Cell cell = CellUtil.createCell(get.getRow(), FIXED_ROW, FIXED_ROW, // co RegionObserverWithBypassExample-1-Cell Create cell directly using the supplied utility. time, KeyValue.Type.Put.getCode(), Bytes.toBytes(time)); // ^^ RegionObserverWithBypassExample LOG.debug("Had a match, adding fake cell: " + cell); // vv RegionObserverWithBypassExample results.add(cell); /*[*/e.bypass();/*]*/ // co RegionObserverWithBypassExample-2-Bypass Once the special cell is inserted all subsequent coprocessors are skipped. } // ^^ RegionObserverWithBypassExample } }
e.bypass(); e.complete(); HRegion region = env.getRegion();
e.bypass(); Region region = env.getRegion(); byte[] row = append.getRow();
@Override public void preGetOp(ObserverContext<RegionCoprocessorEnvironment> c, Get get, List<Cell> result) throws IOException { c.bypass(); }
RegionCoprocessorEnvironment env = e.getEnvironment(); e.bypass(); e.complete(); HRegion region = env.getRegion();
RegionCoprocessorEnvironment env = e.getEnvironment(); e.bypass(); Region region = env.getRegion(); byte[] row = increment.getRow();
@Override public void prePut(final ObserverContext<RegionCoprocessorEnvironment> e, final Put put, final WALEdit edit, final Durability durability) throws IOException { PREPUT_INVOCATIONS.incrementAndGet(); Map<byte[], List<Cell>> familyMap = put.getFamilyCellMap(); if (familyMap.containsKey(test)) { PREPUT_BYPASSES.incrementAndGet(); e.bypass(); } } }
@Override public void preGetOp(final ObserverContext<RegionCoprocessorEnvironment> c, final Get get, final List<Cell> result) throws IOException { if (get.getAttribute("count") != null) { result.clear(); // order is important! result.add(new KeyValue(count, count, delete, Bytes.toBytes(nDelete))); result.add(new KeyValue(count, count, put, Bytes.toBytes(nCount))); c.bypass(); } } }