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-state
Notice 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
FieldsModifier and TypeFieldDescriptionprivate final org.apache.hadoop.fs.Path(package private) static final Stringprivate final org.apache.hadoop.fs.FileSystemprivate static final org.slf4j.Loggerprivate static final long(package private) static final byte[](package private) static final Stringstatic final Stringstatic final String(package private) static final String -
Constructor Summary
ConstructorsConstructorDescriptionFSReplicationPeerStorage(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.conf.Configuration conf) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddPeer(String peerId, ReplicationPeerConfig peerConfig, boolean enabled, SyncReplicationState syncReplicationState) Add a replication peer.private static voidgetPeerConfig(String peerId) Get the peer config of a replication peer.(package private) org.apache.hadoop.fs.PathgetPeerDir(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) booleanisPeerEnabled(String peerId) Test whether a replication peer is enabled.Return the peer ids of all replication peers.private static byte[]voidremovePeer(String peerId) Remove a replication peer.voidsetPeerNewSyncReplicationState(String peerId, SyncReplicationState newState) Set the new sync replication state that we are going to transit to.voidsetPeerState(String peerId, boolean enabled) Set the state of peer,truetoENABLED, otherwise toDISABLED.voidOverwrite 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.voidupdatePeerConfig(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:ReplicationPeerStorageAdd a replication peer.- Specified by:
addPeerin interfaceReplicationPeerStorage- Throws:
ReplicationException- if there are errors accessing the storage service.
-
removePeer
Description copied from interface:ReplicationPeerStorageRemove a replication peer.- Specified by:
removePeerin interfaceReplicationPeerStorage- Throws:
ReplicationException- if there are errors accessing the storage service.
-
setPeerState
Description copied from interface:ReplicationPeerStorageSet the state of peer,truetoENABLED, otherwise toDISABLED.- Specified by:
setPeerStatein 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:ReplicationPeerStorageUpdate the config a replication peer.- Specified by:
updatePeerConfigin interfaceReplicationPeerStorage- Throws:
ReplicationException- if there are errors accessing the storage service.
-
listPeerIds
Description copied from interface:ReplicationPeerStorageReturn the peer ids of all replication peers.- Specified by:
listPeerIdsin interfaceReplicationPeerStorage- Throws:
ReplicationException- if there are errors accessing the storage service.
-
isPeerEnabled
Description copied from interface:ReplicationPeerStorageTest whether a replication peer is enabled.- Specified by:
isPeerEnabledin interfaceReplicationPeerStorage- Throws:
ReplicationException- if there are errors accessing the storage service.
-
getPeerConfig
Description copied from interface:ReplicationPeerStorageGet the peer config of a replication peer.- Specified by:
getPeerConfigin 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:ReplicationPeerStorageSet the new sync replication state that we are going to transit to.- Specified by:
setPeerNewSyncReplicationStatein interfaceReplicationPeerStorage- Throws:
ReplicationException- if there are errors accessing the storage service.
-
transitPeerSyncReplicationState
Description copied from interface:ReplicationPeerStorageOverwrite 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:
transitPeerSyncReplicationStatein interfaceReplicationPeerStorage- Throws:
ReplicationException- if there are errors accessing the storage service.
-
getPeerSyncReplicationState
Description copied from interface:ReplicationPeerStorageGet the sync replication state.- Specified by:
getPeerSyncReplicationStatein interfaceReplicationPeerStorage- Throws:
ReplicationException- if there are errors accessing the storage service.
-
getPeerNewSyncReplicationState
public SyncReplicationState getPeerNewSyncReplicationState(String peerId) throws ReplicationException Description copied from interface:ReplicationPeerStorageGet the new sync replication state. Will returnSyncReplicationState.NONEif we are not in a transition.- Specified by:
getPeerNewSyncReplicationStatein 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
-