This is an automated email from the ASF dual-hosted git repository. chenglei pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/phoenix.git
The following commit(s) were added to refs/heads/master by this push: new ec78cd1 PHOENIX-5556 Avoid repeatedly loading IndexMetaData For IndexRegionObserver ec78cd1 is described below commit ec78cd142a21a2ccf6f1f53ee16b501bf81352c5 Author: chenglei <cheng...@apache.org> AuthorDate: Thu Nov 7 10:33:46 2019 +0800 PHOENIX-5556 Avoid repeatedly loading IndexMetaData For IndexRegionObserver --- .../phoenix/hbase/index/IndexRegionObserver.java | 39 ++++++++++++++-------- .../hbase/index/builder/IndexBuildManager.java | 4 +-- 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/IndexRegionObserver.java b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/IndexRegionObserver.java index 2af8d95..9ab8ed3 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/IndexRegionObserver.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/IndexRegionObserver.java @@ -524,16 +524,15 @@ public class IndexRegionObserver implements RegionObserver, RegionCoprocessor { } } - private void prepareIndexMutations(ObserverContext<RegionCoprocessorEnvironment> c, - MiniBatchOperationInProgress<Mutation> miniBatchOp, BatchMutateContext context, - Collection<? extends Mutation> mutations, long now) throws Throwable { - IndexMetaData indexMetaData = this.builder.getIndexMetaData(miniBatchOp); - if (!(indexMetaData instanceof PhoenixIndexMetaData)) { - throw new DoNotRetryIOException( - "preBatchMutateWithExceptions: indexMetaData is not an instance of PhoenixIndexMetaData " + - c.getEnvironment().getRegion().getRegionInfo().getTable().getNameAsString()); - } - List<IndexMaintainer> maintainers = ((PhoenixIndexMetaData)indexMetaData).getIndexMaintainers(); + private void prepareIndexMutations( + ObserverContext<RegionCoprocessorEnvironment> c, + MiniBatchOperationInProgress<Mutation> miniBatchOp, + BatchMutateContext context, + Collection<? extends Mutation> mutations, + long now, + PhoenixIndexMetaData indexMetaData) throws Throwable { + + List<IndexMaintainer> maintainers = indexMetaData.getIndexMaintainers(); // 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")) { @@ -544,7 +543,7 @@ public class IndexRegionObserver implements RegionObserver, RegionCoprocessor { // get the index updates for all elements in this batch Collection<Pair<Pair<Mutation, byte[]>, byte[]>> indexUpdates = - this.builder.getIndexUpdates(miniBatchOp, mutations); + this.builder.getIndexUpdates(miniBatchOp, mutations, indexMetaData); current.addTimelineAnnotation("Built index updates, doing preStep"); TracingUtils.addAnnotation(current, "index update count", indexUpdates.size()); @@ -613,10 +612,24 @@ public class IndexRegionObserver implements RegionObserver, RegionCoprocessor { } } + 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; + } + public void preBatchMutateWithExceptions(ObserverContext<RegionCoprocessorEnvironment> c, MiniBatchOperationInProgress<Mutation> miniBatchOp) throws Throwable { ignoreAtomicOperations(miniBatchOp); - BatchMutateContext context = new BatchMutateContext(this.builder.getIndexMetaData(miniBatchOp).getClientVersion()); + PhoenixIndexMetaData indexMetaData = getPhoenixIndexMetaData(c, miniBatchOp); + BatchMutateContext context = new BatchMutateContext(indexMetaData.getClientVersion()); setBatchMutateContext(c, context); Mutation firstMutation = miniBatchOp.getOperation(0); ReplayWrite replayWrite = this.builder.getReplayWrite(firstMutation); @@ -642,7 +655,7 @@ public class IndexRegionObserver implements RegionObserver, RegionCoprocessor { } long start = EnvironmentEdgeManager.currentTimeMillis(); - prepareIndexMutations(c, miniBatchOp, context, mutations, now); + prepareIndexMutations(c, miniBatchOp, context, mutations, now, indexMetaData); metricSource.updateIndexPrepareTime(EnvironmentEdgeManager.currentTimeMillis() - start); // Sleep for one millisecond if we have prepared the index updates in less than 1 ms. The sleep is necessary to diff --git a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/builder/IndexBuildManager.java b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/builder/IndexBuildManager.java index 1827917..7573478 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/builder/IndexBuildManager.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/builder/IndexBuildManager.java @@ -81,9 +81,9 @@ public class IndexBuildManager implements Stoppable { public Collection<Pair<Pair<Mutation, byte[]>, byte[]>> getIndexUpdates( MiniBatchOperationInProgress<Mutation> miniBatchOp, - Collection<? extends Mutation> mutations) throws Throwable { + Collection<? extends Mutation> mutations, + IndexMetaData indexMetaData) throws Throwable { // notify the delegate that we have started processing a batch - final IndexMetaData indexMetaData = this.delegate.getIndexMetaData(miniBatchOp); this.delegate.batchStarted(miniBatchOp, indexMetaData); // Avoid the Object overhead of the executor when it's not actually parallelizing anything.