You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hbase.apache.org by GitBox <gi...@apache.org> on 2019/09/12 11:32:52 UTC

[GitHub] [hbase] wchevreuil commented on a change in pull request #566: HBASE-22380 break circle replication when doing bulkload

wchevreuil commented on a change in pull request #566: HBASE-22380 break circle replication when doing bulkload
URL: https://github.com/apache/hbase/pull/566#discussion_r323690611
 
 

 ##########
 File path: hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestBulkLoadReplication.java
 ##########
 @@ -0,0 +1,304 @@
+/**
+ * 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.regionserver;
+
+import static org.apache.hadoop.hbase.HConstants.REPLICATION_CLUSTER_ID;
+import static org.apache.hadoop.hbase.HConstants.REPLICATION_CONF_DIR;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FSDataOutputStream;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.hbase.Cell;
+import org.apache.hadoop.hbase.CellBuilder;
+import org.apache.hadoop.hbase.CellBuilderFactory;
+import org.apache.hadoop.hbase.CellBuilderType;
+import org.apache.hadoop.hbase.HBaseClassTestRule;
+import org.apache.hadoop.hbase.HBaseTestingUtility;
+import org.apache.hadoop.hbase.HConstants;
+import org.apache.hadoop.hbase.KeyValue;
+import org.apache.hadoop.hbase.client.Admin;
+import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder;
+import org.apache.hadoop.hbase.client.Connection;
+import org.apache.hadoop.hbase.client.ConnectionFactory;
+import org.apache.hadoop.hbase.client.Get;
+import org.apache.hadoop.hbase.client.Result;
+import org.apache.hadoop.hbase.client.Table;
+import org.apache.hadoop.hbase.client.TableDescriptor;
+import org.apache.hadoop.hbase.client.TableDescriptorBuilder;
+import org.apache.hadoop.hbase.coprocessor.ObserverContext;
+import org.apache.hadoop.hbase.coprocessor.RegionCoprocessor;
+import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment;
+import org.apache.hadoop.hbase.coprocessor.RegionObserver;
+import org.apache.hadoop.hbase.io.hfile.HFile;
+import org.apache.hadoop.hbase.io.hfile.HFileContext;
+import org.apache.hadoop.hbase.replication.ReplicationPeerConfig;
+import org.apache.hadoop.hbase.replication.TestReplicationBase;
+import org.apache.hadoop.hbase.testclassification.MediumTests;
+import org.apache.hadoop.hbase.testclassification.ReplicationTests;
+import org.apache.hadoop.hbase.tool.BulkLoadHFilesTool;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.hadoop.hbase.util.Pair;
+import org.apache.hadoop.hdfs.MiniDFSCluster;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.TemporaryFolder;
+import org.junit.rules.TestName;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Integration test for bulk load replication. Defines two clusters, with two way replication.
+ * Performs a bulk load on cluster defined by UTIL1 first, asserts the Cell on the bulk loaded file
+ * gets into the related table in UTIL1, then also validates the same got replicated to cluster
+ * UTIL2. Then, bulk loads another file into UTIL2, and checks if related values are present on
+ * UTIL2, and also gets replicated to UTIL1.
+ * It also defines a preBulkLoad coprocessor that is added to all test table regions on each of the
+ * clusters, in order to count amount of times bulk load actually gets invoked. This is to certify
+ * we are not entered in the infinite loop condition addressed by HBASE-22380.
+ */
+@Category({ ReplicationTests.class, MediumTests.class})
+public class TestBulkLoadReplication extends TestReplicationBase {
+
+  @ClassRule
+  public static final HBaseClassTestRule CLASS_RULE =
+    HBaseClassTestRule.forClass(TestBulkLoadReplication.class);
+
+  protected static final Logger LOG =
+    LoggerFactory.getLogger(TestBulkLoadReplication.class);
+
+  private static final String PEER1_CLUSTER_ID = "peer1";
+  private static final String PEER2_CLUSTER_ID = "peer2";
+  private static final String PEER3_CLUSTER_ID = "peer3";
+
+  private static final String PEER_ID1 = "1";
+  private static final String PEER_ID3 = "3";
+
+  private static final AtomicInteger BULK_LOADS_COUNT = new AtomicInteger(0);
+  private static CountDownLatch BULK_LOAD_LATCH;
+
+  private static final HBaseTestingUtility UTIL3 = new HBaseTestingUtility();
+  private static final Configuration CONF3 = UTIL3.getConfiguration();
+  private static Table htable3;
+
+  @Rule
+  public TestName name = new TestName();
+
+  @ClassRule
+  public static TemporaryFolder testFolder = new TemporaryFolder();
+
+  @BeforeClass
+  public static void setUpBeforeClass() throws Exception {
+    setupBulkLoadConfigsForCluster(CONF1, PEER1_CLUSTER_ID);
+    setupBulkLoadConfigsForCluster(CONF2, PEER2_CLUSTER_ID);
+    setupBulkLoadConfigsForCluster(CONF3, PEER3_CLUSTER_ID);
+    setupConfig(UTIL3, "/3");
+    TestReplicationBase.setUpBeforeClass();
+    startThirdCluster();
+  }
+
+  private static void startThirdCluster() throws Exception {
+    LOG.info("Setup Zk to same one from UTIL1 and UTIL2");
+    UTIL3.setZkCluster(UTIL1.getZkCluster());
+    UTIL3.startMiniCluster(NUM_SLAVES1);
+
+    TableDescriptor table = TableDescriptorBuilder.newBuilder(tableName)
+      .setColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(famName).setMaxVersions(100)
+        .setScope(HConstants.REPLICATION_SCOPE_GLOBAL).build())
+      .setColumnFamily(ColumnFamilyDescriptorBuilder.of(noRepfamName)).build();
+
+    Connection connection3 = ConnectionFactory.createConnection(CONF3);
+    try (Admin admin3 = connection3.getAdmin()) {
+      admin3.createTable(table, HBaseTestingUtility.KEYS_FOR_HBA_CREATE_TABLE);
+    }
+    UTIL3.waitUntilAllRegionsAssigned(tableName);
+    htable3 = connection3.getTable(tableName);
+  }
+
+  @Before
+  @Override
+  public void setUpBase() throws Exception {
+    super.setUpBase();
+    ReplicationPeerConfig peer1Config = getPeerConfigForCluster(UTIL1);
+    ReplicationPeerConfig peer2Config = getPeerConfigForCluster(UTIL2);
+    ReplicationPeerConfig peer3Config = getPeerConfigForCluster(UTIL3);
+    //adds cluster1 as a remote peer on cluster2
 
 Review comment:
   I should had made some comments here: this _super.setUpBase()_ call on line #150 already sets replication from 1->2, then on the subsequent lines I'm setting 2->1, 2->3 and 3->2. So we have following topology: "1 <-> 2 <->3". This breaks my original solution (was only tracking bulkoad originator id) in the same way as if I had: "1 -> 2 -> 3 -> 1". Same problem:  a bulk load started by 1 would get replicated to 2 first, then 2 would try replicate to 3 and back to 1 again. 1 would break the loop, as it would find its id as originator, but 3 would sent it back to 2, and then we would get an infinite loop between 2 and 3.   

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services