Skip to content

Commit ba40de1

Browse files
committed
HBASE-27448 Add an admin method to get replication enabled state
1 parent 984d226 commit ba40de1

File tree

11 files changed

+131
-0
lines changed

11 files changed

+131
-0
lines changed

hbase-client/src/main/java/org/apache/hadoop/hbase/client/Admin.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2555,4 +2555,12 @@ List<LogEntry> getLogEntries(Set<ServerName> serverNames, String logType, Server
25552555
* Flush master local region
25562556
*/
25572557
void flushMasterStore() throws IOException;
2558+
2559+
/**
2560+
* Check if a replication peer is enabled.
2561+
* @param peerId id of replication peer to check
2562+
* @return <code>true</code> if replication peer is enabled
2563+
* @throws IOException if a remote or network exception occurs
2564+
*/
2565+
boolean isReplicationPeerEnabled(String peerId) throws IOException;
25582566
}

hbase-client/src/main/java/org/apache/hadoop/hbase/client/AdminOverAsyncAdmin.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,4 +1084,9 @@ public List<LogEntry> getLogEntries(Set<ServerName> serverNames, String logType,
10841084
public void flushMasterStore() throws IOException {
10851085
get(admin.flushMasterStore());
10861086
}
1087+
1088+
@Override
1089+
public boolean isReplicationPeerEnabled(String peerId) throws IOException {
1090+
return get(admin.isReplicationPeerEnabled(peerId));
1091+
}
10871092
}

hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncAdmin.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1776,4 +1776,12 @@ CompletableFuture<List<LogEntry>> getLogEntries(Set<ServerName> serverNames, Str
17761776
* Flush master local region
17771777
*/
17781778
CompletableFuture<Void> flushMasterStore();
1779+
1780+
/**
1781+
* Check if a replication peer is enabled.
1782+
* @param peerId id of replication peer to check
1783+
* @return true if replication peer is enabled. The return value will be wrapped by a
1784+
* {@link CompletableFuture}.
1785+
*/
1786+
CompletableFuture<Boolean> isReplicationPeerEnabled(String peerId);
17791787
}

hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncHBaseAdmin.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -959,4 +959,9 @@ public CompletableFuture<List<LogEntry>> getLogEntries(Set<ServerName> serverNam
959959
public CompletableFuture<Void> flushMasterStore() {
960960
return wrap(rawAdmin.flushMasterStore());
961961
}
962+
963+
@Override
964+
public CompletableFuture<Boolean> isReplicationPeerEnabled(String peerId) {
965+
return wrap(rawAdmin.isReplicationPeerEnabled(peerId));
966+
}
962967
}

hbase-client/src/main/java/org/apache/hadoop/hbase/client/RawAsyncHBaseAdmin.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@
192192
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetProcedureResultResponse;
193193
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetProceduresRequest;
194194
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetProceduresResponse;
195+
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetReplicationPeerStateRequest;
196+
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetReplicationPeerStateResponse;
195197
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetTableDescriptorsRequest;
196198
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetTableDescriptorsResponse;
197199
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetTableNamesRequest;
@@ -4284,4 +4286,16 @@ Void> call(controller, stub, request.build(),
42844286
(s, c, req, done) -> s.flushMasterStore(c, req, done), resp -> null))
42854287
.call();
42864288
}
4289+
4290+
@Override
4291+
public CompletableFuture<Boolean> isReplicationPeerEnabled(String peerId) {
4292+
GetReplicationPeerStateRequest.Builder request = GetReplicationPeerStateRequest.newBuilder();
4293+
request.setPeerId(peerId);
4294+
return this.<Boolean> newMasterCaller()
4295+
.action((controller, stub) -> this.<GetReplicationPeerStateRequest,
4296+
GetReplicationPeerStateResponse, Boolean> call(controller, stub, request.build(),
4297+
(s, c, req, done) -> s.isReplicationPeerEnabled(c, req, done),
4298+
resp -> resp.getIsEnabled()))
4299+
.call();
4300+
}
42874301
}

hbase-protocol-shaded/src/main/protobuf/server/master/Master.proto

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,13 @@ message ModifyColumnStoreFileTrackerResponse {
761761
message FlushMasterStoreRequest {}
762762
message FlushMasterStoreResponse {}
763763

764+
message GetReplicationPeerStateRequest {
765+
required string peer_id = 1;
766+
}
767+
message GetReplicationPeerStateResponse {
768+
required bool is_enabled = 1;
769+
}
770+
764771
service MasterService {
765772
/** Used by the client to get the number of regions that have received the updated schema */
766773
rpc GetSchemaAlterStatus(GetSchemaAlterStatusRequest)
@@ -1203,6 +1210,9 @@ service MasterService {
12031210

12041211
rpc FlushMasterStore(FlushMasterStoreRequest)
12051212
returns(FlushMasterStoreResponse);
1213+
1214+
rpc IsReplicationPeerEnabled(GetReplicationPeerStateRequest)
1215+
returns(GetReplicationPeerStateResponse);
12061216
}
12071217

12081218
// HBCK Service definitions.

hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterRpcServices.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,8 @@
246246
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetProcedureResultResponse;
247247
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetProceduresRequest;
248248
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetProceduresResponse;
249+
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetReplicationPeerStateRequest;
250+
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetReplicationPeerStateResponse;
249251
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetSchemaAlterStatusRequest;
250252
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetSchemaAlterStatusResponse;
251253
import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.GetTableDescriptorsRequest;
@@ -3491,4 +3493,16 @@ public FlushMasterStoreResponse flushMasterStore(RpcController controller,
34913493
}
34923494
return FlushMasterStoreResponse.newBuilder().build();
34933495
}
3496+
3497+
@Override
3498+
public GetReplicationPeerStateResponse isReplicationPeerEnabled(RpcController controller,
3499+
GetReplicationPeerStateRequest request) throws ServiceException {
3500+
boolean isEnabled;
3501+
try {
3502+
isEnabled = server.getReplicationPeerManager().getPeerState(request.getPeerId());
3503+
} catch (ReplicationException ioe) {
3504+
throw new ServiceException(ioe);
3505+
}
3506+
return GetReplicationPeerStateResponse.newBuilder().setIsEnabled(isEnabled).build();
3507+
}
34943508
}

hbase-server/src/main/java/org/apache/hadoop/hbase/master/replication/ReplicationPeerManager.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,15 @@ private void setPeerState(String peerId, boolean enabled) throws ReplicationExce
271271
desc.getSyncReplicationState()));
272272
}
273273

274+
public boolean getPeerState(String peerId) throws ReplicationException {
275+
ReplicationPeerDescription desc = peers.get(peerId);
276+
if (desc != null) {
277+
return desc.isEnabled();
278+
} else {
279+
throw new ReplicationException("Replication Peer of " + peerId + " does not exist.");
280+
}
281+
}
282+
274283
public void enablePeer(String peerId) throws ReplicationException {
275284
setPeerState(peerId, true);
276285
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.hadoop.hbase.replication;
19+
20+
import static org.junit.Assert.assertFalse;
21+
import static org.junit.Assert.assertTrue;
22+
23+
import org.apache.hadoop.hbase.HBaseClassTestRule;
24+
import org.apache.hadoop.hbase.testclassification.LargeTests;
25+
import org.apache.hadoop.hbase.testclassification.ReplicationTests;
26+
import org.junit.ClassRule;
27+
import org.junit.Test;
28+
import org.junit.experimental.categories.Category;
29+
30+
@Category({ ReplicationTests.class, LargeTests.class })
31+
public class TestGetReplicationPeerState extends TestReplicationBase {
32+
33+
@ClassRule
34+
public static final HBaseClassTestRule CLASS_RULE =
35+
HBaseClassTestRule.forClass(TestGetReplicationPeerState.class);
36+
37+
@Test
38+
public void testGetReplicationPeerState() throws Exception {
39+
40+
// Test disable replication peer
41+
hbaseAdmin.disableReplicationPeer("2");
42+
assertFalse(hbaseAdmin.isReplicationPeerEnabled("2"));
43+
44+
// Test enable replication peer
45+
hbaseAdmin.enableReplicationPeer("2");
46+
assertTrue(hbaseAdmin.isReplicationPeerEnabled("2"));
47+
}
48+
}

hbase-server/src/test/java/org/apache/hadoop/hbase/rsgroup/VerifyingRSGroupAdmin.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -939,4 +939,9 @@ public Future<Void> modifyTableStoreFileTrackerAsync(TableName tableName, String
939939
public void flushMasterStore() throws IOException {
940940
admin.flushMasterStore();
941941
}
942+
943+
@Override
944+
public boolean isReplicationPeerEnabled(String peerId) throws IOException {
945+
return admin.isReplicationPeerEnabled(peerId);
946+
}
942947
}

0 commit comments

Comments
 (0)