1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase.wal;
19
20 import static org.junit.Assert.assertEquals;
21 import static org.junit.Assert.assertFalse;
22 import static org.junit.Assert.assertNotNull;
23 import static org.junit.Assert.assertTrue;
24
25 import java.util.ArrayList;
26 import java.util.List;
27
28 import org.apache.hadoop.fs.Path;
29 import org.apache.hadoop.hbase.Cell;
30 import org.apache.hadoop.hbase.CellUtil;
31 import org.apache.hadoop.hbase.HBaseTestingUtility;
32 import org.apache.hadoop.hbase.HColumnDescriptor;
33 import org.apache.hadoop.hbase.HTableDescriptor;
34 import org.apache.hadoop.hbase.MiniHBaseCluster;
35 import org.apache.hadoop.hbase.ServerName;
36 import org.apache.hadoop.hbase.TableName;
37 import org.apache.hadoop.hbase.client.Get;
38 import org.apache.hadoop.hbase.client.Put;
39 import org.apache.hadoop.hbase.client.Result;
40 import org.apache.hadoop.hbase.client.Table;
41 import org.apache.hadoop.hbase.testclassification.LargeTests;
42 import org.apache.hadoop.hbase.testclassification.RegionServerTests;
43 import org.apache.hadoop.hbase.util.Bytes;
44 import org.apache.hadoop.hbase.util.CommonFSUtils;
45 import org.junit.AfterClass;
46 import org.junit.BeforeClass;
47 import org.junit.Test;
48 import org.junit.experimental.categories.Category;
49
50 @Category({RegionServerTests.class, LargeTests.class})
51 public class TestWALSplitWithDeletedTableData {
52
53 private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
54
55 @BeforeClass
56 public static void setup() throws Exception {
57 TEST_UTIL.startMiniCluster(2);
58 }
59
60 @AfterClass
61 public static void tearDown() throws Exception {
62 TEST_UTIL.shutdownMiniCluster();
63 }
64
65 @Test
66 public void testWALSplitWithDeletedTableData() throws Exception {
67 final byte[] CFNAME = Bytes.toBytes("f1");
68 final byte[] QNAME = Bytes.toBytes("q1");
69 final byte[] VALUE = Bytes.toBytes("v1");
70 final TableName t1 = TableName.valueOf("t1");
71 final TableName t2 = TableName.valueOf("t2");
72 final byte[][] splitRows = { Bytes.toBytes("a"), Bytes.toBytes("b"), Bytes.toBytes("c"),
73 Bytes.toBytes("d") };
74 HTableDescriptor htd = new HTableDescriptor(t1);
75 htd.addFamily(new HColumnDescriptor(CFNAME));
76 Table tab1 = TEST_UTIL.createTable(htd, splitRows);
77 HTableDescriptor htd2 = new HTableDescriptor(t2);
78 htd2.addFamily(new HColumnDescriptor(CFNAME));
79 Table tab2 = TEST_UTIL.createTable(htd2, splitRows);
80 List<Put> puts = new ArrayList<Put>(4);
81 byte[][] rks = { Bytes.toBytes("ac"), Bytes.toBytes("ba"), Bytes.toBytes("ca"),
82 Bytes.toBytes("dd") };
83 for (byte[] rk : rks) {
84 puts.add(new Put(rk).addColumn(CFNAME, QNAME, VALUE));
85 }
86 tab1.put(puts);
87 tab2.put(puts);
88 MiniHBaseCluster cluster = TEST_UTIL.getMiniHBaseCluster();
89 TEST_UTIL.deleteTable(t1);
90 Path tableDir = CommonFSUtils.getWALTableDir(TEST_UTIL.getConfiguration(), t1);
91
92 assertFalse(TEST_UTIL.getDFSCluster().getFileSystem().exists(tableDir));
93 ServerName rs1 = cluster.getRegionServer(1).getServerName();
94
95 cluster.killRegionServer(rs1);
96 cluster.waitForRegionServerToStop(rs1, 60 * 1000);
97 assertEquals(1, cluster.hbaseCluster.getLiveRegionServers().size());
98 Thread.sleep(1 * 1000);
99 TEST_UTIL.waitUntilNoRegionsInTransition(60 * 1000);
100
101 assertFalse(TEST_UTIL.getDFSCluster().getFileSystem().exists(tableDir));
102
103 for (byte[] rk : rks) {
104 Result result = tab2.get(new Get(rk));
105 assertFalse(result.isEmpty());
106 Cell cell = result.getColumnLatestCell(CFNAME, QNAME);
107 assertNotNull(cell);
108 assertTrue(CellUtil.matchingValue(cell, VALUE));
109 }
110 }
111 }