shahrs87 commented on code in PR #4556:
URL: https://github.com/apache/hbase/pull/4556#discussion_r907662916


##########
hbase-server/src/main/java/org/apache/hadoop/hbase/replication/regionserver/ReplicationMarkerChore.java:
##########
@@ -0,0 +1,118 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase.replication.regionserver;
+
+import static 
org.apache.hadoop.hbase.replication.master.ReplicationSinkTrackerTableCreator.REPLICATION_SINK_TRACKER_TABLE_NAME;
+
+import java.io.IOException;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.ScheduledChore;
+import org.apache.hadoop.hbase.Stoppable;
+import org.apache.hadoop.hbase.client.RegionInfo;
+import org.apache.hadoop.hbase.client.RegionInfoBuilder;
+import org.apache.hadoop.hbase.regionserver.MultiVersionConcurrencyControl;
+import org.apache.hadoop.hbase.regionserver.RegionServerServices;
+import org.apache.hadoop.hbase.regionserver.wal.WALUtil;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
+import org.apache.hadoop.hbase.wal.WAL;
+import org.apache.hadoop.hbase.wal.WALEdit;
+import org.apache.yetus.audience.InterfaceAudience;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * This chore is responsible to create replication marker rows with special 
WALEdit with family as
+ * {@link org.apache.hadoop.hbase.wal.WALEdit#METAFAMILY} and column qualifier 
as
+ * {@link WALEdit#REPLICATION_MARKER} and empty value. If config key
+ * {@link #REPLICATION_MARKER_ENABLED_KEY} is set to true, then we will create 
1 marker row every
+ * {@link #REPLICATION_MARKER_CHORE_DURATION_KEY} ms
+ * {@link 
org.apache.hadoop.hbase.replication.regionserver.ReplicationSourceWALReader} 
will populate
+ * the Replication Marker edit with region_server_name, wal_name and 
wal_offset encoded in
+ * {@link 
org.apache.hadoop.hbase.shaded.protobuf.generated.WALProtos.ReplicationMarkerDescriptor}
+ * object. {@link 
org.apache.hadoop.hbase.replication.regionserver.Replication} will change the
+ * REPLICATION_SCOPE for this edit to GLOBAL so that it can replicate. On the 
sink cluster,
+ * {@link org.apache.hadoop.hbase.replication.regionserver.ReplicationSink} 
will convert the
+ * ReplicationMarkerDescriptor into a Put mutation to 
REPLICATION_SINK_TRACKER_TABLE_NAME_STR table.
+ */
[email protected]
+public class ReplicationMarkerChore extends ScheduledChore {
+  private static final Logger LOG = 
LoggerFactory.getLogger(ReplicationMarkerChore.class);
+  private static final MultiVersionConcurrencyControl MVCC = new 
MultiVersionConcurrencyControl();
+  public static final RegionInfo REGION_INFO =
+    RegionInfoBuilder.newBuilder(REPLICATION_SINK_TRACKER_TABLE_NAME).build();
+  private static final String DELIMITER = "_";
+  private final Configuration conf;
+  private final RegionServerServices rsServices;
+  private WAL wal;
+
+  public static final String REPLICATION_MARKER_ENABLED_KEY =
+    "hbase.regionserver.replication.marker.enabled";
+  public static final boolean REPLICATION_MARKER_ENABLED_DEFAULT = false;
+
+  public static final String REPLICATION_MARKER_CHORE_DURATION_KEY =
+    "hbase.regionserver.replication.marker.chore.duration";
+  public static final int REPLICATION_MARKER_CHORE_DURATION_DEFAULT = 30 * 
1000; // 30 seconds
+
+  public ReplicationMarkerChore(final Stoppable stopper, final 
RegionServerServices rsServices,
+    int period, Configuration conf) {
+    super("ReplicationTrackerChore", stopper, period);
+    this.conf = conf;
+    this.rsServices = rsServices;
+  }
+
+  @Override
+  protected void chore() {
+    if (wal == null) {
+      try {
+        wal = rsServices.getWAL(null);
+      } catch (IOException ioe) {
+        LOG.warn("Unable to get WAL ", ioe);
+        // Shouldn't happen. Ignore and wait for the next chore run.
+        return;
+      }
+    }
+    String serverName = rsServices.getServerName().getServerName();
+    long timeStamp = EnvironmentEdgeManager.currentTime();
+    // We only have timestamp in ReplicationMarkerDescriptor and the remaining 
properties walname,
+    // regionserver name and wal offset at ReplicationSourceWALReaderThread.
+    byte[] rowKey = getRowKey(serverName, timeStamp);
+    if (LOG.isTraceEnabled()) {
+      LOG.trace("Creating replication marker edit.");
+    }
+    try {
+      WALUtil.writeReplicationMarkerAndSync(wal, MVCC, REGION_INFO, rowKey, 
timeStamp);

Review Comment:
   > And for the multi wal support, we do not need to implement it in this PR. 
But let's at least discuss about the design and make sure that we do not need 
to do breaking changes when we want to add the support later. 
   
   What I was thinking is as follows: 
   1. Currently `ReplicationMarkerChore` calls  `rsServices.getWAL` to get the 
current WAL. In multi WAL implementation, we will replace it with 
`rsServices.getWALs` and iterate over all the WALs and create a replication 
marker row for each WAL. This will seamlessly handled via 
ReplicationSourceWALReader class to replicate.
   @Apache9 WDYT ?
   
   > And also, if the feature will be released before we add the multi wal 
support, we need to find a way to make sure that user can not enable multi wal 
and this feature together.
   
   I think it is fine keeping this feature with multi wal support also. I 
tested the test case `TestReplicationMarker` with provider as `multiwal` and it 
worked fine. However it will create marker row for just first WAL but since we 
use this feature just for persisting events to a table, it doesn't cause any 
harm.
   @Apache9  WDYT ?



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

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to