saintstack commented on a change in pull request #2496:
URL: https://github.com/apache/hbase/pull/2496#discussion_r499705325
##########
File path:
hbase-server/src/main/java/org/apache/hadoop/hbase/replication/regionserver/ReplicationSourceManager.java
##########
@@ -1181,57 +1184,63 @@ MetricsReplicationGlobalSourceSource getGlobalMetrics()
{
/**
* Add an hbase:meta Catalog replication source. Called on open of an
hbase:meta Region.
- * @see #removeCatalogReplicationSource()
+ * Create it once only. If exists already, use the existing one.
+ * @see #removeCatalogReplicationSource(RegionInfo)
*/
- public ReplicationSourceInterface addCatalogReplicationSource() throws
IOException {
- // Open/Create the hbase:meta ReplicationSource once only.
+ public ReplicationSourceInterface addCatalogReplicationSource(RegionInfo
regionInfo)
+ throws IOException {
+ // Poor-man's putIfAbsent
synchronized (this.catalogReplicationSource) {
ReplicationSourceInterface rs = this.catalogReplicationSource.get();
return rs != null ? rs :
-
this.catalogReplicationSource.getAndSet(createCatalogReplicationSource());
+
this.catalogReplicationSource.getAndSet(createCatalogReplicationSource(regionInfo));
}
}
/**
* Remove the hbase:meta Catalog replication source.
* Called when we close hbase:meta.
- * @see #addCatalogReplicationSource()
+ * @see #addCatalogReplicationSource(RegionInfo regionInfo)
*/
- public void removeCatalogReplicationSource() {
+ public void removeCatalogReplicationSource(RegionInfo regionInfo) {
// Nothing to do. Leave any CatalogReplicationSource in place in case an
hbase:meta Region
// comes back to this server.
}
/**
* Create, initialize, and start the Catalog ReplicationSource.
*/
- private ReplicationSourceInterface createCatalogReplicationSource() throws
IOException {
- // Has the hbase:meta WALProvider been instantiated?
+ private ReplicationSourceInterface createCatalogReplicationSource(RegionInfo
regionInfo)
+ throws IOException {
+ // Instantiate walProvider if not done already. Can be instantiated here
but also over
+ // in the #warmupRegion call made by the Master on a 'move' operation.
+ // We need to do extra work if we did NOT instantiate the provider.
WALProvider walProvider = this.walFactory.getMetaWALProvider();
- boolean addListener = false;
- if (walProvider == null) {
- // The meta walProvider has not been instantiated. Create it.
+ boolean instantiate = walProvider == null;
+ if (instantiate) {
+ // Instantiate the meta walProvider.
walProvider = this.walFactory.getMetaProvider();
- addListener = true;
}
CatalogReplicationSourcePeer peer = new
CatalogReplicationSourcePeer(this.conf,
this.clusterId.toString(), "meta_" +
ServerRegionReplicaUtil.REGION_REPLICA_REPLICATION_PEER);
final ReplicationSourceInterface crs = new CatalogReplicationSource();
crs.init(conf, fs, this, new NoopReplicationQueueStorage(), peer, server,
peer.getId(),
clusterId, walProvider.getWALFileLengthProvider(), new
MetricsSource(peer.getId()));
- if (addListener) {
- walProvider.addWALActionsListener(new WALActionsListener() {
- @Override
- public void postLogRoll(Path oldPath, Path newPath) throws IOException
{
- crs.enqueueLog(newPath);
- }
- });
- } else {
- // This is a problem. We'll have a ReplicationSource but no listener on
hbase:meta WALs
- // so nothing will be replicated.
- LOG.error("Did not install WALActionsListener creating
CatalogReplicationSource!");
+ WALActionsListener listener = new WALActionsListener() {
+ @Override public void postLogRoll(Path oldPath, Path newPath) throws
IOException {
+ crs.enqueueLog(newPath);
+ }
+ };
+ walProvider.addWALActionsListener(listener);
+ if (!instantiate) {
+ // If we did not instantiate provider, need to add our listener on
already-created WAL
+ // instance too (listeners are passed by provider to WAL instance on
creation but if provider
+ // created already, our listener add above is missed). Add the current
WAL file to the
+ // Replication Source so it can start replicating it.
+ WAL wal = walProvider.getWAL(regionInfo);
Review comment:
Thanks for taking a look.
The reasoning is that this is the one place we add a listener on the meta
WALProvider which we only visit once when we create the meta ReplicationSource
Let me add more doc on this to try and make it more clear.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]