use of org.apache.hadoop.hbase.replication.ReplicationPeerDescription in project hbase by apache.
the class TestReplicationAdmin method testPeerConfig.
/**
* 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);
}
use of org.apache.hadoop.hbase.replication.ReplicationPeerDescription in project hbase by apache.
the class HBaseAdmin method checkAndSyncTableDescToPeers.
/**
* Connect to peer and check the table descriptor on peer:
* <ol>
* <li>Create the same table on peer when not exist.</li>
* <li>Throw an exception if the table already has replication enabled on any of the column
* families.</li>
* <li>Throw an exception if the table exists on peer cluster but descriptors are not same.</li>
* </ol>
* @param tableName name of the table to sync to the peer
* @param splits table split keys
* @throws IOException
*/
private void checkAndSyncTableDescToPeers(final TableName tableName, final byte[][] splits) throws IOException {
List<ReplicationPeerDescription> peers = listReplicationPeers();
if (peers == null || peers.size() <= 0) {
throw new IllegalArgumentException("Found no peer cluster for replication.");
}
for (ReplicationPeerDescription peerDesc : peers) {
if (needToReplicate(tableName, peerDesc)) {
Configuration peerConf = getPeerClusterConfiguration(peerDesc);
try (Connection conn = ConnectionFactory.createConnection(peerConf);
Admin repHBaseAdmin = conn.getAdmin()) {
HTableDescriptor localHtd = getTableDescriptor(tableName);
HTableDescriptor peerHtd = null;
if (!repHBaseAdmin.tableExists(tableName)) {
repHBaseAdmin.createTable(localHtd, splits);
} else {
peerHtd = repHBaseAdmin.getTableDescriptor(tableName);
if (peerHtd == null) {
throw new IllegalArgumentException("Failed to get table descriptor for table " + tableName.getNameAsString() + " from peer cluster " + peerDesc.getPeerId());
}
if (!compareForReplication(peerHtd, localHtd)) {
throw new IllegalArgumentException("Table " + tableName.getNameAsString() + " exists in peer cluster " + peerDesc.getPeerId() + ", but the table descriptors are not same when compared with source cluster." + " Thus can not enable the table's replication switch.");
}
}
}
}
}
}
use of org.apache.hadoop.hbase.replication.ReplicationPeerDescription in project hbase by apache.
the class ReplicationSerDeHelper method toReplicationPeerDescription.
public static ReplicationPeerDescription toReplicationPeerDescription(ReplicationProtos.ReplicationPeerDescription desc) {
boolean enabled = ReplicationProtos.ReplicationState.State.ENABLED == desc.getState().getState();
ReplicationPeerConfig config = convert(desc.getConfig());
return new ReplicationPeerDescription(desc.getId(), enabled, config);
}
use of org.apache.hadoop.hbase.replication.ReplicationPeerDescription in project hbase by apache.
the class HMaster method getReplicationLoad.
public HashMap<String, List<Pair<ServerName, ReplicationLoadSource>>> getReplicationLoad(ServerName[] serverNames) {
List<ReplicationPeerDescription> peerList = this.getReplicationPeerManager().listPeers(null);
if (peerList == null) {
return null;
}
HashMap<String, List<Pair<ServerName, ReplicationLoadSource>>> replicationLoadSourceMap = new HashMap<>(peerList.size());
peerList.stream().forEach(peer -> replicationLoadSourceMap.put(peer.getPeerId(), new ArrayList<>()));
for (ServerName serverName : serverNames) {
List<ReplicationLoadSource> replicationLoadSources = getServerManager().getLoad(serverName).getReplicationLoadSourceList();
for (ReplicationLoadSource replicationLoadSource : replicationLoadSources) {
List<Pair<ServerName, ReplicationLoadSource>> replicationLoadSourceList = replicationLoadSourceMap.get(replicationLoadSource.getPeerID());
if (replicationLoadSourceList == null) {
LOG.debug("{} does not exist, but it exists " + "in znode(/hbase/replication/rs). when the rs restarts, peerId is deleted, so " + "we just need to ignore it", replicationLoadSource.getPeerID());
continue;
}
replicationLoadSourceList.add(new Pair<>(serverName, replicationLoadSource));
}
}
for (List<Pair<ServerName, ReplicationLoadSource>> loads : replicationLoadSourceMap.values()) {
if (loads.size() > 0) {
loads.sort(Comparator.comparingLong(load -> (-1) * load.getSecond().getReplicationLag()));
}
}
return replicationLoadSourceMap;
}
use of org.apache.hadoop.hbase.replication.ReplicationPeerDescription in project hbase by apache.
the class ReplicationPeerConfigUtil method toReplicationPeerDescription.
public static ReplicationPeerDescription toReplicationPeerDescription(ReplicationProtos.ReplicationPeerDescription desc) {
boolean enabled = ReplicationProtos.ReplicationState.State.ENABLED == desc.getState().getState();
ReplicationPeerConfig config = convert(desc.getConfig());
return new ReplicationPeerDescription(desc.getId(), enabled, config, toSyncReplicationState(desc.getSyncReplicationState()));
}
Aggregations