-
Notifications
You must be signed in to change notification settings - Fork 3.4k
HBASE-28792: AsyncTableImpl should call coprocessor callbacks in a defined order #6168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ndimiduk
merged 5 commits into
apache:master
from
HubSpot:asynctableimpl-coproc-callback
Sep 4, 2024
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
02b99bc
AsyncTableImpl should call coprocessor callbacks in a defined order
charlesconnell 334dcde
Order onComplete() call via a Phaser
charlesconnell f694380
Unit test for AsyncAggregationClient+AsyncTableImpl
charlesconnell 82cef8b
tweak test
charlesconnell 5573a60
Use Phaser in onRegionError
charlesconnell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
156 changes: 156 additions & 0 deletions
156
...java/org/apache/hadoop/hbase/client/TestAsyncAggregationClientWithCallbackThreadPool.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,156 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.hadoop.hbase.client; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
|
|
||
| import java.util.concurrent.ExecutionException; | ||
| import java.util.concurrent.ExecutorService; | ||
| import java.util.concurrent.Executors; | ||
| import java.util.stream.Collectors; | ||
| import java.util.stream.LongStream; | ||
| import org.apache.hadoop.conf.Configuration; | ||
| import org.apache.hadoop.hbase.HBaseClassTestRule; | ||
| import org.apache.hadoop.hbase.HBaseTestingUtil; | ||
| import org.apache.hadoop.hbase.TableName; | ||
| import org.apache.hadoop.hbase.client.coprocessor.AsyncAggregationClient; | ||
| import org.apache.hadoop.hbase.client.coprocessor.LongColumnInterpreter; | ||
| import org.apache.hadoop.hbase.coprocessor.AggregateImplementation; | ||
| import org.apache.hadoop.hbase.coprocessor.CoprocessorHost; | ||
| import org.apache.hadoop.hbase.testclassification.CoprocessorTests; | ||
| import org.apache.hadoop.hbase.testclassification.MediumTests; | ||
| import org.apache.hadoop.hbase.util.Bytes; | ||
| import org.junit.AfterClass; | ||
| import org.junit.BeforeClass; | ||
| import org.junit.ClassRule; | ||
| import org.junit.Test; | ||
| import org.junit.experimental.categories.Category; | ||
|
|
||
| /** | ||
| * Same as TestAsyncAggregationClient, except that {@link AsyncTableImpl} is involved in addition to | ||
| * {@link RawAsyncTableImpl}. Exercises the code paths in {@link AsyncTableImpl#coprocessorService}. | ||
| */ | ||
| @Category({ MediumTests.class, CoprocessorTests.class }) | ||
| public class TestAsyncAggregationClientWithCallbackThreadPool { | ||
|
|
||
| @ClassRule | ||
| public static final HBaseClassTestRule CLASS_RULE = | ||
| HBaseClassTestRule.forClass(TestAsyncAggregationClientWithCallbackThreadPool.class); | ||
|
|
||
| private static HBaseTestingUtil UTIL = new HBaseTestingUtil(); | ||
|
|
||
| private static TableName TABLE_NAME = TableName.valueOf("TestAsyncAggregationClient"); | ||
|
|
||
| private static byte[] CF = Bytes.toBytes("CF"); | ||
|
|
||
| private static byte[] CQ = Bytes.toBytes("CQ"); | ||
|
|
||
| private static byte[] CQ2 = Bytes.toBytes("CQ2"); | ||
|
|
||
| private static long COUNT = 1000; | ||
|
|
||
| private static AsyncConnection CONN; | ||
|
|
||
| private static AsyncTable<ScanResultConsumer> TABLE; | ||
|
|
||
| private static ExecutorService EXECUTOR_SERVICE; | ||
|
|
||
| @BeforeClass | ||
| public static void setUp() throws Exception { | ||
| Configuration conf = UTIL.getConfiguration(); | ||
| conf.setStrings(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY, | ||
| AggregateImplementation.class.getName()); | ||
| UTIL.startMiniCluster(3); | ||
| byte[][] splitKeys = new byte[8][]; | ||
| for (int i = 111; i < 999; i += 111) { | ||
| splitKeys[i / 111 - 1] = Bytes.toBytes(String.format("%03d", i)); | ||
| } | ||
| UTIL.createTable(TABLE_NAME, CF, splitKeys); | ||
| CONN = ConnectionFactory.createAsyncConnection(UTIL.getConfiguration()).get(); | ||
| EXECUTOR_SERVICE = Executors.newFixedThreadPool(1); | ||
| TABLE = CONN.getTable(TABLE_NAME, EXECUTOR_SERVICE); | ||
| TABLE.putAll(LongStream.range(0, COUNT) | ||
| .mapToObj(l -> new Put(Bytes.toBytes(String.format("%03d", l))) | ||
| .addColumn(CF, CQ, Bytes.toBytes(l)).addColumn(CF, CQ2, Bytes.toBytes(l * l))) | ||
| .collect(Collectors.toList())).get(); | ||
| } | ||
|
|
||
| @AfterClass | ||
| public static void tearDown() throws Exception { | ||
| CONN.close(); | ||
| UTIL.shutdownMiniCluster(); | ||
| EXECUTOR_SERVICE.shutdownNow(); | ||
| } | ||
|
|
||
| @Test | ||
| public void testMax() throws InterruptedException, ExecutionException { | ||
| assertEquals(COUNT - 1, AsyncAggregationClient | ||
| .max(TABLE, new LongColumnInterpreter(), new Scan().addColumn(CF, CQ)).get().longValue()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testMin() throws InterruptedException, ExecutionException { | ||
| assertEquals(0, AsyncAggregationClient | ||
| .min(TABLE, new LongColumnInterpreter(), new Scan().addColumn(CF, CQ)).get().longValue()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testRowCount() throws InterruptedException, ExecutionException { | ||
| assertEquals(COUNT, | ||
| AsyncAggregationClient | ||
| .rowCount(TABLE, new LongColumnInterpreter(), new Scan().addColumn(CF, CQ)).get() | ||
| .longValue()); | ||
|
|
||
| // Run the count twice in case some state doesn't get cleaned up inside AsyncTableImpl | ||
| // on the first time. | ||
| assertEquals(COUNT, | ||
| AsyncAggregationClient | ||
| .rowCount(TABLE, new LongColumnInterpreter(), new Scan().addColumn(CF, CQ)).get() | ||
| .longValue()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testSum() throws InterruptedException, ExecutionException { | ||
| assertEquals(COUNT * (COUNT - 1) / 2, AsyncAggregationClient | ||
| .sum(TABLE, new LongColumnInterpreter(), new Scan().addColumn(CF, CQ)).get().longValue()); | ||
| } | ||
|
|
||
| private static final double DELTA = 1E-3; | ||
|
|
||
| @Test | ||
| public void testAvg() throws InterruptedException, ExecutionException { | ||
| assertEquals( | ||
| (COUNT - 1) / 2.0, AsyncAggregationClient | ||
| .avg(TABLE, new LongColumnInterpreter(), new Scan().addColumn(CF, CQ)).get().doubleValue(), | ||
| DELTA); | ||
| } | ||
|
|
||
| @Test | ||
| public void testStd() throws InterruptedException, ExecutionException { | ||
| double avgSq = | ||
| LongStream.range(0, COUNT).map(l -> l * l).reduce((l1, l2) -> l1 + l2).getAsLong() | ||
| / (double) COUNT; | ||
| double avg = (COUNT - 1) / 2.0; | ||
| double std = Math.sqrt(avgSq - avg * avg); | ||
| assertEquals( | ||
| std, AsyncAggregationClient | ||
| .std(TABLE, new LongColumnInterpreter(), new Scan().addColumn(CF, CQ)).get().doubleValue(), | ||
| DELTA); | ||
| } | ||
|
|
||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the Javadoc on this method,
onCompletemust implement a happens-after semantic for allonRegionCompleteand allonRegionErrorinvocations. This implies that there are multiple regions to complete AND multiple forms of completion, so I think that this can be solved with a phaser ; you need a more general purpose mutex.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point that onRegionError should be included in the barrier. I'm guessing you meant to say "so I think that this cannot be solved with a phaser," but I disagree. The phaser can be used in onRegionError just the same as onRegionComplete.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I see. Phaser is more powerful than I initially understood -- very cool! Yes, this looks better to me.