001/**
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018
019package org.apache.hadoop.hbase.rsgroup;
020
021
022import java.io.IOException;
023import java.util.List;
024import java.util.Set;
025
026import org.apache.hadoop.hbase.NamespaceDescriptor;
027import org.apache.hadoop.hbase.TableName;
028import org.apache.hadoop.hbase.net.Address;
029import org.apache.hadoop.hbase.util.Bytes;
030import org.apache.yetus.audience.InterfaceAudience;
031
032/**
033 * Interface used to manage RSGroupInfo storage. An implementation
034 * has the option to support offline mode.
035 * See {@link RSGroupBasedLoadBalancer}
036 */
037@InterfaceAudience.Private
038public interface RSGroupInfoManager {
039
040  String REASSIGN_WAIT_INTERVAL_KEY = "hbase.rsgroup.reassign.wait";
041  long DEFAULT_REASSIGN_WAIT_INTERVAL = 30 * 1000L;
042
043  //Assigned before user tables
044  TableName RSGROUP_TABLE_NAME =
045      TableName.valueOf(NamespaceDescriptor.SYSTEM_NAMESPACE_NAME_STR, "rsgroup");
046  String rsGroupZNode = "rsgroup";
047  byte[] META_FAMILY_BYTES = Bytes.toBytes("m");
048  byte[] META_QUALIFIER_BYTES = Bytes.toBytes("i");
049  byte[] ROW_KEY = {0};
050
051  void start();
052
053  /**
054   * Add given RSGroupInfo to existing list of group infos.
055   */
056  void addRSGroup(RSGroupInfo rsGroupInfo) throws IOException;
057
058  /**
059   * Remove a region server group.
060   */
061  void removeRSGroup(String groupName) throws IOException;
062
063  /**
064   * Move servers to a new group.
065   * @param servers list of servers, must be part of the same group
066   * @param srcGroup groupName being moved from
067   * @param dstGroup groupName being moved to
068   * @return Set of servers moved (May be a subset of {@code servers}).
069   */
070  Set<Address> moveServers(Set<Address> servers, String srcGroup, String dstGroup)
071      throws IOException;
072
073  /**
074   * Gets the group info of server.
075   */
076  RSGroupInfo getRSGroupOfServer(Address serverHostPort) throws IOException;
077
078  /**
079   * Gets {@code RSGroupInfo} for the given group name.
080   */
081  RSGroupInfo getRSGroup(String groupName) throws IOException;
082
083  /**
084   * Get the group membership of a table
085   */
086  String getRSGroupOfTable(TableName tableName) throws IOException;
087
088  /**
089   * Set the group membership of a set of tables
090   *
091   * @param tableNames set of tables to move
092   * @param groupName name of group of tables to move to
093   */
094  void moveTables(Set<TableName> tableNames, String groupName) throws IOException;
095
096  /**
097   * List the existing {@code RSGroupInfo}s.
098   */
099  List<RSGroupInfo> listRSGroups() throws IOException;
100
101  /**
102   * Refresh/reload the group information from the persistent store
103   */
104  void refresh() throws IOException;
105
106  /**
107   * Whether the manager is able to fully return group metadata
108   *
109   * @return whether the manager is in online mode
110   */
111  boolean isOnline();
112
113  /**
114   * Move servers and tables to a new group.
115   * @param servers list of servers, must be part of the same group
116   * @param tables set of tables to move
117   * @param srcGroup groupName being moved from
118   * @param dstGroup groupName being moved to
119   */
120  void moveServersAndTables(Set<Address> servers, Set<TableName> tables,
121      String srcGroup, String dstGroup) throws IOException;
122
123  /**
124   * Remove decommissioned servers from rsgroup
125   * @param servers set of servers to remove
126   */
127  void removeServers(Set<Address> servers) throws IOException;
128}