本文整理了Java中org.apache.hadoop.hbase.client.Admin.addReplicationPeer()
方法的一些代码示例,展示了Admin.addReplicationPeer()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Admin.addReplicationPeer()
方法的具体详情如下:
包路径:org.apache.hadoop.hbase.client.Admin
类名称:Admin
方法名:addReplicationPeer
[英]Add a new replication peer for replicating data to slave cluster.
[中]添加新的复制对等机以将数据复制到从属群集。
代码示例来源:origin: apache/hbase
/**
* Add a new replication peer for replicating data to slave cluster.
* @param peerId a short name that identifies the peer
* @param peerConfig configuration for the replication peer
* @throws IOException if a remote or network exception occurs
*/
default void addReplicationPeer(String peerId, ReplicationPeerConfig peerConfig)
throws IOException {
addReplicationPeer(peerId, peerConfig, true);
}
代码示例来源:origin: apache/hbase
/**
* Add a new remote slave cluster for replication.
* @param id a short name that identifies the cluster
* @param peerConfig configuration for the replication slave cluster
* @deprecated use
* {@link org.apache.hadoop.hbase.client.Admin#addReplicationPeer(String, ReplicationPeerConfig)}
* instead
*/
@Deprecated
public void addPeer(String id, ReplicationPeerConfig peerConfig) throws ReplicationException,
IOException {
this.admin.addReplicationPeer(id, peerConfig);
}
代码示例来源:origin: apache/hbase
/**
* Add a new remote slave cluster for replication.
* @param id a short name that identifies the cluster
* @param peerConfig configuration for the replication slave cluster
* @param tableCfs the table and column-family list which will be replicated for this peer.
* A map from tableName to column family names. An empty collection can be passed
* to indicate replicating all column families. Pass null for replicating all table and column
* families
* @deprecated as release of 2.0.0, and it will be removed in 3.0.0,
* use {@link #addPeer(String, ReplicationPeerConfig)} instead.
*/
@Deprecated
public void addPeer(String id, ReplicationPeerConfig peerConfig,
Map<TableName, ? extends Collection<String>> tableCfs) throws ReplicationException,
IOException {
if (tableCfs != null) {
peerConfig.setTableCFsMap(tableCfs);
}
this.admin.addReplicationPeer(id, peerConfig);
}
代码示例来源:origin: apache/hbase
public static void createPeer() throws IOException {
ReplicationPeerConfig rpc = ReplicationPeerConfig.newBuilder()
.setClusterKey(UTIL.getClusterKey()).setSerial(true).build();
UTIL.getAdmin().addReplicationPeer(PEER_1, rpc);
UTIL.getAdmin().addReplicationPeer(PEER_2, rpc);
}
代码示例来源:origin: apache/hbase
@Test
public void testAddPeerWithState() throws Exception {
ReplicationPeerConfig rpc1 = new ReplicationPeerConfig();
rpc1.setClusterKey(KEY_ONE);
hbaseAdmin.addReplicationPeer(ID_ONE, rpc1, true);
assertTrue(hbaseAdmin.listReplicationPeers(Pattern.compile(ID_ONE)).get(0).isEnabled());
hbaseAdmin.removeReplicationPeer(ID_ONE);
ReplicationPeerConfig rpc2 = new ReplicationPeerConfig();
rpc2.setClusterKey(KEY_SECOND);
hbaseAdmin.addReplicationPeer(ID_SECOND, rpc2, false);
assertFalse(hbaseAdmin.listReplicationPeers(Pattern.compile(ID_SECOND)).get(0).isEnabled());
hbaseAdmin.removeReplicationPeer(ID_SECOND);
}
代码示例来源:origin: apache/hbase
protected final void addPeer(boolean enabled) throws IOException {
UTIL.getAdmin().addReplicationPeer(PEER_ID,
ReplicationPeerConfig.newBuilder().setClusterKey("127.0.0.1:2181:/hbase")
.setReplicationEndpointImpl(LocalReplicationEndpoint.class.getName()).setSerial(true)
.build(),
enabled);
}
代码示例来源:origin: apache/hbase
private void addPeer(String id, int masterClusterNumber,
int slaveClusterNumber) throws Exception {
try (Admin admin = ConnectionFactory.createConnection(configurations[masterClusterNumber])
.getAdmin()) {
admin.addReplicationPeer(id,
new ReplicationPeerConfig().setClusterKey(utilities[slaveClusterNumber].getClusterKey()));
}
}
代码示例来源:origin: apache/hbase
@Test
public void testAddInvalidPeer() {
ReplicationPeerConfigBuilder builder = ReplicationPeerConfig.newBuilder();
builder.setClusterKey(KEY_ONE);
try {
String invalidPeerId = "1-2";
hbaseAdmin.addReplicationPeer(invalidPeerId, builder.build());
fail("Should fail as the peer id: " + invalidPeerId + " is invalid");
} catch (Exception e) {
// OK
}
try {
String invalidClusterKey = "2181:/hbase";
builder.setClusterKey(invalidClusterKey);
hbaseAdmin.addReplicationPeer(ID_ONE, builder.build());
fail("Should fail as the peer cluster key: " + invalidClusterKey + " is invalid");
} catch (Exception e) {
// OK
}
}
代码示例来源:origin: apache/hbase
/**
* Tests that the peer configuration used by ReplicationAdmin contains all
* the peer's properties.
*/
@Test
public void testPeerConfig() throws Exception {
ReplicationPeerConfig config = new ReplicationPeerConfig();
config.setClusterKey(KEY_ONE);
config.getConfiguration().put("key1", "value1");
config.getConfiguration().put("key2", "value2");
hbaseAdmin.addReplicationPeer(ID_ONE, config);
List<ReplicationPeerDescription> peers = hbaseAdmin.listReplicationPeers();
assertEquals(1, peers.size());
ReplicationPeerDescription peerOne = peers.get(0);
assertNotNull(peerOne);
assertEquals("value1", peerOne.getPeerConfig().getConfiguration().get("key1"));
assertEquals("value2", peerOne.getPeerConfig().getConfiguration().get("key2"));
hbaseAdmin.removeReplicationPeer(ID_ONE);
}
代码示例来源:origin: apache/hbase
@BeforeClass
public static void setUpBeforeClass() throws Exception {
UTIL.getConfiguration().set(WALFactory.WAL_PROVIDER, "multiwal");
// make sure that we will create a new group for the table
UTIL.getConfiguration().setInt("hbase.wal.regiongrouping.numgroups", 8);
UTIL.startMiniCluster(3);
Path dir = UTIL.getDataTestDirOnTestFS();
FS = UTIL.getTestFileSystem();
LOG_PATH = new Path(dir, "replicated");
WRITER = WALFactory.createWALWriter(FS, LOG_PATH, UTIL.getConfiguration());
UTIL.getAdmin().addReplicationPeer(PEER_ID,
ReplicationPeerConfig.newBuilder().setClusterKey("127.0.0.1:2181:/hbase")
.setReplicationEndpointImpl(LocalReplicationEndpoint.class.getName()).build(),
true);
}
代码示例来源:origin: apache/hbase
@Test
public void testReplicationPeerConfigUpdateCallback() throws Exception {
String peerId = "1";
ReplicationPeerConfig rpc = new ReplicationPeerConfig();
rpc.setClusterKey(utility2.getClusterKey());
rpc.setReplicationEndpointImpl(TestUpdatableReplicationEndpoint.class.getName());
rpc.getConfiguration().put("key1", "value1");
admin1.addReplicationPeer(peerId, rpc);
rpc.getConfiguration().put("key1", "value2");
admin.updatePeerConfig(peerId, rpc);
if (!TestUpdatableReplicationEndpoint.hasCalledBack()) {
synchronized (TestUpdatableReplicationEndpoint.class) {
TestUpdatableReplicationEndpoint.class.wait(2000L);
}
}
assertEquals(true, TestUpdatableReplicationEndpoint.hasCalledBack());
admin.removePeer(peerId);
}
代码示例来源:origin: apache/hbase
@Before
public void setUpBase() throws Exception {
if (!peerExist(PEER_ID2)) {
ReplicationPeerConfigBuilder builder = ReplicationPeerConfig.newBuilder()
.setClusterKey(utility2.getClusterKey()).setSerial(isSerialPeer());
if (isSyncPeer()) {
FileSystem fs2 = utility2.getTestFileSystem();
// The remote wal dir is not important as we do not use it in DA state, here we only need to
// confirm that a sync peer in DA state can still replicate data to remote cluster
// asynchronously.
builder.setReplicateAllUserTables(false)
.setTableCFsMap(ImmutableMap.of(tableName, ImmutableList.of()))
.setRemoteWALDir(new Path("/RemoteWAL")
.makeQualified(fs2.getUri(), fs2.getWorkingDirectory()).toUri().toString());
}
hbaseAdmin.addReplicationPeer(PEER_ID2, builder.build());
}
}
代码示例来源:origin: apache/hbase
@Test
public void testPeerClusterKey() throws Exception {
ReplicationPeerConfigBuilder builder = ReplicationPeerConfig.newBuilder();
builder.setClusterKey(KEY_ONE);
hbaseAdmin.addReplicationPeer(ID_ONE, builder.build());
try {
builder.setClusterKey(KEY_SECOND);
hbaseAdmin.updateReplicationPeerConfig(ID_ONE, builder.build());
fail("Change cluster key on an existing peer is not allowed");
} catch (Exception e) {
// OK
}
}
代码示例来源:origin: apache/hbase
private void addPeer(String id, int masterClusterNumber, int slaveClusterNumber, String tableCfs)
throws Exception {
try (Admin admin =
ConnectionFactory.createConnection(configurations[masterClusterNumber]).getAdmin()) {
admin.addReplicationPeer(
id,
new ReplicationPeerConfig().setClusterKey(utilities[slaveClusterNumber].getClusterKey())
.setReplicateAllUserTables(false)
.setTableCFsMap(ReplicationPeerConfigUtil.parseTableCFsFromConfig(tableCfs)));
}
}
代码示例来源:origin: apache/hbase
@Test
public void testRemoveTable() throws Exception {
TableName tableName = createTable();
ReplicationPeerConfig peerConfig = ReplicationPeerConfig.newBuilder()
.setClusterKey("127.0.0.1:2181:/hbase")
.setReplicationEndpointImpl(LocalReplicationEndpoint.class.getName())
.setReplicateAllUserTables(false)
.setTableCFsMap(ImmutableMap.of(tableName, Collections.emptyList())).setSerial(true).build();
UTIL.getAdmin().addReplicationPeer(PEER_ID, peerConfig, true);
try (Table table = UTIL.getConnection().getTable(tableName)) {
for (int i = 0; i < 100; i++) {
table.put(new Put(Bytes.toBytes(i)).addColumn(CF, CQ, Bytes.toBytes(i)));
}
}
RegionInfo region = UTIL.getMiniHBaseCluster().getRegions(tableName).get(0).getRegionInfo();
waitUntilHasLastPushedSequenceId(region);
UTIL.getAdmin().updateReplicationPeerConfig(PEER_ID,
ReplicationPeerConfig.newBuilder(peerConfig).setTableCFsMap(Collections.emptyMap()).build());
ReplicationQueueStorage queueStorage =
UTIL.getMiniHBaseCluster().getMaster().getReplicationPeerManager().getQueueStorage();
assertEquals(HConstants.NO_SEQNUM,
queueStorage.getLastSequenceId(region.getEncodedName(), PEER_ID));
}
代码示例来源:origin: apache/hbase
.setReplicationEndpointImpl(LocalReplicationEndpoint.class.getName())
.setReplicateAllUserTables(false).setSerial(true).build();
UTIL.getAdmin().addReplicationPeer(PEER_ID, peerConfig, true);
代码示例来源:origin: apache/hbase
@Test
public void testChangeToSerial() throws Exception {
ReplicationPeerConfig peerConfig =
ReplicationPeerConfig.newBuilder().setClusterKey("127.0.0.1:2181:/hbase")
.setReplicationEndpointImpl(LocalReplicationEndpoint.class.getName()).build();
UTIL.getAdmin().addReplicationPeer(PEER_ID, peerConfig, true);
TableName tableName = createTable();
try (Table table = UTIL.getConnection().getTable(tableName)) {
for (int i = 0; i < 100; i++) {
table.put(new Put(Bytes.toBytes(i)).addColumn(CF, CQ, Bytes.toBytes(i)));
}
}
RegionInfo region = UTIL.getAdmin().getRegions(tableName).get(0);
HRegionServer srcRs = UTIL.getRSForFirstRegionInTable(tableName);
HRegionServer rs = UTIL.getOtherRegionServer(srcRs);
moveRegionAndArchiveOldWals(region, rs);
waitUntilReplicationDone(100);
waitUntilReplicatedToTheCurrentWALFile(srcRs);
UTIL.getAdmin().disableReplicationPeer(PEER_ID);
UTIL.getAdmin().updateReplicationPeerConfig(PEER_ID,
ReplicationPeerConfig.newBuilder(peerConfig).setSerial(true).build());
UTIL.getAdmin().enableReplicationPeer(PEER_ID);
try (Table table = UTIL.getConnection().getTable(tableName)) {
for (int i = 0; i < 100; i++) {
table.put(new Put(Bytes.toBytes(i)).addColumn(CF, CQ, Bytes.toBytes(i)));
}
}
waitUntilReplicationDone(200);
checkOrder(200);
}
代码示例来源:origin: apache/hbase
@Test
public void testPeerBandwidth() throws Exception {
ReplicationPeerConfig rpc = new ReplicationPeerConfig();
rpc.setClusterKey(KEY_ONE);
hbaseAdmin.addReplicationPeer(ID_ONE, rpc);
rpc = admin.getPeerConfig(ID_ONE);
assertEquals(0, rpc.getBandwidth());
rpc.setBandwidth(2097152);
admin.updatePeerConfig(ID_ONE, rpc);
assertEquals(2097152, admin.getPeerConfig(ID_ONE).getBandwidth());
admin.removePeer(ID_ONE);
}
代码示例来源:origin: apache/hbase
@Test
public void testSetReplicateAllUserTables() throws Exception {
ReplicationPeerConfig rpc = new ReplicationPeerConfig();
rpc.setClusterKey(KEY_ONE);
hbaseAdmin.addReplicationPeer(ID_ONE, rpc);
rpc = hbaseAdmin.getReplicationPeerConfig(ID_ONE);
assertTrue(rpc.replicateAllUserTables());
rpc.setReplicateAllUserTables(false);
hbaseAdmin.updateReplicationPeerConfig(ID_ONE, rpc);
rpc = hbaseAdmin.getReplicationPeerConfig(ID_ONE);
assertFalse(rpc.replicateAllUserTables());
rpc.setReplicateAllUserTables(true);
hbaseAdmin.updateReplicationPeerConfig(ID_ONE, rpc);
rpc = hbaseAdmin.getReplicationPeerConfig(ID_ONE);
assertTrue(rpc.replicateAllUserTables());
hbaseAdmin.removeReplicationPeer(ID_ONE);
}
代码示例来源:origin: apache/hbase
private void doTest() throws IOException {
Admin admin = UTIL.getAdmin();
String peerId = "1";
ReplicationPeerConfig peerConfig = ReplicationPeerConfig.newBuilder()
.setClusterKey("localhost:" + UTIL.getZkCluster().getClientPort() + ":/hbase2").build();
admin.addReplicationPeer(peerId, peerConfig, true);
assertEquals(peerConfig.getClusterKey(),
admin.getReplicationPeerConfig(peerId).getClusterKey());
ReplicationPeerConfig newPeerConfig =
ReplicationPeerConfig.newBuilder(peerConfig).setBandwidth(123456).build();
admin.updateReplicationPeerConfig(peerId, newPeerConfig);
assertEquals(newPeerConfig.getBandwidth(),
admin.getReplicationPeerConfig(peerId).getBandwidth());
admin.disableReplicationPeer(peerId);
assertFalse(admin.listReplicationPeers().get(0).isEnabled());
admin.enableReplicationPeer(peerId);
assertTrue(admin.listReplicationPeers().get(0).isEnabled());
admin.removeReplicationPeer(peerId);
assertTrue(admin.listReplicationPeers().isEmpty());
// make sure that we have run into the mocked method
MockHMaster master = (MockHMaster) UTIL.getHBaseCluster().getMaster();
assertTrue(master.addPeerCalled);
assertTrue(master.removePeerCalled);
assertTrue(master.updatePeerConfigCalled);
assertTrue(master.enablePeerCalled);
assertTrue(master.disablePeerCalled);
}
内容来源于网络,如有侵权,请联系作者删除!