1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase.regionserver.wal;
19
20 import static org.junit.Assert.assertTrue;
21 import static org.junit.Assert.fail;
22
23 import java.io.IOException;
24
25 import org.apache.commons.logging.Log;
26 import org.apache.commons.logging.LogFactory;
27 import org.apache.commons.logging.impl.Log4JLogger;
28 import org.apache.hadoop.fs.FileSystem;
29 import org.apache.hadoop.hbase.*;
30 import org.apache.hadoop.hbase.client.HBaseAdmin;
31 import org.apache.hadoop.hbase.client.HTable;
32 import org.apache.hadoop.hbase.client.Put;
33 import org.apache.hadoop.hbase.regionserver.HRegion;
34 import org.apache.hadoop.hbase.regionserver.HRegionServer;
35 import org.apache.hadoop.hbase.util.Bytes;
36 import org.apache.hadoop.hbase.util.FSUtils;
37 import org.apache.hadoop.hdfs.DFSClient;
38 import org.apache.hadoop.hdfs.MiniDFSCluster;
39 import org.apache.hadoop.hdfs.server.datanode.DataNode;
40 import org.apache.hadoop.hdfs.server.namenode.LeaseManager;
41 import org.apache.log4j.Level;
42 import org.junit.After;
43 import org.junit.Before;
44 import org.junit.BeforeClass;
45 import org.junit.Test;
46 import org.junit.experimental.categories.Category;
47
48
49
50
51
52 @Category(MediumTests.class)
53 public class TestLogRollAbort {
54 private static final Log LOG = LogFactory.getLog(TestLogRolling.class);
55 private static MiniDFSCluster dfsCluster;
56 private static HBaseAdmin admin;
57 private static MiniHBaseCluster cluster;
58 private final static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
59
60
61 {
62 ((Log4JLogger)DataNode.LOG).getLogger().setLevel(Level.ALL);
63 ((Log4JLogger)LeaseManager.LOG).getLogger().setLevel(Level.ALL);
64 ((Log4JLogger)LogFactory.getLog("org.apache.hadoop.hdfs.server.namenode.FSNamesystem"))
65 .getLogger().setLevel(Level.ALL);
66 ((Log4JLogger)DFSClient.LOG).getLogger().setLevel(Level.ALL);
67 ((Log4JLogger)HRegionServer.LOG).getLogger().setLevel(Level.ALL);
68 ((Log4JLogger)HRegion.LOG).getLogger().setLevel(Level.ALL);
69 ((Log4JLogger)HLog.LOG).getLogger().setLevel(Level.ALL);
70 }
71
72
73
74 @BeforeClass
75 public static void setUpBeforeClass() throws Exception {
76
77 TEST_UTIL.getConfiguration().setInt(
78 "hbase.regionserver.logroll.errors.tolerated", 2);
79 TEST_UTIL.getConfiguration().setInt("ipc.ping.interval", 10 * 1000);
80 TEST_UTIL.getConfiguration().setInt("ipc.socket.timeout", 10 * 1000);
81 TEST_UTIL.getConfiguration().setInt("hbase.rpc.timeout", 10 * 1000);
82
83
84 TEST_UTIL.getConfiguration().setLong("hbase.client.pause", 5 * 1000);
85
86
87 TEST_UTIL.getConfiguration().setBoolean("dfs.support.append", true);
88
89
90 TEST_UTIL.getConfiguration().setInt("heartbeat.recheck.interval", 5000);
91 TEST_UTIL.getConfiguration().setInt("dfs.heartbeat.interval", 1);
92
93
94 TEST_UTIL.getConfiguration().setInt("dfs.client.block.write.retries", 10);
95
96 TEST_UTIL.getConfiguration().setInt("hbase.regionserver.optionallogflushinterval",
97 120 * 1000);
98 }
99
100 @Before
101 public void setUp() throws Exception {
102 TEST_UTIL.startMiniCluster(2);
103
104 cluster = TEST_UTIL.getHBaseCluster();
105 dfsCluster = TEST_UTIL.getDFSCluster();
106 admin = TEST_UTIL.getHBaseAdmin();
107
108
109 cluster.getMaster().balanceSwitch(false);
110 }
111
112 @After
113 public void tearDown() throws Exception {
114 TEST_UTIL.shutdownMiniCluster();
115 }
116
117
118
119
120
121 @Test
122 public void testRSAbortWithUnflushedEdits() throws Exception {
123 LOG.info("Starting testRSAbortWithUnflushedEdits()");
124
125
126 new HTable(TEST_UTIL.getConfiguration(),
127 HConstants.META_TABLE_NAME).close();
128
129
130 String tableName = this.getClass().getSimpleName();
131 HTableDescriptor desc = new HTableDescriptor(tableName);
132 desc.addFamily(new HColumnDescriptor(HConstants.CATALOG_FAMILY));
133 desc.setDeferredLogFlush(true);
134
135 admin.createTable(desc);
136 HTable table = new HTable(TEST_UTIL.getConfiguration(), tableName);
137
138 HRegionServer server = TEST_UTIL.getRSForFirstRegionInTable(Bytes.toBytes(tableName));
139 HLog log = server.getWAL();
140
141 assertTrue("Need HDFS-826 for this test", log.canGetCurReplicas());
142
143 assertTrue("Need append support for this test",
144 FSUtils.isAppendSupported(TEST_UTIL.getConfiguration()));
145
146 Put p = new Put(Bytes.toBytes("row2001"));
147 p.add(HConstants.CATALOG_FAMILY, Bytes.toBytes("col"), Bytes.toBytes(2001));
148 table.put(p);
149
150 log.sync();
151
152 p = new Put(Bytes.toBytes("row2002"));
153 p.add(HConstants.CATALOG_FAMILY, Bytes.toBytes("col"), Bytes.toBytes(2002));
154 table.put(p);
155
156 dfsCluster.restartDataNodes();
157 LOG.info("Restarted datanodes");
158
159 assertTrue("Should have an outstanding WAL edit", log.hasDeferredEntries());
160 try {
161 log.rollWriter(true);
162 fail("Log roll should have triggered FailedLogCloseException");
163 } catch (FailedLogCloseException flce) {
164 assertTrue("Should have deferred flush log edits outstanding",
165 log.hasDeferredEntries());
166 }
167 }
168
169 @org.junit.Rule
170 public org.apache.hadoop.hbase.ResourceCheckerJUnitRule cu =
171 new org.apache.hadoop.hbase.ResourceCheckerJUnitRule();
172 }
173