@InterfaceAudience.Public @InterfaceStability.Evolving public class ReplicationAdmin extends Object implements Closeable
This class provides the administrative interface to HBase cluster
replication. In order to use it, the cluster and the client using
ReplicationAdmin must be configured with hbase.replication
set to true.
Adding a new peer results in creating new outbound connections from every region server to a subset of region servers on the slave cluster. Each new stream of replication will start replicating from the beginning of the current WAL, meaning that edits from that past will be replicated.
Removing a peer is a destructive and irreversible operation that stops all the replication streams for the given cluster and deletes the metadata used to keep track of the replication state.
To see which commands are available in the shell, type
replication
.
Modifier and Type | Field and Description |
---|---|
static String |
CFNAME |
private Connection |
connection |
private static org.apache.commons.logging.Log |
LOG |
static String |
REPLICATIONGLOBAL |
private ReplicationPeers |
replicationPeers |
private ReplicationQueuesClient |
replicationQueuesClient |
static String |
REPLICATIONTYPE |
static String |
TNAME |
private ZooKeeperWatcher |
zkw
A watcher used by replicationPeers and replicationQueuesClient.
|
Constructor and Description |
---|
ReplicationAdmin(org.apache.hadoop.conf.Configuration conf)
Constructor that creates a connection to the local ZooKeeper ensemble.
|
Modifier and Type | Method and Description |
---|---|
void |
addPeer(String id,
ReplicationPeerConfig peerConfig,
Map<TableName,? extends Collection<String>> tableCfs)
Add a new remote slave cluster for replication.
|
void |
addPeer(String id,
String clusterKey)
Deprecated.
Use addPeer(String, ReplicationPeerConfig, Map) instead.
|
void |
addPeer(String id,
String clusterKey,
String tableCFs)
Deprecated.
|
void |
appendPeerTableCFs(String id,
Map<TableName,? extends Collection<String>> tableCfs)
Append the replicable table-cf config of the specified peer
|
void |
appendPeerTableCFs(String id,
String tableCfs)
Append the replicable table-cf config of the specified peer
|
private void |
checkAndSyncTableDescToPeers(TableName tableName,
byte[][] splits)
Connect to peer and check the table descriptor on peer:
Create the same table on peer when not exist.
Throw exception if the table exists on peer cluster but descriptors are not same.
|
void |
close() |
private ZooKeeperWatcher |
createZooKeeperWatcher() |
void |
disablePeer(String id)
Stop the replication stream to the specified peer.
|
void |
disableTableRep(TableName tableName)
Disable a table's replication switch.
|
void |
enablePeer(String id)
Restart the replication stream to the specified peer.
|
void |
enableTableRep(TableName tableName)
Enable a table's replication switch.
|
ReplicationPeerConfig |
getPeerConfig(String id) |
int |
getPeersCount()
Get the number of slave clusters the local cluster has.
|
boolean |
getPeerState(String id)
Get the state of the specified peer cluster
|
String |
getPeerTableCFs(String id)
Get the replicable table-cf config of the specified peer.
|
(package private) static String |
getTableCfsStr(Map<TableName,? extends Collection<String>> tableCfs) |
private byte[][] |
getTableSplitRowKeys(TableName tableName)
Get the split row keys of table
|
private boolean |
isTableRepEnabled(HTableDescriptor htd) |
Map<String,ReplicationPeerConfig> |
listPeerConfigs() |
Map<String,String> |
listPeers()
Deprecated.
|
List<HashMap<String,String>> |
listReplicated()
Find all column families that are replicated from this cluster
|
(package private) List<ReplicationPeer> |
listReplicationPeers() |
static Map<TableName,List<String>> |
parseTableCFsFromConfig(String tableCFsConfig) |
void |
removePeer(String id)
Removes a peer cluster and stops the replication to it.
|
void |
removePeerTableCFs(String id,
Map<TableName,? extends Collection<String>> tableCfs)
Remove some table-cfs from config of the specified peer
|
void |
removePeerTableCFs(String id,
String tableCf)
Remove some table-cfs from table-cfs config of the specified peer
|
void |
setPeerTableCFs(String id,
Map<TableName,? extends Collection<String>> tableCfs)
Set the replicable table-cf config of the specified peer
|
void |
setPeerTableCFs(String id,
String tableCFs)
Deprecated.
|
private void |
setTableRep(TableName tableName,
boolean isRepEnabled)
Set the table's replication switch if the table's replication switch is already not set.
|
private static final org.apache.commons.logging.Log LOG
public static final String TNAME
public static final String CFNAME
public static final String REPLICATIONTYPE
public static final String REPLICATIONGLOBAL
private final Connection connection
private final ReplicationQueuesClient replicationQueuesClient
private final ReplicationPeers replicationPeers
private final ZooKeeperWatcher zkw
close()
.public ReplicationAdmin(org.apache.hadoop.conf.Configuration conf) throws IOException
conf
- Configuration to useIOException
- if an internal replication error occursRuntimeException
- if replication isn't enabled.private ZooKeeperWatcher createZooKeeperWatcher() throws IOException
IOException
@Deprecated public void addPeer(String id, String clusterKey) throws ReplicationException
id
- a short name that identifies the clusterclusterKey
- the concatenation of the slave cluster's
hbase.zookeeper.quorum:hbase.zookeeper.property.clientPort:zookeeper.znode.parent
IllegalStateException
- if there's already one slave since
multi-slave isn't supported yet.ReplicationException
@Deprecated public void addPeer(String id, String clusterKey, String tableCFs) throws ReplicationException
ReplicationException
public void addPeer(String id, ReplicationPeerConfig peerConfig, Map<TableName,? extends Collection<String>> tableCfs) throws ReplicationException
id
- a short name that identifies the clusterpeerConfig
- configuration for the replication slave clustertableCfs
- 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
familiesReplicationException
public static Map<TableName,List<String>> parseTableCFsFromConfig(String tableCFsConfig)
static String getTableCfsStr(Map<TableName,? extends Collection<String>> tableCfs)
public void removePeer(String id) throws ReplicationException
id
- a short name that identifies the clusterReplicationException
public void enablePeer(String id) throws ReplicationException
id
- a short name that identifies the clusterReplicationException
public void disablePeer(String id) throws ReplicationException
id
- a short name that identifies the clusterReplicationException
public int getPeersCount()
@Deprecated public Map<String,String> listPeers()
listPeerConfigs()
public Map<String,ReplicationPeerConfig> listPeerConfigs()
public ReplicationPeerConfig getPeerConfig(String id) throws ReplicationException
ReplicationException
public String getPeerTableCFs(String id) throws ReplicationException
id
- a short name that identifies the clusterReplicationException
@Deprecated public void setPeerTableCFs(String id, String tableCFs) throws ReplicationException
setPeerTableCFs(String, Map)
id
- a short name that identifies the clusterReplicationException
public void appendPeerTableCFs(String id, String tableCfs) throws ReplicationException
id
- a short that identifies the clustertableCfs
- table-cfs config strReplicationException
public void appendPeerTableCFs(String id, Map<TableName,? extends Collection<String>> tableCfs) throws ReplicationException
id
- a short that identifies the clustertableCfs
- A map from tableName to column family namesReplicationException
public void removePeerTableCFs(String id, String tableCf) throws ReplicationException
id
- a short name that identifies the clustertableCf
- table-cfs config strReplicationException
public void removePeerTableCFs(String id, Map<TableName,? extends Collection<String>> tableCfs) throws ReplicationException
id
- a short name that identifies the clustertableCfs
- A map from tableName to column family namesReplicationException
public void setPeerTableCFs(String id, Map<TableName,? extends Collection<String>> tableCfs) throws ReplicationException
id
- a short name that identifies the clustertableCfs
- 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
familiesReplicationException
public boolean getPeerState(String id) throws ReplicationException
id
- String format of the Short name that identifies the peer,
an IllegalArgumentException is thrown if it doesn't existReplicationException
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
public List<HashMap<String,String>> listReplicated() throws IOException
IOException
public void enableTableRep(TableName tableName) throws IOException
tableName
- name of the tableIOException
- if a remote or network exception occurspublic void disableTableRep(TableName tableName) throws IOException
tableName
- name of the tableIOException
- if a remote or network exception occursprivate byte[][] getTableSplitRowKeys(TableName tableName) throws IOException
tableName
- table nameIOException
private void checkAndSyncTableDescToPeers(TableName tableName, byte[][] splits) throws IOException
tableName
- name of the table to sync to the peersplits
- table split keysIOException
List<ReplicationPeer> listReplicationPeers()
private void setTableRep(TableName tableName, boolean isRepEnabled) throws IOException
tableName
- name of the tableisRepEnabled
- is replication switch enable or disableIOException
- if a remote or network exception occursprivate boolean isTableRepEnabled(HTableDescriptor htd)
htd
- table descriptor details for the table to checkCopyright © 2007–2019 The Apache Software Foundation. All rights reserved.