wchevreuil commented on a change in pull request #2960:
URL: https://github.com/apache/hbase/pull/2960#discussion_r578368537
##########
File path:
hbase-client/src/main/java/org/apache/hadoop/hbase/replication/ReplicationQueuesZKImpl.java
##########
@@ -132,17 +132,45 @@ public void addLog(String queueId, String filename)
throws ReplicationException
}
@Override
- public void removeLog(String queueId, String filename) {
+ public void removeLog(String queueId, String filename)
+ throws ReplicationSourceWithoutPeerException {
try {
- String znode = ZKUtil.joinZNode(this.myQueuesZnode, queueId);
- znode = ZKUtil.joinZNode(znode, filename);
- ZKUtil.deleteNode(this.zookeeper, znode);
- } catch (KeeperException e) {
- this.abortable.abort("Failed to remove wal from queue (queueId=" +
queueId + ", filename="
- + filename + ")", e);
+ try {
+ String znode = ZKUtil.joinZNode(this.myQueuesZnode, queueId);
+ znode = ZKUtil.joinZNode(znode, filename);
+ ZKUtil.deleteNode(this.zookeeper, znode);
+ } catch (KeeperException e) {
+ // in case of no node exception we should not crash the region server
+ // but instead check if the replication peer has been removed.
+ // If so, we can throw here so that the source can terminate itself.
+ // This situation can occur when the replication peer znodes has been
+ // removed but the sources not terminated due to any miss from zk node
delete watcher.
+ if (e instanceof KeeperException.NoNodeException) {
+ if (!doesPeerExist(queueId)) {
+ LOG.warn("Replication peer " + queueId + " has been removed", e);
+ throw new ReplicationSourceWithoutPeerException(
+ "Znodes for peer has been delete where as source is still
active", e);
Review comment:
nit: "a source", not "as source"
##########
File path:
hbase-client/src/main/java/org/apache/hadoop/hbase/replication/ReplicationSourceWithoutPeerException.java
##########
@@ -0,0 +1,37 @@
+/**
+ * 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;
+
+import org.apache.hadoop.hbase.classification.InterfaceAudience;
+
+/**
+ * This exception is thrown when attempts to read an HFile fail due to
corruption or truncation
+ * issues.
+ */
[email protected]
Review comment:
nit: Javadoc description is not consistent.
##########
File path:
hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicationSourceWithoutReplicationZnodes.java
##########
@@ -0,0 +1,234 @@
+/*
+ *
+ * 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.ReplicationSourceDummy.fakeExceptionMessage;
+
+import java.io.IOException;
+import java.net.URLEncoder;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.hbase.ClusterId;
+import org.apache.hadoop.hbase.HBaseConfiguration;
+import org.apache.hadoop.hbase.HBaseTestingUtility;
+import org.apache.hadoop.hbase.HColumnDescriptor;
+import org.apache.hadoop.hbase.HConstants;
+import org.apache.hadoop.hbase.HRegionInfo;
+import org.apache.hadoop.hbase.HTableDescriptor;
+import org.apache.hadoop.hbase.KeyValue;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.regionserver.MultiVersionConcurrencyControl;
+import org.apache.hadoop.hbase.regionserver.wal.WALActionsListener;
+import org.apache.hadoop.hbase.regionserver.wal.WALEdit;
+import org.apache.hadoop.hbase.replication.ReplicationException;
+import
org.apache.hadoop.hbase.replication.ReplicationSourceDummyWithNoTermination;
+import
org.apache.hadoop.hbase.replication.ReplicationSourceWithoutPeerException;
+import org.apache.hadoop.hbase.replication.ReplicationStateZKBase;
+import org.apache.hadoop.hbase.replication.regionserver.helper.DummyServer;
+import org.apache.hadoop.hbase.testclassification.MediumTests;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.hadoop.hbase.util.FSUtils;
+import org.apache.hadoop.hbase.wal.WAL;
+import org.apache.hadoop.hbase.wal.WALFactory;
+import org.apache.hadoop.hbase.wal.WALKey;
+import org.apache.hadoop.hbase.zookeeper.ZKClusterId;
+import org.apache.hadoop.hbase.zookeeper.ZKUtil;
+import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.TestName;
+
+@Category(MediumTests.class)
+public class TestReplicationSourceWithoutReplicationZnodes {
+
+ private static final Log LOG =
+ LogFactory.getLog(TestReplicationSourceManager.class);
+
+ private static Configuration conf;
+
+ private static HBaseTestingUtility utility;
+
+ private static Replication replication;
+
+ private static ReplicationSourceManager manager;
+
+ private static ZooKeeperWatcher zkw;
+
+ private static HTableDescriptor htd;
+
+ private static HRegionInfo hri;
+
+ private static final byte[] r1 = Bytes.toBytes("r1");
+
+ private static final byte[] r2 = Bytes.toBytes("r2");
+
+ private static final byte[] f1 = Bytes.toBytes("f1");
+
+ private static final byte[] f2 = Bytes.toBytes("f2");
+
+ private static final TableName test =
+ TableName.valueOf("test");
+
+ private static final String slaveId = "1";
+
+ private static FileSystem fs;
+
+ private static Path oldLogDir;
+
+ private static Path logDir;
+
+ private static DummyServer server;
+
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception {
+
+ conf = HBaseConfiguration.create();
+ conf.set("replication.replicationsource.implementation",
+ ReplicationSourceDummyWithNoTermination.class.getCanonicalName());
+ conf.setBoolean(HConstants.REPLICATION_ENABLE_KEY,
+ HConstants.REPLICATION_ENABLE_DEFAULT);
+ conf.setLong("replication.sleep.before.failover", 2000);
+ conf.setInt("replication.source.maxretriesmultiplier", 10);
+ utility = new HBaseTestingUtility(conf);
+ utility.startMiniZKCluster();
+
+ zkw = new ZooKeeperWatcher(conf, "test", null);
+ ZKUtil.createWithParents(zkw, "/hbase/replication");
+ ZKUtil.createWithParents(zkw, "/hbase/replication/peers/1");
+ ZKUtil.setData(zkw, "/hbase/replication/peers/1",
+ Bytes.toBytes(conf.get(HConstants.ZOOKEEPER_QUORUM) + ":"
+ + conf.get(HConstants.ZOOKEEPER_CLIENT_PORT) + ":/1"));
+ ZKUtil.createWithParents(zkw, "/hbase/replication/peers/1/peer-state");
+ ZKUtil.setData(zkw, "/hbase/replication/peers/1/peer-state",
+ ReplicationStateZKBase.ENABLED_ZNODE_BYTES);
+ ZKUtil.createWithParents(zkw, "/hbase/replication/state");
+ ZKUtil.setData(zkw, "/hbase/replication/state",
ReplicationStateZKBase.ENABLED_ZNODE_BYTES);
+
+ ZKClusterId.setClusterId(zkw, new ClusterId());
+ FSUtils.setRootDir(utility.getConfiguration(), utility.getDataTestDir());
+ fs = FileSystem.get(conf);
+ oldLogDir = new Path(utility.getDataTestDir(),
+ HConstants.HREGION_OLDLOGDIR_NAME);
+ logDir = new Path(utility.getDataTestDir(),
+ HConstants.HREGION_LOGDIR_NAME);
+ server = new DummyServer(conf, "example.hostname.com", zkw);
+ replication = new Replication(server, fs, logDir, oldLogDir);
+ manager = replication.getReplicationManager();
+
+ manager.addSource(slaveId);
+
+ htd = new HTableDescriptor(test);
+ HColumnDescriptor col = new HColumnDescriptor(f1);
+ col.setScope(HConstants.REPLICATION_SCOPE_GLOBAL);
+ htd.addFamily(col);
+ col = new HColumnDescriptor(f2);
+ col.setScope(HConstants.REPLICATION_SCOPE_LOCAL);
+ htd.addFamily(col);
+
+ hri = new HRegionInfo(htd.getTableName(), r1, r2);
+ }
+
+ @AfterClass
+ public static void tearDownAfterClass() throws Exception {
+ try {
+ manager.join();
+ } catch (RuntimeException re) {
+ if (re.getMessage().equals(fakeExceptionMessage)) {
+ LOG.info("It is fine");
+ }
+ }
+ utility.shutdownMiniCluster();
+ }
+
+ @Rule
+ public TestName testName = new TestName();
+
+ private void cleanLogDir() throws IOException {
+ fs.delete(logDir, true);
+ fs.delete(oldLogDir, true);
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ LOG.info("Start " + testName.getMethodName());
+ cleanLogDir();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ LOG.info("End " + testName.getMethodName());
+ cleanLogDir();
+ }
+
+ /**
+ * When the peer is removed, hbase remove the peer znodes and there is zk
watcher
+ * which terminates the replication sources. In case of zk watcher not
getting invoked
+ * or a race condition between source deleting the log znode and zk watcher
+ * terminating the source, we might get the NoNode exception. In that case,
the right
+ * thing is to terminate the replication source.
Review comment:
> In case of zk watcher not getting invoked or a race condition between
source deleting the log znode and zk watcher terminating the source
I'm struggling to understand how this is possible without manually deleting
the znodes (which is not a valid scenario).
The only place I see updating log position (eventually calling
ReplicationQueuesZKImpl.removeLog) is the SourceShipperThread, which is
_terminated_ in ReplicationSouceManager.removePeer.
Mind sharing a real world condition where you had identified this problem?
----------------------------------------------------------------
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]