1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase.zookeeper;
20
21 import org.apache.commons.logging.Log;
22 import org.apache.commons.logging.LogFactory;
23 import org.apache.hadoop.hbase.classification.InterfaceAudience;
24 import org.apache.hadoop.hbase.regionserver.HRegionServer;
25 import org.apache.hadoop.hbase.regionserver.handler.FinishRegionRecoveringHandler;
26 import org.apache.zookeeper.KeeperException;
27
28
29
30
31 @InterfaceAudience.Private
32 public class RecoveringRegionWatcher extends ZooKeeperListener {
33 private static final Log LOG = LogFactory.getLog(RecoveringRegionWatcher.class);
34
35 private HRegionServer server;
36
37
38
39
40 public RecoveringRegionWatcher(ZooKeeperWatcher watcher, HRegionServer server) {
41 super(watcher);
42 watcher.registerListener(this);
43 this.server = server;
44 }
45
46
47
48
49
50 @Override
51 public void nodeDeleted(String path) {
52 if (this.server.isStopped() || this.server.isStopping()) {
53 return;
54 }
55
56 String parentPath = path.substring(0, path.lastIndexOf('/'));
57 if (!this.watcher.recoveringRegionsZNode.equalsIgnoreCase(parentPath)) {
58 return;
59 }
60
61 String regionName = path.substring(parentPath.length() + 1);
62
63 server.getExecutorService().submit(new FinishRegionRecoveringHandler(server, regionName, path));
64 }
65
66 @Override
67 public void nodeDataChanged(String path) {
68 registerWatcher(path);
69 }
70
71 @Override
72 public void nodeChildrenChanged(String path) {
73 registerWatcher(path);
74 }
75
76
77
78
79
80 private void registerWatcher(String path) {
81 String parentPath = path.substring(0, path.lastIndexOf('/'));
82 if (!this.watcher.recoveringRegionsZNode.equalsIgnoreCase(parentPath)) {
83 return;
84 }
85
86 try {
87 ZKUtil.getDataAndWatch(watcher, path);
88 } catch (KeeperException e) {
89 LOG.warn("Can't register watcher on znode " + path, e);
90 }
91 }
92 }