PageRenderTime 59ms CodeModel.GetById 7ms RepoModel.GetById 1ms app.codeStats 0ms

/src/test/java/org/apache/hadoop/hbase/regionserver/wal/TestLogRollAbort.java

http://github.com/apache/hbase
Java | 173 lines | 108 code | 25 blank | 40 comment | 0 complexity | 1472ec8e046e652042781b7162069c4e MD5 | raw file
Possible License(s): Apache-2.0, MIT
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. package org.apache.hadoop.hbase.regionserver.wal;
  19. import static org.junit.Assert.assertTrue;
  20. import static org.junit.Assert.fail;
  21. import java.io.IOException;
  22. import org.apache.commons.logging.Log;
  23. import org.apache.commons.logging.LogFactory;
  24. import org.apache.commons.logging.impl.Log4JLogger;
  25. import org.apache.hadoop.fs.FileSystem;
  26. import org.apache.hadoop.hbase.*;
  27. import org.apache.hadoop.hbase.client.HBaseAdmin;
  28. import org.apache.hadoop.hbase.client.HTable;
  29. import org.apache.hadoop.hbase.client.Put;
  30. import org.apache.hadoop.hbase.regionserver.HRegion;
  31. import org.apache.hadoop.hbase.regionserver.HRegionServer;
  32. import org.apache.hadoop.hbase.util.Bytes;
  33. import org.apache.hadoop.hbase.util.FSUtils;
  34. import org.apache.hadoop.hdfs.DFSClient;
  35. import org.apache.hadoop.hdfs.MiniDFSCluster;
  36. import org.apache.hadoop.hdfs.server.datanode.DataNode;
  37. import org.apache.hadoop.hdfs.server.namenode.LeaseManager;
  38. import org.apache.log4j.Level;
  39. import org.junit.After;
  40. import org.junit.Before;
  41. import org.junit.BeforeClass;
  42. import org.junit.Test;
  43. import org.junit.experimental.categories.Category;
  44. /**
  45. * Tests for conditions that should trigger RegionServer aborts when
  46. * rolling the current HLog fails.
  47. */
  48. @Category(MediumTests.class)
  49. public class TestLogRollAbort {
  50. private static final Log LOG = LogFactory.getLog(TestLogRolling.class);
  51. private static MiniDFSCluster dfsCluster;
  52. private static HBaseAdmin admin;
  53. private static MiniHBaseCluster cluster;
  54. private final static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
  55. // verbose logging on classes that are touched in these tests
  56. {
  57. ((Log4JLogger)DataNode.LOG).getLogger().setLevel(Level.ALL);
  58. ((Log4JLogger)LeaseManager.LOG).getLogger().setLevel(Level.ALL);
  59. ((Log4JLogger)LogFactory.getLog("org.apache.hadoop.hdfs.server.namenode.FSNamesystem"))
  60. .getLogger().setLevel(Level.ALL);
  61. ((Log4JLogger)DFSClient.LOG).getLogger().setLevel(Level.ALL);
  62. ((Log4JLogger)HRegionServer.LOG).getLogger().setLevel(Level.ALL);
  63. ((Log4JLogger)HRegion.LOG).getLogger().setLevel(Level.ALL);
  64. ((Log4JLogger)HLog.LOG).getLogger().setLevel(Level.ALL);
  65. }
  66. // Need to override this setup so we can edit the config before it gets sent
  67. // to the HDFS & HBase cluster startup.
  68. @BeforeClass
  69. public static void setUpBeforeClass() throws Exception {
  70. // Tweak default timeout values down for faster recovery
  71. TEST_UTIL.getConfiguration().setInt(
  72. "hbase.regionserver.logroll.errors.tolerated", 2);
  73. TEST_UTIL.getConfiguration().setInt("ipc.ping.interval", 10 * 1000);
  74. TEST_UTIL.getConfiguration().setInt("ipc.socket.timeout", 10 * 1000);
  75. TEST_UTIL.getConfiguration().setInt("hbase.rpc.timeout", 10 * 1000);
  76. // Increase the amount of time between client retries
  77. TEST_UTIL.getConfiguration().setLong("hbase.client.pause", 5 * 1000);
  78. // make sure log.hflush() calls syncFs() to open a pipeline
  79. TEST_UTIL.getConfiguration().setBoolean("dfs.support.append", true);
  80. // lower the namenode & datanode heartbeat so the namenode
  81. // quickly detects datanode failures
  82. TEST_UTIL.getConfiguration().setInt("heartbeat.recheck.interval", 5000);
  83. TEST_UTIL.getConfiguration().setInt("dfs.heartbeat.interval", 1);
  84. // the namenode might still try to choose the recently-dead datanode
  85. // for a pipeline, so try to a new pipeline multiple times
  86. TEST_UTIL.getConfiguration().setInt("dfs.client.block.write.retries", 10);
  87. // set periodic sync to 2 min so it doesn't run during test
  88. TEST_UTIL.getConfiguration().setInt("hbase.regionserver.optionallogflushinterval",
  89. 120 * 1000);
  90. }
  91. @Before
  92. public void setUp() throws Exception {
  93. TEST_UTIL.startMiniCluster(2);
  94. cluster = TEST_UTIL.getHBaseCluster();
  95. dfsCluster = TEST_UTIL.getDFSCluster();
  96. admin = TEST_UTIL.getHBaseAdmin();
  97. // disable region rebalancing (interferes with log watching)
  98. cluster.getMaster().balanceSwitch(false);
  99. }
  100. @After
  101. public void tearDown() throws Exception {
  102. TEST_UTIL.shutdownMiniCluster();
  103. }
  104. /**
  105. * Tests that RegionServer aborts if we hit an error closing the WAL when
  106. * there are unsynced WAL edits. See HBASE-4282.
  107. */
  108. @Test
  109. public void testRSAbortWithUnflushedEdits() throws Exception {
  110. LOG.info("Starting testRSAbortWithUnflushedEdits()");
  111. // When the META table can be opened, the region servers are running
  112. new HTable(TEST_UTIL.getConfiguration(),
  113. HConstants.META_TABLE_NAME).close();
  114. // Create the test table and open it
  115. String tableName = this.getClass().getSimpleName();
  116. HTableDescriptor desc = new HTableDescriptor(tableName);
  117. desc.addFamily(new HColumnDescriptor(HConstants.CATALOG_FAMILY));
  118. desc.setDeferredLogFlush(true);
  119. admin.createTable(desc);
  120. HTable table = new HTable(TEST_UTIL.getConfiguration(), tableName);
  121. HRegionServer server = TEST_UTIL.getRSForFirstRegionInTable(Bytes.toBytes(tableName));
  122. HLog log = server.getWAL();
  123. assertTrue("Need HDFS-826 for this test", log.canGetCurReplicas());
  124. // don't run this test without append support (HDFS-200 & HDFS-142)
  125. assertTrue("Need append support for this test",
  126. FSUtils.isAppendSupported(TEST_UTIL.getConfiguration()));
  127. Put p = new Put(Bytes.toBytes("row2001"));
  128. p.add(HConstants.CATALOG_FAMILY, Bytes.toBytes("col"), Bytes.toBytes(2001));
  129. table.put(p);
  130. log.sync();
  131. p = new Put(Bytes.toBytes("row2002"));
  132. p.add(HConstants.CATALOG_FAMILY, Bytes.toBytes("col"), Bytes.toBytes(2002));
  133. table.put(p);
  134. dfsCluster.restartDataNodes();
  135. LOG.info("Restarted datanodes");
  136. assertTrue("Should have an outstanding WAL edit", log.hasDeferredEntries());
  137. try {
  138. log.rollWriter(true);
  139. fail("Log roll should have triggered FailedLogCloseException");
  140. } catch (FailedLogCloseException flce) {
  141. assertTrue("Should have deferred flush log edits outstanding",
  142. log.hasDeferredEntries());
  143. }
  144. }
  145. @org.junit.Rule
  146. public org.apache.hadoop.hbase.ResourceCheckerJUnitRule cu =
  147. new org.apache.hadoop.hbase.ResourceCheckerJUnitRule();
  148. }