-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
HBASE-27902 Utility to invoke coproc on multiple servers using AsyncAdmin #5295
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
86328ca
HBASE-27902 New async admin api to invoke coproc on multiple servers
jinggou 7683f91
fix spotless check error
jinggou 7b55785
make coprocessorServiceOnAllRegionServers be a default method in Asyn…
jinggou 9735a8f
introduce a helper class AsyncAdminClientUtils to put coprocessorServ…
jinggou 8cb16a2
remove change in TestInterfaceAlign
jinggou 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 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
This file contains 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
This file contains 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
This file contains 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
161 changes: 161 additions & 0 deletions
161
...a/org/apache/hadoop/hbase/coprocessor/TestAsyncCoprocessorOnAllRegionServersEndpoint.java
This file contains 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,161 @@ | ||
/* | ||
* 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.coprocessor; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import com.google.protobuf.RpcCallback; | ||
import com.google.protobuf.RpcController; | ||
import com.google.protobuf.Service; | ||
import java.io.FileNotFoundException; | ||
import java.util.Collections; | ||
import java.util.Map; | ||
import java.util.concurrent.ExecutionException; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
import org.apache.hadoop.hbase.HBaseClassTestRule; | ||
import org.apache.hadoop.hbase.HConstants; | ||
import org.apache.hadoop.hbase.ServerName; | ||
import org.apache.hadoop.hbase.client.ConnectionFactory; | ||
import org.apache.hadoop.hbase.client.RetriesExhaustedException; | ||
import org.apache.hadoop.hbase.client.TestAsyncAdminBase; | ||
import org.apache.hadoop.hbase.coprocessor.protobuf.generated.DummyRegionServerEndpointProtos.DummyRequest; | ||
import org.apache.hadoop.hbase.coprocessor.protobuf.generated.DummyRegionServerEndpointProtos.DummyResponse; | ||
import org.apache.hadoop.hbase.coprocessor.protobuf.generated.DummyRegionServerEndpointProtos.DummyService; | ||
import org.apache.hadoop.hbase.ipc.CoprocessorRpcUtils; | ||
import org.apache.hadoop.hbase.testclassification.ClientTests; | ||
import org.apache.hadoop.hbase.testclassification.MediumTests; | ||
import org.junit.AfterClass; | ||
import org.junit.BeforeClass; | ||
import org.junit.ClassRule; | ||
import org.junit.Test; | ||
import org.junit.experimental.categories.Category; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Parameterized; | ||
|
||
@RunWith(Parameterized.class) | ||
@Category({ ClientTests.class, MediumTests.class }) | ||
public class TestAsyncCoprocessorOnAllRegionServersEndpoint extends TestAsyncAdminBase { | ||
@ClassRule | ||
public static final HBaseClassTestRule CLASS_RULE = | ||
HBaseClassTestRule.forClass(TestAsyncCoprocessorOnAllRegionServersEndpoint.class); | ||
|
||
private static final String THROW_CLASS_NAME = "java.io.FileNotFoundException"; | ||
private static final String DUMMY_VALUE = "val"; | ||
private static final int NUM_SLAVES = 5; | ||
private static final int NUM_SUCCESS_REGION_SERVERS = 3; | ||
|
||
@BeforeClass | ||
public static void setUpBeforeClass() throws Exception { | ||
TEST_UTIL.getConfiguration().setInt(HConstants.HBASE_RPC_TIMEOUT_KEY, 60000); | ||
TEST_UTIL.getConfiguration().setInt(HConstants.HBASE_CLIENT_OPERATION_TIMEOUT, 120000); | ||
TEST_UTIL.getConfiguration().setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 2); | ||
TEST_UTIL.getConfiguration().setStrings(CoprocessorHost.MASTER_COPROCESSOR_CONF_KEY, | ||
ProtobufCoprocessorService.class.getName()); | ||
TEST_UTIL.getConfiguration().setStrings(CoprocessorHost.REGIONSERVER_COPROCESSOR_CONF_KEY, | ||
DummyRegionServerEndpoint.class.getName()); | ||
TEST_UTIL.startMiniCluster(NUM_SLAVES); | ||
ASYNC_CONN = ConnectionFactory.createAsyncConnection(TEST_UTIL.getConfiguration()).get(); | ||
} | ||
|
||
@AfterClass | ||
public static void tearDownAfterClass() throws Exception { | ||
TEST_UTIL.shutdownMiniCluster(); | ||
} | ||
|
||
@Test | ||
public void testRegionServersCoprocessorService() | ||
throws ExecutionException, InterruptedException { | ||
DummyRequest request = DummyRequest.getDefaultInstance(); | ||
Map<ServerName, Object> resultMap = | ||
admin.<DummyService.Stub, DummyResponse> coprocessorServiceOnAllRegionServers( | ||
DummyService::newStub, (s, c, done) -> s.dummyCall(c, request, done)).get(); | ||
|
||
resultMap.forEach((k, v) -> { | ||
assertTrue(v instanceof DummyResponse); | ||
DummyResponse resp = (DummyResponse) v; | ||
assertEquals(DUMMY_VALUE, resp.getValue()); | ||
}); | ||
} | ||
|
||
@Test | ||
public void testRegionServerCoprocessorsServiceAllFail() | ||
throws ExecutionException, InterruptedException { | ||
DummyRequest request = DummyRequest.getDefaultInstance(); | ||
Map<ServerName, Object> resultMap = | ||
admin.<DummyService.Stub, DummyResponse> coprocessorServiceOnAllRegionServers( | ||
DummyService::newStub, (s, c, done) -> s.dummyThrow(c, request, done)).get(); | ||
|
||
resultMap.forEach((k, v) -> { | ||
assertTrue(v instanceof RetriesExhaustedException); | ||
Throwable e = (Throwable) v; | ||
assertTrue(e.getMessage().contains(THROW_CLASS_NAME)); | ||
}); | ||
} | ||
|
||
@Test | ||
public void testRegionServerCoprocessorsServicePartialFail() | ||
throws ExecutionException, InterruptedException { | ||
DummyRequest request = DummyRequest.getDefaultInstance(); | ||
AtomicInteger callCount = new AtomicInteger(); | ||
Map<ServerName, Object> resultMap = admin.<DummyService.Stub, | ||
DummyResponse> coprocessorServiceOnAllRegionServers(DummyService::newStub, (s, c, done) -> { | ||
callCount.addAndGet(1); | ||
if (callCount.get() <= NUM_SUCCESS_REGION_SERVERS) { | ||
s.dummyCall(c, request, done); | ||
} else { | ||
s.dummyThrow(c, request, done); | ||
} | ||
}).get(); | ||
|
||
AtomicInteger successCallCount = new AtomicInteger(); | ||
resultMap.forEach((k, v) -> { | ||
if (v instanceof DummyResponse) { | ||
successCallCount.addAndGet(1); | ||
DummyResponse resp = (DummyResponse) v; | ||
assertEquals(DUMMY_VALUE, resp.getValue()); | ||
} else { | ||
assertTrue(v instanceof RetriesExhaustedException); | ||
Throwable e = (Throwable) v; | ||
assertTrue(e.getMessage().contains(THROW_CLASS_NAME)); | ||
} | ||
}); | ||
assertEquals(NUM_SUCCESS_REGION_SERVERS, successCallCount.get()); | ||
} | ||
|
||
public static class DummyRegionServerEndpoint extends DummyService | ||
implements RegionServerCoprocessor { | ||
@Override | ||
public Iterable<Service> getServices() { | ||
return Collections.singleton(this); | ||
} | ||
|
||
@Override | ||
public void dummyCall(RpcController controller, DummyRequest request, | ||
RpcCallback<DummyResponse> callback) { | ||
callback.run(DummyResponse.newBuilder().setValue(DUMMY_VALUE).build()); | ||
} | ||
|
||
@Override | ||
public void dummyThrow(RpcController controller, DummyRequest request, | ||
RpcCallback<DummyResponse> done) { | ||
CoprocessorRpcUtils.setControllerException(controller, | ||
new FileNotFoundException("/file.txt")); | ||
} | ||
} | ||
} |
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.
same as master branch PR, we might not need this change anymore
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.
+1.