@InterfaceAudience.Private public class FSReplicationPeerStorage extends Object implements ReplicationPeerStorage
hbase | --peers | --<peer_id> | --peer_config | --disabled | --sync-rep-stateNotice that, if the peer is enabled, we will not have a disabled file. And for other files, to avoid depending on atomic rename, we will use two files for storing the content. When loading, we will try to read both the files and load the newer one. And when writing, we will write to the older file.
Modifier and Type | Field and Description |
---|---|
private org.apache.hadoop.fs.Path |
dir |
(package private) static String |
DISABLED_FILE |
private org.apache.hadoop.fs.FileSystem |
fs |
private static org.slf4j.Logger |
LOG |
private static long |
MAX_FILE_SIZE |
(package private) static byte[] |
NONE_STATE_BYTES |
(package private) static String |
PEER_CONFIG_FILE |
static String |
PEERS_DIR |
static String |
PEERS_DIR_DEFAULT |
(package private) static String |
SYNC_REPLICATION_STATE_FILE |
Constructor and Description |
---|
FSReplicationPeerStorage(org.apache.hadoop.fs.FileSystem fs,
org.apache.hadoop.conf.Configuration conf) |
Modifier and Type | Method and Description |
---|---|
void |
addPeer(String peerId,
ReplicationPeerConfig peerConfig,
boolean enabled,
SyncReplicationState syncReplicationState)
Add a replication peer.
|
private static void |
delete(org.apache.hadoop.fs.FileSystem fs,
org.apache.hadoop.fs.Path dir,
String name) |
ReplicationPeerConfig |
getPeerConfig(String peerId)
Get the peer config of a replication peer.
|
(package private) org.apache.hadoop.fs.Path |
getPeerDir(String peerId) |
SyncReplicationState |
getPeerNewSyncReplicationState(String peerId)
Get the new sync replication state.
|
SyncReplicationState |
getPeerSyncReplicationState(String peerId)
Get the sync replication state.
|
private Pair<SyncReplicationState,SyncReplicationState> |
getStateAndNewState(String peerId) |
boolean |
isPeerEnabled(String peerId)
Test whether a replication peer is enabled.
|
List<String> |
listPeerIds()
Return the peer ids of all replication peers.
|
private static byte[] |
read(org.apache.hadoop.fs.FileSystem fs,
org.apache.hadoop.fs.Path dir,
String name) |
void |
removePeer(String peerId)
Remove a replication peer.
|
void |
setPeerNewSyncReplicationState(String peerId,
SyncReplicationState newState)
Set the new sync replication state that we are going to transit to.
|
void |
setPeerState(String peerId,
boolean enabled)
Set the state of peer,
true to ENABLED , otherwise to DISABLED . |
void |
transitPeerSyncReplicationState(String peerId)
Overwrite the sync replication state with the new sync replication state which is set with the
ReplicationPeerStorage.setPeerNewSyncReplicationState(String, SyncReplicationState) method above, and clear
the new sync replication state. |
void |
updatePeerConfig(String peerId,
ReplicationPeerConfig peerConfig)
Update the config a replication peer.
|
private static void |
write(org.apache.hadoop.fs.FileSystem fs,
org.apache.hadoop.fs.Path dir,
String name,
byte[] data) |
private static final org.slf4j.Logger LOG
public static final String PEERS_DIR
public static final String PEERS_DIR_DEFAULT
static final String PEER_CONFIG_FILE
static final String DISABLED_FILE
static final String SYNC_REPLICATION_STATE_FILE
static final byte[] NONE_STATE_BYTES
private final org.apache.hadoop.fs.FileSystem fs
private final org.apache.hadoop.fs.Path dir
private static final long MAX_FILE_SIZE
public FSReplicationPeerStorage(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.conf.Configuration conf) throws IOException
IOException
org.apache.hadoop.fs.Path getPeerDir(String peerId)
public void addPeer(String peerId, ReplicationPeerConfig peerConfig, boolean enabled, SyncReplicationState syncReplicationState) throws ReplicationException
ReplicationPeerStorage
addPeer
in interface ReplicationPeerStorage
ReplicationException
- if there are errors accessing the storage service.public void removePeer(String peerId) throws ReplicationException
ReplicationPeerStorage
removePeer
in interface ReplicationPeerStorage
ReplicationException
- if there are errors accessing the storage service.public void setPeerState(String peerId, boolean enabled) throws ReplicationException
ReplicationPeerStorage
true
to ENABLED
, otherwise to DISABLED
.setPeerState
in interface ReplicationPeerStorage
ReplicationException
- if there are errors accessing the storage service.public void updatePeerConfig(String peerId, ReplicationPeerConfig peerConfig) throws ReplicationException
ReplicationPeerStorage
updatePeerConfig
in interface ReplicationPeerStorage
ReplicationException
- if there are errors accessing the storage service.public List<String> listPeerIds() throws ReplicationException
ReplicationPeerStorage
listPeerIds
in interface ReplicationPeerStorage
ReplicationException
- if there are errors accessing the storage service.public boolean isPeerEnabled(String peerId) throws ReplicationException
ReplicationPeerStorage
isPeerEnabled
in interface ReplicationPeerStorage
ReplicationException
- if there are errors accessing the storage service.public ReplicationPeerConfig getPeerConfig(String peerId) throws ReplicationException
ReplicationPeerStorage
getPeerConfig
in interface ReplicationPeerStorage
ReplicationException
- if there are errors accessing the storage service.private Pair<SyncReplicationState,SyncReplicationState> getStateAndNewState(String peerId) throws IOException
IOException
public void setPeerNewSyncReplicationState(String peerId, SyncReplicationState newState) throws ReplicationException
ReplicationPeerStorage
setPeerNewSyncReplicationState
in interface ReplicationPeerStorage
ReplicationException
- if there are errors accessing the storage service.public void transitPeerSyncReplicationState(String peerId) throws ReplicationException
ReplicationPeerStorage
ReplicationPeerStorage.setPeerNewSyncReplicationState(String, SyncReplicationState)
method above, and clear
the new sync replication state.transitPeerSyncReplicationState
in interface ReplicationPeerStorage
ReplicationException
- if there are errors accessing the storage service.public SyncReplicationState getPeerSyncReplicationState(String peerId) throws ReplicationException
ReplicationPeerStorage
getPeerSyncReplicationState
in interface ReplicationPeerStorage
ReplicationException
- if there are errors accessing the storage service.public SyncReplicationState getPeerNewSyncReplicationState(String peerId) throws ReplicationException
ReplicationPeerStorage
SyncReplicationState.NONE
if we are not
in a transition.getPeerNewSyncReplicationState
in interface ReplicationPeerStorage
ReplicationException
- if there are errors accessing the storage service.private static byte[] read(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path dir, String name) throws IOException
IOException
private static void write(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path dir, String name, byte[] data) throws IOException
IOException
private static void delete(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path dir, String name) throws IOException
IOException
Copyright © 2007–2020 The Apache Software Foundation. All rights reserved.