Review Board 1.7.22


hbase-5688 Convert zk root-region-server znode content to pb

Review Request #4600 - Created April 1, 2012 and updated

Michael Stack
hbase-5688
Reviewers
hbase
hbase-git
Changes the content of the root location znode, root-region-server, to be
four magic bytes ('PBUF') followed by a protobuf message that holds the
ServerName of the server currently hosting root.

D src/main/java/org/apache/hadoop/hbase/catalog/RootLocationEditor.java
  Removed. Had two methods, one to add root-region-server znode and another
  to removed it.  Rather, put these methods in RootRegionTracker.  It
  tracks root-region-server znode.  Having all to do w/ root-region-server
  is more cohesive.  Also makes it so can encapsulate in one class
  all to do w/ create, delete, and reading of root-region-server.
  We also want to purge the catalog package (See note at head of
  CatalogTracker).
M src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java
M src/main/java/org/apache/hadoop/hbase/master/AssignmentManager.java
M src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
  Get root region location from RootRegionTracker rather than from RootLocationEditor.
A src/main/java/org/apache/hadoop/hbase/protobuf/ProtobufUtil.java
  Utility to do w/ protobuf handling.  Has methods to help prefixing
  and stripping from serialized protobuf messages some 'magic'.
A src/main/java/org/apache/hadoop/hbase/protobuf/generated/ZooKeeperProtos.java
  PB generated.
M src/main/java/org/apache/hadoop/hbase/util/HBaseFsck.java
  Use new RootRegionTracker method for getting content of znode rather
  than do it all here (going via RootRegionTracker, we can keep how
  the znode content is serialized private to the RootRegionTracker class.
M src/main/java/org/apache/hadoop/hbase/zookeeper/RootRegionTracker.java
  Has the methods that used to be in RootLocationEditor plus a new

 
src/main/java/org/apache/hadoop/hbase/catalog/RootLocationEditor.java
Revision c90864a New Change
1
/**

   
2
 * Copyright 2010 The Apache Software Foundation

   
3
 *

   
4
 * Licensed to the Apache Software Foundation (ASF) under one

   
5
 * or more contributor license agreements.  See the NOTICE file

   
6
 * distributed with this work for additional information

   
7
 * regarding copyright ownership.  The ASF licenses this file

   
8
 * to you under the Apache License, Version 2.0 (the

   
9
 * "License"); you may not use this file except in compliance

   
10
 * with the License.  You may obtain a copy of the License at

   
11
 *

   
12
 *     http://www.apache.org/licenses/LICENSE-2.0

   
13
 *

   
14
 * Unless required by applicable law or agreed to in writing, software

   
15
 * distributed under the License is distributed on an "AS IS" BASIS,

   
16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

   
17
 * See the License for the specific language governing permissions and

   
18
 * limitations under the License.

   
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.classification.InterfaceAudience;

   
25
import org.apache.hadoop.hbase.ServerName;

   
26
import org.apache.hadoop.hbase.util.Bytes;

   
27
import org.apache.hadoop.hbase.zookeeper.ZKUtil;

   
28
import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;

   
29
import org.apache.zookeeper.KeeperException;

   
30

    
   

   
31
/**

   
32
 * Makes changes to the location of <code>-ROOT-</code> in ZooKeeper.

   
33
 */

   
34
@InterfaceAudience.Private

   
35
public class RootLocationEditor {

   
36
  private static final Log LOG = LogFactory.getLog(RootLocationEditor.class);

   
37

    
   

   
38
  /**

   
39
   * Deletes the location of <code>-ROOT-</code> in ZooKeeper.

   
40
   * @param zookeeper zookeeper reference

   
41
   * @throws KeeperException unexpected zookeeper exception

   
42
   */

   
43
  public static void deleteRootLocation(ZooKeeperWatcher zookeeper)

   
44
  throws KeeperException {

   
45
    LOG.info("Unsetting ROOT region location in ZooKeeper");

   
46
    try {

   
47
      // Just delete the node.  Don't need any watches, only we will create it.

   
48
      ZKUtil.deleteNode(zookeeper, zookeeper.rootServerZNode);

   
49
    } catch(KeeperException.NoNodeException nne) {

   
50
      // Has already been deleted

   
51
    }

   
52
  }

   
53

    
   

   
54
  /**

   
55
   * Sets the location of <code>-ROOT-</code> in ZooKeeper to the

   
56
   * specified server address.

   
57
   * @param zookeeper zookeeper reference

   
58
   * @param location The server hosting <code>-ROOT-</code>

   
59
   * @throws KeeperException unexpected zookeeper exception

   
60
   */

   
61
  public static void setRootLocation(ZooKeeperWatcher zookeeper,

   
62
      final ServerName location)

   
63
  throws KeeperException {

   
64
    LOG.info("Setting ROOT region location in ZooKeeper as " + location);

   
65
    try {

   
66
      ZKUtil.createAndWatch(zookeeper, zookeeper.rootServerZNode,

   
67
        Bytes.toBytes(location.toString()));

   
68
    } catch(KeeperException.NodeExistsException nee) {

   
69
      LOG.debug("ROOT region location already existed, updated location");

   
70
      ZKUtil.setData(zookeeper, zookeeper.rootServerZNode,

   
71
          Bytes.toBytes(location.toString()));

   
72
    }

   
73
  }

   
74
}

   
src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java
Revision b2a5463 New Change
 
src/main/java/org/apache/hadoop/hbase/master/AssignmentManager.java
Revision 64def15 New Change
 
src/main/java/org/apache/hadoop/hbase/protobuf/ProtobufUtil.java
New File
 
src/main/java/org/apache/hadoop/hbase/protobuf/generated/ZooKeeperProtos.java
New File
 
src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
Revision 9c215b4 New Change
 
src/main/java/org/apache/hadoop/hbase/util/HBaseFsck.java
Revision 2f05005 New Change
 
src/main/java/org/apache/hadoop/hbase/zookeeper/RootRegionTracker.java
Revision 33e4e71 New Change
 
src/main/protobuf/ZooKeeper.proto
New File
 
src/test/java/org/apache/hadoop/hbase/catalog/TestCatalogTracker.java
Revision 533b2bf New Change
 
src/test/java/org/apache/hadoop/hbase/catalog/TestCatalogTrackerOnCluster.java
Revision fe37156 New Change
 
src/test/java/org/apache/hadoop/hbase/master/TestMasterNoCluster.java
Revision 2132036 New Change
 
src/test/java/org/apache/hadoop/hbase/zookeeper/TestRootRegionTracker.java
New File
 
  1. src/main/java/org/apache/hadoop/hbase/catalog/RootLocationEditor.java: Loading...
  2. src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java: Loading...
  3. src/main/java/org/apache/hadoop/hbase/master/AssignmentManager.java: Loading...
  4. src/main/java/org/apache/hadoop/hbase/protobuf/ProtobufUtil.java: Loading...
  5. src/main/java/org/apache/hadoop/hbase/protobuf/generated/ZooKeeperProtos.java: Loading...
  6. src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java: Loading...
  7. src/main/java/org/apache/hadoop/hbase/util/HBaseFsck.java: Loading...
  8. src/main/java/org/apache/hadoop/hbase/zookeeper/RootRegionTracker.java: Loading...
  9. src/main/protobuf/ZooKeeper.proto: Loading...
  10. src/test/java/org/apache/hadoop/hbase/catalog/TestCatalogTracker.java: Loading...
  11. src/test/java/org/apache/hadoop/hbase/catalog/TestCatalogTrackerOnCluster.java: Loading...
  12. src/test/java/org/apache/hadoop/hbase/master/TestMasterNoCluster.java: Loading...
  13. src/test/java/org/apache/hadoop/hbase/zookeeper/TestRootRegionTracker.java: Loading...