wchevreuil commented on a change in pull request #819: HBASE-23285  Sometimes 
walArchiveDir does not exist when separate the old WALs into different 
regionserver directories
URL: https://github.com/apache/hbase/pull/819#discussion_r346277342
 
 

 ##########
 File path: 
hbase-server/src/test/java/org/apache/hadoop/hbase/master/cleaner/TestSeparateOldWALCleaner.java
 ##########
 @@ -0,0 +1,186 @@
+/**
+ * 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.master.cleaner;
+
+import java.io.IOException;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.hbase.HBaseClassTestRule;
+import org.apache.hadoop.hbase.HBaseTestingUtility;
+import org.apache.hadoop.hbase.HConstants;
+import org.apache.hadoop.hbase.MiniHBaseCluster;
+import org.apache.hadoop.hbase.StartMiniClusterOption;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.client.Admin;
+import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder;
+import org.apache.hadoop.hbase.client.Put;
+import org.apache.hadoop.hbase.client.RegionInfo;
+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.regionserver.HRegion;
+import org.apache.hadoop.hbase.regionserver.HRegionServer;
+import org.apache.hadoop.hbase.testclassification.SmallTests;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.hadoop.hbase.util.CommonFSUtils;
+import org.apache.hadoop.hbase.wal.AbstractFSWALProvider;
+import org.apache.hadoop.hbase.wal.WAL;
+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.TestName;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * Test separate old wal deletion as logs are rolled.
+ */
+@Category(SmallTests.class)
+public class TestSeparateOldWALCleaner  {
+
+  @ClassRule
+  public static final HBaseClassTestRule CLASS_RULE =
+      HBaseClassTestRule.forClass(TestSeparateOldWALCleaner.class);
+
+  private static final Logger LOG =
+      LoggerFactory.getLogger(TestSeparateOldWALCleaner.class);
+  protected HRegionServer server;
+  protected String tableName;
+  protected byte[] value;
+  protected FileSystem fs;
+  protected MiniDFSCluster dfsCluster;
+  protected Admin admin;
+  protected MiniHBaseCluster cluster;
+  protected static final HBaseTestingUtility TEST_UTIL =
+      new HBaseTestingUtility();
+  @Rule
+  public final TestName name = new TestName();
+
+  public TestSeparateOldWALCleaner()  {
+    this.server = null;
+    this.tableName = null;
+
+    String className = this.getClass().getName();
+    StringBuilder v = new StringBuilder(className);
+    while (v.length() < 1000) {
+      v.append(className);
+    }
+    this.value = Bytes.toBytes(v.toString());
+  }
+
+  // Need to override this setup so we can edit the config before it gets sent
+  // to the HDFS & HBase cluster startup.
+  @BeforeClass
+  public static void setUpBeforeClass() throws Exception {
+
+    Configuration conf = TEST_UTIL.getConfiguration();
+    conf.setBoolean("hbase.separate.oldlogdir.by.regionserver",true);
+  }
+
+  @Before
+  public void setUp() throws Exception {
+    // Use 2 DataNodes and default values for other StartMiniCluster options.
+    
TEST_UTIL.startMiniCluster(StartMiniClusterOption.builder().numDataNodes(2).build());
+
+    cluster = TEST_UTIL.getHBaseCluster();
+    dfsCluster = TEST_UTIL.getDFSCluster();
+    fs = TEST_UTIL.getTestFileSystem();
+    admin = TEST_UTIL.getAdmin();
+
+    // disable region rebalancing (interferes with log watching)
+    cluster.getMaster().balanceSwitch(false);
+  }
+
+  @After
+  public void tearDown() throws Exception  {
+    TEST_UTIL.shutdownMiniCluster();
+  }
+
+  protected void startAndWriteData() throws IOException, InterruptedException {
+    TEST_UTIL.getConnection().getTable(TableName.META_TABLE_NAME);
+    this.server = cluster.getRegionServerThreads().get(0).getRegionServer();
+
+    Table table = createTestTable();
+    server = TEST_UTIL.getRSForFirstRegionInTable(table.getName());
+    for (int i = 1; i <= 32; i++) {
+      doPut(table, i);
+      if (i % 4 == 0) {
+        try {
+          Thread.sleep(1000);
+        } catch (InterruptedException e) {
+          // continue
+        }
+      }
+    }
+  }
+
+  /**
+   * Tests that oldWALs/rs are deleted
+   */
+  @Test
+  public void testCleanedRSLogRolling() throws Exception {
+    this.tableName = getName();
+    startAndWriteData();
+    RegionInfo region = 
server.getRegions(TableName.valueOf(tableName)).get(0).getRegionInfo();
+    final WAL log = server.getWAL(region);
+    LOG.info("there are " + AbstractFSWALProvider.getNumRolledLogFiles(log) + 
" log files");
+
+    // flush all regions
+    for (HRegion r : server.getOnlineRegionsLocalContext()) {
+      r.flush(true);
+    }
+
+    //start cleaner chore
+    Configuration conf = TEST_UTIL.getConfiguration();
+    Path rootdir = CommonFSUtils.getWALRootDir(conf);
+    Path OLD_WALS_DIR =
+        new Path(rootdir, HConstants.HREGION_OLDLOGDIR_NAME);
+    DirScanPool POOL = new DirScanPool(TEST_UTIL.getConfiguration());
+    LogCleaner cleaner = new LogCleaner(100, server, conf, fs, OLD_WALS_DIR, 
POOL);
+    Thread thread = new Thread(() -> cleaner.chore());
+    thread.setDaemon(true);
+    thread.start();
+
+    // Now roll the log
+    log.rollWriter();
 
 Review comment:
   We must assert what we are testing in this method. If we want to validate 
that wal file got deleted from the given RS oldWAL dir, then we should verify 
that the given folder is now empty. 

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


With regards,
Apache Git Services

Reply via email to