Class FSReplicationPeerStorage
java.lang.Object
org.apache.hadoop.hbase.replication.FSReplicationPeerStorage
- All Implemented Interfaces:
ReplicationPeerStorage
A filesystem based replication peer storage. The implementation does not require atomic rename so
you can use it on cloud OSS.
FileSystem layout:
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.
-
Field Summary
Modifier and TypeFieldDescriptionprivate final org.apache.hadoop.fs.Path
(package private) static final String
private final org.apache.hadoop.fs.FileSystem
private static final org.slf4j.Logger
private static final long
(package private) static final byte[]
(package private) static final String
static final String
static final String
(package private) static final String
-
Constructor Summary
ConstructorDescriptionFSReplicationPeerStorage
(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.conf.Configuration conf) -
Method Summary
Modifier and TypeMethodDescriptionvoid
addPeer
(String peerId, ReplicationPeerConfig peerConfig, boolean enabled, SyncReplicationState syncReplicationState) Add a replication peer.private static void
getPeerConfig
(String peerId) Get the peer config of a replication peer.(package private) org.apache.hadoop.fs.Path
getPeerDir
(String peerId) getPeerNewSyncReplicationState
(String peerId) Get the new sync replication state.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.Return the peer ids of all replication peers.private static byte[]
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
toENABLED
, otherwise toDISABLED
.void
Overwrite the sync replication state with the new sync replication state which is set with theReplicationPeerStorage.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
-
Field Details
-
LOG
-
PEERS_DIR
- See Also:
-
PEERS_DIR_DEFAULT
- See Also:
-
PEER_CONFIG_FILE
- See Also:
-
DISABLED_FILE
- See Also:
-
SYNC_REPLICATION_STATE_FILE
- See Also:
-
NONE_STATE_BYTES
-
fs
-
dir
-
MAX_FILE_SIZE
- See Also:
-
-
Constructor Details
-
FSReplicationPeerStorage
public FSReplicationPeerStorage(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.conf.Configuration conf) throws IOException - Throws:
IOException
-
-
Method Details
-
getPeerDir
-
addPeer
public void addPeer(String peerId, ReplicationPeerConfig peerConfig, boolean enabled, SyncReplicationState syncReplicationState) throws ReplicationException Description copied from interface:ReplicationPeerStorage
Add a replication peer.- Specified by:
addPeer
in interfaceReplicationPeerStorage
- Throws:
ReplicationException
- if there are errors accessing the storage service.
-
removePeer
Description copied from interface:ReplicationPeerStorage
Remove a replication peer.- Specified by:
removePeer
in interfaceReplicationPeerStorage
- Throws:
ReplicationException
- if there are errors accessing the storage service.
-
setPeerState
Description copied from interface:ReplicationPeerStorage
Set the state of peer,true
toENABLED
, otherwise toDISABLED
.- Specified by:
setPeerState
in interfaceReplicationPeerStorage
- Throws:
ReplicationException
- if there are errors accessing the storage service.
-
updatePeerConfig
public void updatePeerConfig(String peerId, ReplicationPeerConfig peerConfig) throws ReplicationException Description copied from interface:ReplicationPeerStorage
Update the config a replication peer.- Specified by:
updatePeerConfig
in interfaceReplicationPeerStorage
- Throws:
ReplicationException
- if there are errors accessing the storage service.
-
listPeerIds
Description copied from interface:ReplicationPeerStorage
Return the peer ids of all replication peers.- Specified by:
listPeerIds
in interfaceReplicationPeerStorage
- Throws:
ReplicationException
- if there are errors accessing the storage service.
-
isPeerEnabled
Description copied from interface:ReplicationPeerStorage
Test whether a replication peer is enabled.- Specified by:
isPeerEnabled
in interfaceReplicationPeerStorage
- Throws:
ReplicationException
- if there are errors accessing the storage service.
-
getPeerConfig
Description copied from interface:ReplicationPeerStorage
Get the peer config of a replication peer.- Specified by:
getPeerConfig
in interfaceReplicationPeerStorage
- Throws:
ReplicationException
- if there are errors accessing the storage service.
-
getStateAndNewState
private Pair<SyncReplicationState,SyncReplicationState> getStateAndNewState(String peerId) throws IOException - Throws:
IOException
-
setPeerNewSyncReplicationState
public void setPeerNewSyncReplicationState(String peerId, SyncReplicationState newState) throws ReplicationException Description copied from interface:ReplicationPeerStorage
Set the new sync replication state that we are going to transit to.- Specified by:
setPeerNewSyncReplicationState
in interfaceReplicationPeerStorage
- Throws:
ReplicationException
- if there are errors accessing the storage service.
-
transitPeerSyncReplicationState
Description copied from interface:ReplicationPeerStorage
Overwrite the sync replication state with the new sync replication state which is set with theReplicationPeerStorage.setPeerNewSyncReplicationState(String, SyncReplicationState)
method above, and clear the new sync replication state.- Specified by:
transitPeerSyncReplicationState
in interfaceReplicationPeerStorage
- Throws:
ReplicationException
- if there are errors accessing the storage service.
-
getPeerSyncReplicationState
Description copied from interface:ReplicationPeerStorage
Get the sync replication state.- Specified by:
getPeerSyncReplicationState
in interfaceReplicationPeerStorage
- Throws:
ReplicationException
- if there are errors accessing the storage service.
-
getPeerNewSyncReplicationState
public SyncReplicationState getPeerNewSyncReplicationState(String peerId) throws ReplicationException Description copied from interface:ReplicationPeerStorage
Get the new sync replication state. Will returnSyncReplicationState.NONE
if we are not in a transition.- Specified by:
getPeerNewSyncReplicationState
in interfaceReplicationPeerStorage
- Throws:
ReplicationException
- if there are errors accessing the storage service.
-
read
private static byte[] read(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path dir, String name) throws IOException - Throws:
IOException
-
write
private static void write(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path dir, String name, byte[] data) throws IOException - Throws:
IOException
-
delete
private static void delete(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path dir, String name) throws IOException - Throws:
IOException
-