1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase.master;
19
20 import static org.junit.Assert.assertEquals;
21 import static org.junit.Assert.assertFalse;
22 import static org.junit.Assert.assertTrue;
23
24 import java.util.HashSet;
25 import java.util.Set;
26
27 import org.apache.commons.logging.Log;
28 import org.apache.commons.logging.LogFactory;
29 import org.apache.hadoop.fs.FileSystem;
30 import org.apache.hadoop.fs.Path;
31 import org.apache.hadoop.hbase.HBaseTestingUtility;
32 import org.apache.hadoop.hbase.HConstants;
33 import org.apache.hadoop.hbase.testclassification.MediumTests;
34 import org.apache.hadoop.hbase.ServerName;
35 import org.apache.hadoop.hbase.SplitLogTask;
36 import org.apache.hadoop.hbase.util.FSUtils;
37 import org.apache.hadoop.hbase.zookeeper.ZKSplitLog;
38 import org.apache.hadoop.hbase.zookeeper.ZKUtil;
39 import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
40 import org.apache.zookeeper.CreateMode;
41 import org.apache.zookeeper.ZooDefs.Ids;
42 import org.junit.AfterClass;
43 import org.junit.BeforeClass;
44 import org.junit.Test;
45 import org.junit.experimental.categories.Category;
46
47
48
49
50 @Category(MediumTests.class)
51 public class TestMasterFileSystem {
52
53 private static final Log LOG = LogFactory.getLog(TestMasterFileSystem.class);
54 private static final HBaseTestingUtility UTIL = new HBaseTestingUtility();
55
56 @BeforeClass
57 public static void setupTest() throws Exception {
58 UTIL.startMiniCluster();
59 }
60
61 @AfterClass
62 public static void teardownTest() throws Exception {
63 UTIL.shutdownMiniCluster();
64 }
65
66 @Test
67 public void testFsUriSetProperly() throws Exception {
68 HMaster master = UTIL.getMiniHBaseCluster().getMaster();
69 MasterFileSystem fs = master.getMasterFileSystem();
70 Path masterRoot = FSUtils.getRootDir(fs.conf);
71 Path rootDir = FSUtils.getRootDir(fs.getFileSystem().getConf());
72
73 LOG.debug("from fs uri:" + FileSystem.getDefaultUri(fs.getFileSystem().getConf()));
74 LOG.debug("from configuration uri:" + FileSystem.getDefaultUri(fs.conf));
75
76 assertEquals(masterRoot, rootDir);
77 }
78
79 @Test
80 public void testRemoveStaleRecoveringRegionsDuringMasterInitialization() throws Exception {
81
82 if (!UTIL.getConfiguration().getBoolean(HConstants.DISTRIBUTED_LOG_REPLAY_KEY, false)) return;
83
84 LOG.info("Starting testRemoveStaleRecoveringRegionsDuringMasterInitialization");
85 HMaster master = UTIL.getMiniHBaseCluster().getMaster();
86 MasterFileSystem fs = master.getMasterFileSystem();
87
88 String failedRegion = "failedRegoin1";
89 String staleRegion = "staleRegion";
90 ServerName inRecoveryServerName = ServerName.valueOf("mgr,1,1");
91 ServerName previouselyFaildServerName = ServerName.valueOf("previous,1,1");
92 String walPath = "/hbase/data/.logs/" + inRecoveryServerName.getServerName()
93 + "-splitting/test";
94
95 ZooKeeperWatcher zkw = HBaseTestingUtility.getZooKeeperWatcher(UTIL);
96 zkw.getRecoverableZooKeeper().create(ZKSplitLog.getEncodedNodeName(zkw, walPath),
97 new SplitLogTask.Owned(inRecoveryServerName, fs.getLogRecoveryMode()).toByteArray(),
98 Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
99 String staleRegionPath = ZKUtil.joinZNode(zkw.recoveringRegionsZNode, staleRegion);
100 ZKUtil.createWithParents(zkw, staleRegionPath);
101 String inRecoveringRegionPath = ZKUtil.joinZNode(zkw.recoveringRegionsZNode, failedRegion);
102 inRecoveringRegionPath = ZKUtil.joinZNode(inRecoveringRegionPath,
103 inRecoveryServerName.getServerName());
104 ZKUtil.createWithParents(zkw, inRecoveringRegionPath);
105 Set<ServerName> servers = new HashSet<ServerName>();
106 servers.add(previouselyFaildServerName);
107 fs.removeStaleRecoveringRegionsFromZK(servers);
108
109
110 assertFalse(ZKUtil.checkExists(zkw, staleRegionPath) != -1);
111 assertTrue(ZKUtil.checkExists(zkw, inRecoveringRegionPath) != -1);
112
113 ZKUtil.deleteChildrenRecursively(zkw, zkw.recoveringRegionsZNode);
114 ZKUtil.deleteChildrenRecursively(zkw, zkw.splitLogZNode);
115 zkw.close();
116 }
117
118 }