001/* 002 * 003 * Licensed to the Apache Software Foundation (ASF) under one 004 * or more contributor license agreements. See the NOTICE file 005 * distributed with this work for additional information 006 * regarding copyright ownership. The ASF licenses this file 007 * to you under the Apache License, Version 2.0 (the 008 * "License"); you may not use this file except in compliance 009 * with the License. You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, software 014 * distributed under the License is distributed on an "AS IS" BASIS, 015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 016 * See the License for the specific language governing permissions and 017 * limitations under the License. 018 */ 019package org.apache.hadoop.hbase.zookeeper; 020 021import java.util.List; 022 023import org.apache.yetus.audience.InterfaceAudience; 024import org.apache.zookeeper.KeeperException; 025 026/** 027 * Tracks the master Maintenance Mode via ZK. 028 * 029 * Unused. Used to be set by hbck to prevent concurrent splits/merges, but those use PV2 now and 030 * HBCK2 uses it's own service, so no longer an issue. Left in, in case we need to use this for 031 * the incomplete parts of HBCK2... 032 */ 033@InterfaceAudience.Private 034public class MasterMaintenanceModeTracker extends ZKListener { 035 private boolean hasChildren; 036 037 public MasterMaintenanceModeTracker(ZKWatcher watcher) { 038 super(watcher); 039 hasChildren = false; 040 } 041 042 public boolean isInMaintenanceMode() { 043 return hasChildren; 044 } 045 046 private void update(String path) { 047 if (path.startsWith(watcher.znodePaths.masterMaintZNode)) { 048 update(); 049 } 050 } 051 052 private void update() { 053 try { 054 List<String> children = 055 ZKUtil.listChildrenAndWatchForNewChildren(watcher, watcher.znodePaths.masterMaintZNode); 056 hasChildren = (children != null && children.size() > 0); 057 } catch (KeeperException e) { 058 // Ignore the ZK keeper exception 059 hasChildren = false; 060 } 061 } 062 063 /** 064 * Starts the tracking of whether master is in Maintenance Mode. 065 */ 066 public void start() { 067 watcher.registerListener(this); 068 update(); 069 } 070 071 @Override 072 public void nodeCreated(String path) { 073 update(path); 074 } 075 076 @Override 077 public void nodeDeleted(String path) { 078 update(path); 079 } 080 081 @Override 082 public void nodeChildrenChanged(String path) { 083 update(path); 084 } 085}