Java Code Examples for org.apache.hadoop.hbase.regionserver.MiniBatchOperationInProgress#addOperationsFromCP()
The following examples show how to use
org.apache.hadoop.hbase.regionserver.MiniBatchOperationInProgress#addOperationsFromCP() .
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: TestRegionObserverForAddingMutationsFromCoprocessors.java From hbase with Apache License 2.0 | 6 votes |
@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).addColumns(test, dummy, cells.get(0).getTimestamp()), new Delete(row2).addColumns(test, dummy, cells.get(0).getTimestamp()), }; LOG.info("Deleting:" + Arrays.toString(deletes)); miniBatchOp.addOperationsFromCP(0, deletes); } }
Example 2
Source File: TestRegionObserverForAddingMutationsFromCoprocessors.java From hbase with Apache License 2.0 | 6 votes |
@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).addFamily(test, cells.get(0).getTimestamp()), new Delete(row2).addFamily(test, cells.get(0).getTimestamp()), }; LOG.info("Deleting:" + Arrays.toString(deletes)); miniBatchOp.addOperationsFromCP(0, deletes); } }
Example 3
Source File: TestRegionObserverForAddingMutationsFromCoprocessors.java From hbase with Apache License 2.0 | 6 votes |
@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); } }
Example 4
Source File: IndexRegionObserver.java From phoenix with Apache License 2.0 | 6 votes |
/** * The index update generation for local indexes uses the existing index update generation code (i.e., * the {@link IndexBuilder} implementation). */ private void handleLocalIndexUpdates(ObserverContext<RegionCoprocessorEnvironment> c, MiniBatchOperationInProgress<Mutation> miniBatchOp, Collection<? extends Mutation> pendingMutations, PhoenixIndexMetaData indexMetaData) throws Throwable { ListMultimap<HTableInterfaceReference, Pair<Mutation, byte[]>> indexUpdates = ArrayListMultimap.<HTableInterfaceReference, Pair<Mutation, byte[]>>create(); this.builder.getIndexUpdates(indexUpdates, miniBatchOp, pendingMutations, indexMetaData); byte[] tableName = c.getEnvironment().getRegion().getTableDescriptor().getTableName().getName(); HTableInterfaceReference hTableInterfaceReference = new HTableInterfaceReference(new ImmutableBytesPtr(tableName)); List<Pair<Mutation, byte[]>> localIndexUpdates = indexUpdates.removeAll(hTableInterfaceReference); if (localIndexUpdates == null || localIndexUpdates.isEmpty()) { return; } List<Mutation> localUpdates = new ArrayList<Mutation>(); Iterator<Pair<Mutation, byte[]>> indexUpdatesItr = localIndexUpdates.iterator(); while (indexUpdatesItr.hasNext()) { Pair<Mutation, byte[]> next = indexUpdatesItr.next(); localUpdates.add(next.getFirst()); } if (!localUpdates.isEmpty()) { miniBatchOp.addOperationsFromCP(0, localUpdates.toArray(new Mutation[localUpdates.size()])); } }
Example 5
Source File: TestRegionObserverForAddingMutationsFromCoprocessors.java From hbase with Apache License 2.0 | 5 votes |
@Override public void preBatchMutate(ObserverContext<RegionCoprocessorEnvironment> c, MiniBatchOperationInProgress<Mutation> miniBatchOp) throws IOException { Mutation mut = miniBatchOp.getOperation(0); List<Cell> cells = mut.getFamilyCellMap().get(test); Put[] puts = new Put[] { new Put(Bytes.toBytes("cpPut")).addColumn(test, dummy, cells.get(0).getTimestamp(), Bytes.toBytes("cpdummy")).setTTL(mut.getTTL()) }; LOG.info("Putting:" + Arrays.toString(puts)); miniBatchOp.addOperationsFromCP(0, puts); }
Example 6
Source File: TestRegionObserverForAddingMutationsFromCoprocessors.java From hbase with Apache License 2.0 | 5 votes |
@Override public void preBatchMutate(ObserverContext<RegionCoprocessorEnvironment> c, MiniBatchOperationInProgress<Mutation> miniBatchOp) throws IOException { Mutation mut = miniBatchOp.getOperation(0); List<Cell> cells = mut.getFamilyCellMap().get(test); Put[] puts = new Put[] { new Put(row1).addColumn(test, dummy, cells.get(0).getTimestamp(), Bytes.toBytes("cpdummy")), new Put(row2).addColumn(test, dummy, cells.get(0).getTimestamp(), dummy), new Put(row3).addColumn(test, dummy, cells.get(0).getTimestamp(), dummy), }; LOG.info("Putting:" + Arrays.toString(puts)); miniBatchOp.addOperationsFromCP(0, puts); }
Example 7
Source File: PhoenixTransactionalIndexer.java From phoenix with Apache License 2.0 | 4 votes |
@Override public void preBatchMutate(ObserverContext<RegionCoprocessorEnvironment> c, MiniBatchOperationInProgress<Mutation> miniBatchOp) throws IOException { Mutation m = miniBatchOp.getOperation(0); if (!codec.isEnabled(m)) { return; } PhoenixIndexMetaData indexMetaData = new PhoenixIndexMetaDataBuilder(c.getEnvironment()).getIndexMetaData(miniBatchOp); if ( indexMetaData.getClientVersion() >= MetaDataProtocol.MIN_TX_CLIENT_SIDE_MAINTENANCE && !indexMetaData.hasLocalIndexes()) { // Still generate index updates server side for local indexes return; } BatchMutateContext context = new BatchMutateContext(indexMetaData.getClientVersion()); setBatchMutateContext(c, context); Collection<Pair<Mutation, byte[]>> indexUpdates = null; // get the current span, or just use a null-span to avoid a bunch of if statements try (TraceScope scope = Trace.startSpan("Starting to build index updates")) { Span current = scope.getSpan(); if (current == null) { current = NullSpan.INSTANCE; } RegionCoprocessorEnvironment env = c.getEnvironment(); PhoenixTransactionContext txnContext = indexMetaData.getTransactionContext(); if (txnContext == null) { throw new NullPointerException("Expected to find transaction in metadata for " + env.getRegionInfo().getTable().getNameAsString()); } PhoenixTxIndexMutationGenerator generator = new PhoenixTxIndexMutationGenerator(env.getConfiguration(), indexMetaData, env.getRegionInfo().getTable().getName(), env.getRegionInfo().getStartKey(), env.getRegionInfo().getEndKey()); try (Table htable = env.getConnection().getTable(env.getRegionInfo().getTable())) { // get the index updates for all elements in this batch indexUpdates = generator.getIndexUpdates(htable, getMutationIterator(miniBatchOp)); } byte[] tableName = c.getEnvironment().getRegionInfo().getTable().getName(); Iterator<Pair<Mutation, byte[]>> indexUpdatesItr = indexUpdates.iterator(); List<Mutation> localUpdates = new ArrayList<Mutation>(indexUpdates.size()); while(indexUpdatesItr.hasNext()) { Pair<Mutation, byte[]> next = indexUpdatesItr.next(); if (Bytes.compareTo(next.getSecond(), tableName) == 0) { // These mutations will not go through the preDelete hooks, so we // must manually convert them here. Mutation mutation = TransactionUtil.convertIfDelete(next.getFirst()); localUpdates.add(mutation); indexUpdatesItr.remove(); } } if (!localUpdates.isEmpty()) { miniBatchOp.addOperationsFromCP(0, localUpdates.toArray(new Mutation[localUpdates.size()])); } if (!indexUpdates.isEmpty()) { context.indexUpdates = indexUpdates; } current.addTimelineAnnotation("Built index updates, doing preStep"); TracingUtils.addAnnotation(current, "index update count", context.indexUpdates.size()); } catch (Throwable t) { String msg = "Failed to update index with entries:" + indexUpdates; LOGGER.error(msg, t); ServerUtil.throwIOException(msg, t); } }