@InterfaceAudience.Private public class ReplicationSourceManager extends Object implements ReplicationListener
When a region server dies, this class uses a watcher to get notified and it tries to grab a lock in order to transfer all the queues in a local old source.
Synchronization specification:
sources
. sources
is a ConcurrentHashMap and there
is a Lock for peer id in PeerProcedureHandlerImpl
. So there is no race for peer
operations.walsById
. There are four methods which modify it,
addPeer(String)
, removePeer(String)
,
cleanOldLogs(NavigableSet, String, boolean, String)
and preLogRoll(Path)
.
walsById
is a ConcurrentHashMap and there is a Lock for peer id in
PeerProcedureHandlerImpl
. So there is no race between addPeer(String)
and
removePeer(String)
. cleanOldLogs(NavigableSet, String, boolean, String)
is
called by ReplicationSourceInterface
. So no race with addPeer(String)
.
removePeer(String)
will terminate the ReplicationSourceInterface
firstly, then
remove the wals from walsById
. So no race with removePeer(String)
. The only
case need synchronized is cleanOldLogs(NavigableSet, String, boolean, String)
and
preLogRoll(Path)
.walsByIdRecoveredQueues
. There are three methods which
modify it, removePeer(String)
,
cleanOldLogs(NavigableSet, String, boolean, String)
and
ReplicationSourceManager.NodeFailoverWorker.run()
.
cleanOldLogs(NavigableSet, String, boolean, String)
is called by
ReplicationSourceInterface
. removePeer(String)
will terminate the
ReplicationSourceInterface
firstly, then remove the wals from
walsByIdRecoveredQueues
. And ReplicationSourceManager.NodeFailoverWorker.run()
will add the wals to walsByIdRecoveredQueues
firstly, then start up a
ReplicationSourceInterface
. So there is no race here. For
ReplicationSourceManager.NodeFailoverWorker.run()
and removePeer(String)
, there
is already synchronized on oldsources
. So no need synchronized on
walsByIdRecoveredQueues
.latestPaths
to avoid the new open source miss new log.oldsources
to avoid adding recovered source for the
to-be-removed peer.Constructor and Description |
---|
ReplicationSourceManager(ReplicationQueueStorage queueStorage,
ReplicationPeers replicationPeers,
ReplicationTracker replicationTracker,
org.apache.hadoop.conf.Configuration conf,
Server server,
org.apache.hadoop.fs.FileSystem fs,
org.apache.hadoop.fs.Path logDir,
org.apache.hadoop.fs.Path oldLogDir,
UUID clusterId,
WALFileLengthProvider walFileLengthProvider)
Creates a replication manager and sets the watch on all the other registered region servers
|
Modifier and Type | Method and Description |
---|---|
void |
addHFileRefs(TableName tableName,
byte[] family,
List<Pair<org.apache.hadoop.fs.Path,org.apache.hadoop.fs.Path>> pairs) |
void |
addPeer(String peerId)
1.
|
void |
cleanUpHFileRefs(String peerId,
List<String> files) |
org.apache.hadoop.fs.FileSystem |
getFs()
Get the handle on the local file system
|
org.apache.hadoop.fs.Path |
getLogDir()
Get the directory where wals are stored by their RSs
|
org.apache.hadoop.fs.Path |
getOldLogDir()
Get the directory where wals are archived
|
List<ReplicationSourceInterface> |
getOldSources()
Get a list of all the recovered sources of this rs
|
ReplicationPeers |
getReplicationPeers()
Get the ReplicationPeers used by this ReplicationSourceManager
|
ReplicationSourceInterface |
getSource(String peerId)
Get the normal source for a given peer
|
List<ReplicationSourceInterface> |
getSources()
Get a list of all the normal sources of this rs
|
String |
getStats()
Get a string representation of all the sources' metrics
|
AtomicLong |
getTotalBufferUsed() |
Map<String,Map<String,NavigableSet<String>>> |
getWALs()
Get a copy of the wals of the normal sources on this rs
|
void |
join()
Terminate the replication on this region server
|
void |
logPositionAndCleanOldLogs(String queueId,
boolean queueRecovered,
org.apache.hadoop.hbase.replication.regionserver.WALEntryBatch entryBatch)
This method will log the current position to storage.
|
void |
postLogRoll(org.apache.hadoop.fs.Path newLog) |
void |
preLogRoll(org.apache.hadoop.fs.Path newLog) |
void |
refreshSources(String peerId)
Close the previous replication sources of this peer id and open new sources to trigger the new
replication state changes or new replication config changes.
|
void |
regionServerRemoved(String regionserver)
A region server has been removed from the local cluster
|
void |
removePeer(String peerId)
1.
|
public ReplicationSourceManager(ReplicationQueueStorage queueStorage, ReplicationPeers replicationPeers, ReplicationTracker replicationTracker, org.apache.hadoop.conf.Configuration conf, Server server, org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path logDir, org.apache.hadoop.fs.Path oldLogDir, UUID clusterId, WALFileLengthProvider walFileLengthProvider) throws IOException
queueStorage
- the interface for manipulating replication queuesreplicationPeers
- replicationTracker
- conf
- the configuration to useserver
- the server for this region serverfs
- the file system to uselogDir
- the directory that contains all wal directories of live RSsoldLogDir
- the directory where old logs are archivedclusterId
- IOException
public void addPeer(String peerId) throws IOException
peerId
- the id of replication peerIOException
public void removePeer(String peerId)
peerId
- the id of the replication peerpublic void refreshSources(String peerId) throws IOException
peerId
- the id of the replication peerIOException
public void logPositionAndCleanOldLogs(String queueId, boolean queueRecovered, org.apache.hadoop.hbase.replication.regionserver.WALEntryBatch entryBatch)
queueId
- id of the replication queuequeueRecovered
- indicates if this queue comes from another region serverentryBatch
- the wal entry batch we just shippedpublic void preLogRoll(org.apache.hadoop.fs.Path newLog) throws IOException
IOException
public void postLogRoll(org.apache.hadoop.fs.Path newLog) throws IOException
IOException
public void regionServerRemoved(String regionserver)
ReplicationListener
regionServerRemoved
in interface ReplicationListener
regionserver
- the removed region serverpublic void join()
public Map<String,Map<String,NavigableSet<String>>> getWALs()
public List<ReplicationSourceInterface> getSources()
public List<ReplicationSourceInterface> getOldSources()
public ReplicationSourceInterface getSource(String peerId)
public AtomicLong getTotalBufferUsed()
public org.apache.hadoop.fs.Path getOldLogDir()
public org.apache.hadoop.fs.Path getLogDir()
public org.apache.hadoop.fs.FileSystem getFs()
public ReplicationPeers getReplicationPeers()
public String getStats()
public void addHFileRefs(TableName tableName, byte[] family, List<Pair<org.apache.hadoop.fs.Path,org.apache.hadoop.fs.Path>> pairs) throws IOException
IOException
Copyright © 2007–2019 Cloudera. All rights reserved.