Apache9 commented on a change in pull request #2496:
URL: https://github.com/apache/hbase/pull/2496#discussion_r499155825



##########
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:
       Do we need to check whether we have already added the listener? I do not 
think the warmupRegion is the only reason to lead us here, as we will come here 
if meta region is moved out and then moved back?




----------------------------------------------------------------
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]


Reply via email to