org.apache.hadoop.hbase.regionserver.MiniBatchOperationInProgress Java Examples

The following examples show how to use org.apache.hadoop.hbase.regionserver.MiniBatchOperationInProgress. 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 vote down vote up
@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 #2
Source File: IndexRegionObserver.java    From phoenix with Apache License 2.0 6 votes vote down vote up
@Override
public void postBatchMutateIndispensably(ObserverContext<RegionCoprocessorEnvironment> c,
    MiniBatchOperationInProgress<Mutation> miniBatchOp, final boolean success) throws IOException {
    if (this.disabled) {
        return;
    }
    BatchMutateContext context = getBatchMutateContext(c);
    if (context == null) {
        return;
    }
    try {
        for (RowLock rowLock : context.rowLocks) {
            rowLock.release();
        }
        this.builder.batchCompleted(miniBatchOp);

        if (success) { // The pre-index and data table updates are successful, and now, do post index updates
            doPost(c, context);
        }
     } finally {
         removeBatchMutateContext(c);
     }
}
 
Example #3
Source File: Indexer.java    From phoenix with Apache License 2.0 6 votes vote down vote up
@Override
public void preBatchMutate(ObserverContext<RegionCoprocessorEnvironment> c,
    MiniBatchOperationInProgress<Mutation> miniBatchOp) throws IOException {
    if (this.disabled) {
        return;
    }
    long start = EnvironmentEdgeManager.currentTimeMillis();
    try {
        preBatchMutateWithExceptions(c, miniBatchOp);
        return;
    } catch (Throwable t) {
        rethrowIndexingException(t);
    } finally {
        long duration = EnvironmentEdgeManager.currentTimeMillis() - start;
        if (duration >= slowIndexPrepareThreshold) {
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug(getCallTooSlowMessage("preBatchMutate",
                        duration, slowIndexPrepareThreshold));
            }
            metricSource.incrementNumSlowIndexPrepareCalls();
        }
        metricSource.updateIndexPrepareTime(duration);
    }
    throw new RuntimeException(
      "Somehow didn't return an index update but also didn't propagate the failure to the client!");
}
 
Example #4
Source File: IndexRegionObserver.java    From phoenix with Apache License 2.0 6 votes vote down vote up
/**
 * 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: IndexBuildManager.java    From phoenix with Apache License 2.0 6 votes vote down vote up
public void getIndexUpdates(ListMultimap<HTableInterfaceReference, Pair<Mutation, byte[]>> indexUpdates,
    MiniBatchOperationInProgress<Mutation> miniBatchOp,
    Collection<? extends Mutation> mutations,
    IndexMetaData indexMetaData) throws Throwable {
  // notify the delegate that we have started processing a batch
  this.delegate.batchStarted(miniBatchOp, indexMetaData);
  CachedLocalTable cachedLocalTable =
          CachedLocalTable.build(
                  mutations,
                  (PhoenixIndexMetaData)indexMetaData,
                  this.regionCoprocessorEnvironment.getRegion());
  // Avoid the Object overhead of the executor when it's not actually parallelizing anything.
  for (Mutation m : mutations) {
    Collection<Pair<Mutation, byte[]>> updates = delegate.getIndexUpdate(m, indexMetaData, cachedLocalTable);
    for (Pair<Mutation, byte[]> update : updates) {
      indexUpdates.put(new HTableInterfaceReference(new ImmutableBytesPtr(update.getSecond())), new Pair<>(update.getFirst(), m.getRow()));
    }
  }
}
 
Example #6
Source File: IndexBuildManager.java    From phoenix with Apache License 2.0 6 votes vote down vote up
public Collection<Pair<Mutation, byte[]>> getIndexUpdate(
        MiniBatchOperationInProgress<Mutation> miniBatchOp,
        Collection<? extends Mutation> mutations) throws Throwable {
  // notify the delegate that we have started processing a batch
  final IndexMetaData indexMetaData = this.delegate.getIndexMetaData(miniBatchOp);
  this.delegate.batchStarted(miniBatchOp, indexMetaData);

  CachedLocalTable cachedLocalTable =
          CachedLocalTable.build(
                  mutations,
                  (PhoenixIndexMetaData)indexMetaData,
                  this.regionCoprocessorEnvironment.getRegion());
  // Avoid the Object overhead of the executor when it's not actually parallelizing anything.
  ArrayList<Pair<Mutation, byte[]>> results = new ArrayList<>(mutations.size());
  for (Mutation m : mutations) {
    Collection<Pair<Mutation, byte[]>> updates = delegate.getIndexUpdate(m, indexMetaData, cachedLocalTable);
    if (PhoenixIndexMetaData.isIndexRebuild(m.getAttributesMap())) {
      for (Pair<Mutation, byte[]> update : updates) {
        update.getFirst().setAttribute(BaseScannerRegionObserver.REPLAY_WRITES,
                BaseScannerRegionObserver.REPLAY_INDEX_REBUILD_WRITES);
      }
    }
    results.addAll(updates);
  }
  return results;
}
 
Example #7
Source File: PhoenixTransactionalIndexer.java    From phoenix with Apache License 2.0 6 votes vote down vote up
private static Iterator<Mutation> getMutationIterator(final MiniBatchOperationInProgress<Mutation> miniBatchOp) {
    return new Iterator<Mutation>() {
        private int i = 0;
        
        @Override
        public boolean hasNext() {
            return i < miniBatchOp.size();
        }

        @Override
        public Mutation next() {
            return miniBatchOp.getOperation(i++);
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException();
        }
        
    };
}
 
Example #8
Source File: TestRegionObserverForAddingMutationsFromCoprocessors.java    From hbase with Apache License 2.0 6 votes vote down vote up
@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 #9
Source File: TestRegionObserverForAddingMutationsFromCoprocessors.java    From hbase with Apache License 2.0 6 votes vote down vote up
@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 #10
Source File: IndexRegionObserver.java    From phoenix with Apache License 2.0 6 votes vote down vote up
private Collection<? extends Mutation> groupMutations(MiniBatchOperationInProgress<Mutation> miniBatchOp,
                                                      BatchMutateContext context) throws IOException {
    context.multiMutationMap = new HashMap<>();
    for (int i = 0; i < miniBatchOp.size(); i++) {
        Mutation m = miniBatchOp.getOperation(i);
        // skip this mutation if we aren't enabling indexing
        // unfortunately, we really should ask if the raw mutation (rather than the combined mutation)
        // should be indexed, which means we need to expose another method on the builder. Such is the
        // way optimization go though.
        if (miniBatchOp.getOperationStatus(i) != IGNORE && this.builder.isEnabled(m)) {
            ImmutableBytesPtr row = new ImmutableBytesPtr(m.getRow());
            MultiMutation stored = context.multiMutationMap.get(row);
            if (stored == null) {
                // we haven't seen this row before, so add it
                stored = new MultiMutation(row);
                context.multiMutationMap.put(row, stored);
            }
            stored.addAll(m);
        }
    }
    return context.multiMutationMap.values();
}
 
Example #11
Source File: ConcurrentMutationsExtendedIT.java    From phoenix with Apache License 2.0 6 votes vote down vote up
@Override public void preBatchMutate(ObserverContext<RegionCoprocessorEnvironment> c,
        MiniBatchOperationInProgress<Mutation> miniBatchOp) throws HBaseIOException {
    try {
        String tableName = c.getEnvironment().getRegionInfo().getTable().getNameAsString();
        if (tableName.startsWith(LOCK_TEST_TABLE_PREFIX)) {
            if (lockedTableRow) {
                throw new DoNotRetryIOException(
                        "Expected lock in preBatchMutate to be exclusive, but it wasn't for row "
                                + Bytes
                                .toStringBinary(miniBatchOp.getOperation(0).getRow()));
            }
            lockedTableRow = true;
            Thread.sleep(ROW_LOCK_WAIT_TIME + 2000);
        }
        Thread.sleep(Math.abs(RAND.nextInt()) % 10);
    } catch (InterruptedException e) {
    } finally {
        lockedTableRow = false;
    }

}
 
Example #12
Source File: Indexer.java    From phoenix with Apache License 2.0 6 votes vote down vote up
@Override
public void preBatchMutate(ObserverContext<RegionCoprocessorEnvironment> c,
    MiniBatchOperationInProgress<Mutation> miniBatchOp) throws IOException {
    if (this.disabled) {
        super.preBatchMutate(c, miniBatchOp);
        return;
    }
    try {
        preBatchMutateWithExceptions(c, miniBatchOp);
        return;
    } catch (Throwable t) {
        rethrowIndexingException(t);
    }
    throw new RuntimeException(
      "Somehow didn't return an index update but also didn't propagate the failure to the client!");
}
 
Example #13
Source File: PhoenixIndexBuilder.java    From phoenix with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void batchStarted(MiniBatchOperationInProgress<Pair<Mutation, Integer>> miniBatchOp) throws IOException {
    // The entire purpose of this method impl is to get the existing rows for the
    // table rows being indexed into the block cache, as the index maintenance code
    // does a point scan per row
    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()));
    }
    Scan scan = IndexManagementUtil.newLocalStateScan(maintainers);
    ScanRanges scanRanges = ScanRanges.create(Collections.singletonList(keys), SchemaUtil.VAR_BINARY_SCHEMA);
    scanRanges.setScanStartStopRow(scan);
    scan.setFilter(scanRanges.getSkipScanFilter());
    HRegion region = this.env.getRegion();
    RegionScanner scanner = region.getScanner(scan);
    // Run through the scanner using internal nextRaw method
    MultiVersionConsistencyControl.setThreadReadPoint(scanner.getMvccReadPoint());
    region.startRegionOperation();
    try {
        boolean hasMore;
        do {
            List<KeyValue> results = Lists.newArrayList();
            // Results are potentially returned even when the return value of s.next is false
            // since this is an indication of whether or not there are more values after the
            // ones returned
            hasMore = scanner.nextRaw(results, null);
        } while (hasMore);
    } finally {
        try {
            scanner.close();
        } finally {
            region.closeRegionOperation();
        }
    }
}
 
Example #14
Source File: IndexRegionObserver.java    From phoenix with Apache License 2.0 5 votes vote down vote up
/**
 * This method applies the pending put mutations on the the next row states.
 * Before this method is called, the next row states is set to current row states.
 */
private void applyPendingPutMutations(MiniBatchOperationInProgress<Mutation> miniBatchOp,
                                      BatchMutateContext context, long now) throws IOException {
    for (Integer i = 0; i < miniBatchOp.size(); i++) {
        if (miniBatchOp.getOperationStatus(i) == IGNORE) {
            continue;
        }
        Mutation m = miniBatchOp.getOperation(i);
        // skip this mutation if we aren't enabling indexing
        if (!this.builder.isEnabled(m)) {
            continue;
        }
        // Unless we're replaying edits to rebuild the index, we update the time stamp
        // of the data table to prevent overlapping time stamps (which prevents index
        // inconsistencies as this case isn't handled correctly currently).
        setTimestamp(m, now);
        if (m instanceof Put) {
            ImmutableBytesPtr rowKeyPtr = new ImmutableBytesPtr(m.getRow());
            Pair<Put, Put> dataRowState = context.dataRowStates.get(rowKeyPtr);
            if (dataRowState == null) {
                dataRowState = new Pair<Put, Put>(null, null);
                context.dataRowStates.put(rowKeyPtr, dataRowState);
            }
            Put nextDataRowState = dataRowState.getSecond();
            dataRowState.setSecond((nextDataRowState != null) ? applyNew((Put) m, nextDataRowState) : new Put((Put) m));
        }
    }
}
 
Example #15
Source File: IndexRegionObserver.java    From phoenix with Apache License 2.0 5 votes vote down vote up
/**
 * * Prepares data row current and next row states
 */
private void prepareDataRowStates(ObserverContext<RegionCoprocessorEnvironment> c,
                                  MiniBatchOperationInProgress<Mutation> miniBatchOp,
                                  BatchMutateContext context,
                                  long now) throws IOException {
    if (context.rowsToLock.size() == 0) {
        return;
    }
    // Retrieve the current row states from the data table
    getCurrentRowStates(c, context);
    applyPendingPutMutations(miniBatchOp, context, now);
    applyPendingDeleteMutations(miniBatchOp, context);
}
 
Example #16
Source File: TestFromClientSide3.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public void postBatchMutate(final ObserverContext<RegionCoprocessorEnvironment> c,
        final MiniBatchOperationInProgress<Mutation> miniBatchOp) throws IOException {
  try {
    // waiting for scanner
    latch.await();
  } catch (InterruptedException ex) {
    throw new IOException(ex);
  }
}
 
Example #17
Source File: TestFromClientSide3.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public void postBatchMutate(final ObserverContext<RegionCoprocessorEnvironment> c,
        final MiniBatchOperationInProgress<Mutation> miniBatchOp) throws IOException {
  try {
    latch.await();
  } catch (InterruptedException ex) {
    throw new IOException(ex);
  }
}
 
Example #18
Source File: Indexer.java    From phoenix with Apache License 2.0 5 votes vote down vote up
@Override
public void postBatchMutate(ObserverContext<RegionCoprocessorEnvironment> c,
    MiniBatchOperationInProgress<Mutation> miniBatchOp) throws IOException {
    if (this.disabled) {
        super.postBatchMutate(c, miniBatchOp);
        return;
      }
  this.builder.batchCompleted(miniBatchOp);

  //each batch operation, only the first one will have anything useful, so we can just grab that
  Mutation mutation = miniBatchOp.getOperation(0);
  WALEdit edit = miniBatchOp.getWalEdit(0);
  doPost(edit, mutation, mutation.getDurability());
}
 
Example #19
Source File: IndexRegionObserver.java    From phoenix with Apache License 2.0 5 votes vote down vote up
protected PhoenixIndexMetaData getPhoenixIndexMetaData(ObserverContext<RegionCoprocessorEnvironment> observerContext,
                                                       MiniBatchOperationInProgress<Mutation> miniBatchOp)
        throws IOException {
    IndexMetaData indexMetaData = this.builder.getIndexMetaData(miniBatchOp);
    if (!(indexMetaData instanceof PhoenixIndexMetaData)) {
        throw new DoNotRetryIOException(
                "preBatchMutateWithExceptions: indexMetaData is not an instance of "+PhoenixIndexMetaData.class.getName() +
                        ", current table is:" +
                        observerContext.getEnvironment().getRegion().getRegionInfo().getTable().getNameAsString());
    }
    return (PhoenixIndexMetaData)indexMetaData;
}
 
Example #20
Source File: IndexRegionObserver.java    From phoenix with Apache License 2.0 5 votes vote down vote up
private void doPre(ObserverContext<RegionCoprocessorEnvironment> c, BatchMutateContext context,
                   MiniBatchOperationInProgress<Mutation> miniBatchOp) throws IOException {
    if (ignoreIndexRebuildForTesting && context.rebuild) {
        return;
    }
    long start = EnvironmentEdgeManager.currentTimeMillis();
    try {
        if (failPreIndexUpdatesForTesting) {
            throw new DoNotRetryIOException("Simulating the first (i.e., pre) index table write failure");
        }
        doIndexWritesWithExceptions(context, false);
        metricSource.updatePreIndexUpdateTime(EnvironmentEdgeManager.currentTimeMillis() - start);
        return;
    } catch (Throwable e) {
        metricSource.updatePreIndexUpdateFailureTime(EnvironmentEdgeManager.currentTimeMillis() - start);
        metricSource.incrementPreIndexUpdateFailures();
        // Remove all locks as they are already unlocked. There is no need to unlock them again later when
        // postBatchMutateIndispensably() is called
        removePendingRows(context);
        context.rowLocks.clear();
        if (context.rebuild) {
            throw new IOException(String.format("%s for rebuild", e.getMessage()), e);
        } else {
            rethrowIndexingException(e);
        }
    }
    throw new RuntimeException(
            "Somehow didn't complete the index update, but didn't return succesfully either!");
}
 
Example #21
Source File: Indexer.java    From phoenix with Apache License 2.0 5 votes vote down vote up
@Override
public void postBatchMutateIndispensably(ObserverContext<RegionCoprocessorEnvironment> c,
    MiniBatchOperationInProgress<Mutation> miniBatchOp, final boolean success) throws IOException {
    if (this.disabled) {
        return;
    }
    long start = EnvironmentEdgeManager.currentTimeMillis();
    BatchMutateContext context = getBatchMutateContext(c);
    if (context == null) {
        return;
    }
    try {
        for (RowLock rowLock : context.rowLocks) {
            rowLock.release();
        }
        this.builder.batchCompleted(miniBatchOp);

        if (success) { // if miniBatchOp was successfully written, write index updates
            doPost(c, context);
        }
     } finally {
         removeBatchMutateContext(c);
         long duration = EnvironmentEdgeManager.currentTimeMillis() - start;
         if (duration >= slowIndexWriteThreshold) {
             if (LOGGER.isDebugEnabled()) {
                 LOGGER.debug(getCallTooSlowMessage("postBatchMutateIndispensably",
                         duration, slowIndexWriteThreshold));
             }
             metricSource.incrementNumSlowIndexWriteCalls();
         }
         metricSource.updateIndexWriteTime(duration);
     }
}
 
Example #22
Source File: PhoenixTransactionalIndexer.java    From phoenix with Apache License 2.0 5 votes vote down vote up
@Override
public void postBatchMutateIndispensably(ObserverContext<RegionCoprocessorEnvironment> c,
    MiniBatchOperationInProgress<Mutation> miniBatchOp, final boolean success) throws IOException {
    BatchMutateContext context = getBatchMutateContext(c);
    if (context == null || context.indexUpdates == null) {
        return;
    }
    // get the current span, or just use a null-span to avoid a bunch of if statements
    try (TraceScope scope = Trace.startSpan("Starting to write index updates")) {
        Span current = scope.getSpan();
        if (current == null) {
            current = NullSpan.INSTANCE;
        }

        if (success) { // if miniBatchOp was successfully written, write index updates
            if (!context.indexUpdates.isEmpty()) {
                this.writer.write(context.indexUpdates, false, context.clientVersion);
            }
            current.addTimelineAnnotation("Wrote index updates");
        }
    } catch (Throwable t) {
        String msg = "Failed to write index updates:" + context.indexUpdates;
        LOGGER.error(msg, t);
        ServerUtil.throwIOException(msg, t);
     } finally {
         removeBatchMutateContext(c);
     }
}
 
Example #23
Source File: ScanRegionObserver.java    From phoenix with Apache License 2.0 5 votes vote down vote up
@Override
public void preBatchMutate(ObserverContext<RegionCoprocessorEnvironment> c,
        MiniBatchOperationInProgress<Mutation> miniBatchOp) throws IOException {
    try {
        preBatchMutateWithExceptions(miniBatchOp, c.getEnvironment().getRegion()
                .getTableDescriptor().getTableName().getNameAsString());
    } catch(Throwable t) {
        // Wrap all exceptions in an IOException to prevent region server crashes
        throw ServerUtil.createIOException("Unable to Put cells corresponding to dynamic" +
                "column metadata for " +
                c.getEnvironment().getRegion().getRegionInfo().getTable().getNameAsString(), t);
    }
}
 
Example #24
Source File: WALRecoveryRegionPostOpenIT.java    From phoenix with Apache License 2.0 5 votes vote down vote up
@Override
public void preBatchMutate(ObserverContext<RegionCoprocessorEnvironment> observerContext, MiniBatchOperationInProgress<Mutation> miniBatchOp) throws IOException {

    if (observerContext.getEnvironment().getRegion().getRegionInfo().getTable().getNameAsString().contains(INDEX_TABLE_NAME) && failIndexTableWrite) {
        throw new DoNotRetryIOException();
    }
    Mutation operation = miniBatchOp.getOperation(0);
    Set<byte[]> keySet = operation.getFamilyCellMap().keySet();
    for(byte[] family: keySet) {
        if(Bytes.toString(family).startsWith(QueryConstants.LOCAL_INDEX_COLUMN_FAMILY_PREFIX) && failIndexTableWrite) {
            throw new DoNotRetryIOException();
        }
    }
    super.preBatchMutate(observerContext, miniBatchOp);
}
 
Example #25
Source File: ImmutableIndexExtendedIT.java    From phoenix with Apache License 2.0 5 votes vote down vote up
@Override
public void preBatchMutate(ObserverContext<RegionCoprocessorEnvironment> c,
        MiniBatchOperationInProgress<Mutation> miniBatchOp) throws IOException {
    if (failOnce) {
        // next attempt don't raise
        failOnce = false;
        throw new IOException();
    }
}
 
Example #26
Source File: PartialIndexRebuilderIT.java    From phoenix with Apache License 2.0 5 votes vote down vote up
@Override
public void postBatchMutate(ObserverContext<RegionCoprocessorEnvironment> c, MiniBatchOperationInProgress<Mutation> miniBatchOp) throws IOException {
    // we need to advance the clock, since the index retry logic (copied from HBase) has a time component
    EnvironmentEdge delegate = EnvironmentEdgeManager.getDelegate();
    if (delegate instanceof MyClock) {
        MyClock myClock = (MyClock) delegate;
        myClock.time += 1000;
    }
    throw new DoNotRetryIOException("Simulating write failure on " + c.getEnvironment().getRegionInfo().getTable().getNameAsString());
}
 
Example #27
Source File: MutableIndexFailureIT.java    From phoenix with Apache License 2.0 5 votes vote down vote up
@Override
public void preBatchMutate(ObserverContext<RegionCoprocessorEnvironment> c, MiniBatchOperationInProgress<Mutation> miniBatchOp) throws IOException {
    boolean throwException = false;
    if (FAIL_NEXT_WRITE) {
        throwException = true;
        FAIL_NEXT_WRITE = false;
    } else if (c.getEnvironment().getRegionInfo().getTable().getNameAsString().endsWith("A_" + FAIL_INDEX_NAME)
            && FAIL_WRITE) {
        throwException = true;
        if (TOGGLE_FAIL_WRITE_FOR_RETRY) {
            FAIL_WRITE = !FAIL_WRITE;
        }
    } else {
        // When local index updates are atomic with data updates, testing a write failure to a local
        // index won't make sense.
        Mutation operation = miniBatchOp.getOperation(0);
        if (FAIL_WRITE) {
            Map<byte[],List<Cell>>cellMap = operation.getFamilyCellMap();
            for (Map.Entry<byte[],List<Cell>> entry : cellMap.entrySet()) {
                byte[] family = entry.getKey();
                if (Bytes.toString(family).startsWith(QueryConstants.LOCAL_INDEX_COLUMN_FAMILY_PREFIX)) {
                    int regionStartKeyLen = c.getEnvironment().getRegionInfo().getStartKey().length;
                    Cell firstCell = entry.getValue().get(0);
                    long indexId = MetaDataUtil.getViewIndexIdDataType().getCodec().decodeLong(firstCell.getRowArray(), firstCell.getRowOffset() + regionStartKeyLen, SortOrder.getDefault());
                    // Only throw for first local index as the test may have multiple local indexes
                    if (indexId == Short.MIN_VALUE) {
                        throwException = true;
                        break;
                    }
                }
            }
        }
    }
    if (throwException) {
        if (!TOGGLE_FAIL_WRITE_FOR_RETRY) {
            dropIndex(c);
        }
        throw new DoNotRetryIOException();
    }
}
 
Example #28
Source File: ConcurrentMutationsExtendedIT.java    From phoenix with Apache License 2.0 5 votes vote down vote up
@Override public void postBatchMutate(ObserverContext<RegionCoprocessorEnvironment> c,
        MiniBatchOperationInProgress<Mutation> miniBatchOp) throws IOException {
    try {
        String tableName = c.getEnvironment().getRegionInfo().getTable().getNameAsString();
        if (tableName.startsWith(MVCC_LOCK_TEST_TABLE_PREFIX)) {
            Thread.sleep(ROW_LOCK_WAIT_TIME
                    / 2); // Wait long enough that they'll both have the same mvcc
        }
    } catch (InterruptedException e) {
    }
}
 
Example #29
Source File: UpsertSelectOverlappingBatchesIT.java    From phoenix with Apache License 2.0 5 votes vote down vote up
@Override
    public void preBatchMutate(ObserverContext<RegionCoprocessorEnvironment> c, MiniBatchOperationInProgress<Mutation> miniBatchOp) throws HBaseIOException {
    	// model a slow batch that takes a long time
        if ((miniBatchOp.size()==100 || SLOW_MUTATE) && c.getEnvironment().getRegionInfo().getTable().getNameAsString().equals(dataTable)) {
        	try {
	Thread.sleep(6000);
} catch (InterruptedException e) {
	e.printStackTrace();
}
        }
    }
 
Example #30
Source File: Indexer.java    From phoenix with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void postBatchMutate(ObserverContext<RegionCoprocessorEnvironment> c,
    MiniBatchOperationInProgress<Pair<Mutation, Integer>> miniBatchOp) throws IOException {
    if (this.disabled) {
        super.postBatchMutate(c, miniBatchOp);
        return;
      }
  this.builder.batchCompleted(miniBatchOp);
  // noop for the rest of the indexer - its handled by the first call to put/delete
}