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

The following examples show how to use org.apache.hadoop.hbase.regionserver.MiniBatchOperationInProgress. These examples are extracted from open source projects. 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 Project: phoenix   Source File: Indexer.java    License: 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 2
@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 3
@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 4
@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 5
Source Project: phoenix   Source File: IndexRegionObserver.java    License: 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 6
Source Project: phoenix   Source File: IndexRegionObserver.java    License: 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 7
Source Project: phoenix   Source File: IndexRegionObserver.java    License: 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 8
Source Project: phoenix   Source File: Indexer.java    License: 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 9
Source Project: phoenix   Source File: IndexBuildManager.java    License: 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 10
Source Project: phoenix   Source File: IndexBuildManager.java    License: 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 11
Source Project: phoenix   Source File: PhoenixTransactionalIndexer.java    License: 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 12
Source Project: phoenix   Source File: ConcurrentMutationsExtendedIT.java    License: 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 13
Source Project: phoenix   Source File: Indexer.java    License: 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 14
@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 15
Source Project: hbase   Source File: AccessController.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void preBatchMutate(ObserverContext<RegionCoprocessorEnvironment> c,
    MiniBatchOperationInProgress<Mutation> miniBatchOp) throws IOException {
  if (cellFeaturesEnabled && !compatibleEarlyTermination) {
    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) {
        // We have a failure with table, cf and q perm checks and now giving a chance for cell
        // perm check
        OpType opType;
        if (m instanceof Put) {
          checkForReservedTagPresence(user, m);
          opType = OpType.PUT;
        } else {
          opType = OpType.DELETE;
        }
        AuthResult authResult = null;
        if (checkCoveringPermission(user, opType, c.getEnvironment(), m.getRow(),
          m.getFamilyCellMap(), m.getTimestamp(), Action.WRITE)) {
          authResult = AuthResult.allow(opType.toString(), "Covering cell set",
            user, Action.WRITE, table, m.getFamilyCellMap());
        } else {
          authResult = AuthResult.deny(opType.toString(), "Covering cell set",
            user, Action.WRITE, table, m.getFamilyCellMap());
        }
        AccessChecker.logResult(authResult);
        if (authorizationEnabled && !authResult.isAllowed()) {
          throw new AccessDeniedException("Insufficient permissions "
            + authResult.toContextString());
        }
      }
    }
  }
}
 
Example 16
Source Project: hbase   Source File: WriteSinkCoprocessor.java    License: Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example 17
Source Project: hbase   Source File: TestFromClientSide3.java    License: 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 Project: hbase   Source File: TestFromClientSide3.java    License: 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 19
Source Project: hbase   Source File: SimpleRegionObserver.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void preBatchMutate(ObserverContext<RegionCoprocessorEnvironment> c,
    MiniBatchOperationInProgress<Mutation> miniBatchOp) throws IOException {
  RegionCoprocessorEnvironment e = c.getEnvironment();
  assertNotNull(e);
  assertNotNull(e.getRegion());
  assertNotNull(miniBatchOp);
  ctPreBatchMutate.incrementAndGet();
}
 
Example 20
Source Project: hbase   Source File: SimpleRegionObserver.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void postBatchMutate(final ObserverContext<RegionCoprocessorEnvironment> c,
    final MiniBatchOperationInProgress<Mutation> miniBatchOp) throws IOException {
  RegionCoprocessorEnvironment e = c.getEnvironment();
  assertNotNull(e);
  assertNotNull(e.getRegion());
  assertNotNull(miniBatchOp);
  ctPostBatchMutate.incrementAndGet();
}
 
Example 21
@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 22
@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 23
Source Project: phoenix   Source File: IndexRegionObserver.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void preBatchMutate(ObserverContext<RegionCoprocessorEnvironment> c,
    MiniBatchOperationInProgress<Mutation> miniBatchOp) throws IOException {
    if (this.disabled) {
        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 24
Source Project: phoenix   Source File: IndexRegionObserver.java    License: Apache License 2.0 5 votes vote down vote up
private void ignoreAtomicOperations (MiniBatchOperationInProgress<Mutation> miniBatchOp) {
    for (int i = 0; i < miniBatchOp.size(); i++) {
        Mutation m = miniBatchOp.getOperation(i);
        if (this.builder.isAtomicOp(m)) {
            miniBatchOp.setOperationStatus(i, IGNORE);
            continue;
        }
    }
}
 
Example 25
Source Project: phoenix   Source File: IndexRegionObserver.java    License: Apache License 2.0 5 votes vote down vote up
private void populateRowsToLock(MiniBatchOperationInProgress<Mutation> miniBatchOp, BatchMutateContext context) {
    for (int i = 0; i < miniBatchOp.size(); i++) {
        if (miniBatchOp.getOperationStatus(i) == IGNORE) {
            continue;
        }
        Mutation m = miniBatchOp.getOperation(i);
        if (this.builder.isEnabled(m)) {
            ImmutableBytesPtr row = new ImmutableBytesPtr(m.getRow());
            if (!context.rowsToLock.contains(row)) {
                context.rowsToLock.add(row);
            }
        }
    }
}
 
Example 26
Source Project: phoenix   Source File: IndexRegionObserver.java    License: 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 27
Source Project: phoenix   Source File: IndexRegionObserver.java    License: 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 28
Source Project: phoenix   Source File: IndexRegionObserver.java    License: 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 29
Source Project: phoenix   Source File: IndexRegionObserver.java    License: 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 30
Source Project: phoenix   Source File: Indexer.java    License: 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);
     }
}