1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.hadoop.hbase.catalog;
21
22 import org.apache.commons.logging.Log;
23 import org.apache.commons.logging.LogFactory;
24 import org.apache.hadoop.hbase.HServerAddress;
25 import org.apache.hadoop.hbase.util.Bytes;
26 import org.apache.hadoop.hbase.zookeeper.ZKUtil;
27 import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
28 import org.apache.zookeeper.KeeperException;
29
30
31
32
33 public class RootLocationEditor {
34 private static final Log LOG = LogFactory.getLog(RootLocationEditor.class);
35
36
37
38
39
40
41 public static void deleteRootLocation(ZooKeeperWatcher zookeeper)
42 throws KeeperException {
43 LOG.info("Unsetting ROOT region location in ZooKeeper");
44 try {
45
46 ZKUtil.deleteNode(zookeeper, zookeeper.rootServerZNode);
47 } catch(KeeperException.NoNodeException nne) {
48
49 }
50 }
51
52
53
54
55
56
57
58
59 public static void setRootLocation(ZooKeeperWatcher zookeeper,
60 HServerAddress location)
61 throws KeeperException {
62 LOG.info("Setting ROOT region location in ZooKeeper as " + location);
63 try {
64 ZKUtil.createAndWatch(zookeeper, zookeeper.rootServerZNode,
65 Bytes.toBytes(location.toString()));
66 } catch(KeeperException.NodeExistsException nee) {
67 LOG.debug("ROOT region location already existed, updated location");
68 ZKUtil.setData(zookeeper, zookeeper.rootServerZNode,
69 Bytes.toBytes(location.toString()));
70 }
71 }
72 }