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