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 */
018package org.apache.hadoop.hbase.rsgroup;
019
020import java.io.IOException;
021import java.util.List;
022import java.util.Map;
023import java.util.Set;
024import org.apache.hadoop.hbase.NamespaceDescriptor;
025import org.apache.hadoop.hbase.TableName;
026import org.apache.hadoop.hbase.net.Address;
027import org.apache.hadoop.hbase.util.Bytes;
028import org.apache.yetus.audience.InterfaceAudience;
029
030/**
031 * Interface used to manage RSGroupInfo storage. An implementation has the option to support offline
032 * mode. See {@link RSGroupBasedLoadBalancer}
033 */
034@InterfaceAudience.Private
035public interface RSGroupInfoManager {
036
037  String REASSIGN_WAIT_INTERVAL_KEY = "hbase.rsgroup.reassign.wait";
038  long DEFAULT_REASSIGN_WAIT_INTERVAL = 30 * 1000L;
039
040  // Assigned before user tables
041  TableName RSGROUP_TABLE_NAME =
042    TableName.valueOf(NamespaceDescriptor.SYSTEM_NAMESPACE_NAME_STR, "rsgroup");
043  String rsGroupZNode = "rsgroup";
044  byte[] META_FAMILY_BYTES = Bytes.toBytes("m");
045  byte[] META_QUALIFIER_BYTES = Bytes.toBytes("i");
046  byte[] ROW_KEY = { 0 };
047
048  void start();
049
050  /**
051   * Add given RSGroupInfo to existing list of group infos.
052   */
053  void addRSGroup(RSGroupInfo rsGroupInfo) throws IOException;
054
055  /**
056   * Remove a region server group.
057   */
058  void removeRSGroup(String groupName) throws IOException;
059
060  /**
061   * Move servers to a new group.
062   * @param servers  list of servers, must be part of the same group
063   * @param srcGroup groupName being moved from
064   * @param dstGroup groupName being moved to
065   * @return Set of servers moved (May be a subset of {@code servers}).
066   */
067  Set<Address> moveServers(Set<Address> servers, String srcGroup, String dstGroup)
068    throws IOException;
069
070  /**
071   * Gets the group info of server.
072   */
073  RSGroupInfo getRSGroupOfServer(Address serverHostPort) throws IOException;
074
075  /**
076   * Gets {@code RSGroupInfo} for the given group name.
077   */
078  RSGroupInfo getRSGroup(String groupName) throws IOException;
079
080  /**
081   * Get the group membership of a table
082   */
083  String getRSGroupOfTable(TableName tableName) throws IOException;
084
085  /**
086   * Set the group membership of a set of tables
087   * @param tableNames set of tables to move
088   * @param groupName  name of group of tables to move to
089   */
090  void moveTables(Set<TableName> tableNames, String groupName) throws IOException;
091
092  /**
093   * List the existing {@code RSGroupInfo}s.
094   */
095  List<RSGroupInfo> listRSGroups() throws IOException;
096
097  /**
098   * Refresh/reload the group information from the persistent store
099   */
100  void refresh() throws IOException;
101
102  /**
103   * Whether the manager is able to fully return group metadata
104   * @return whether the manager is in online mode
105   */
106  boolean isOnline();
107
108  /**
109   * Move servers and tables to a new group.
110   * @param servers  list of servers, must be part of the same group
111   * @param tables   set of tables to move
112   * @param srcGroup groupName being moved from
113   * @param dstGroup groupName being moved to
114   */
115  void moveServersAndTables(Set<Address> servers, Set<TableName> tables, String srcGroup,
116    String dstGroup) throws IOException;
117
118  /**
119   * Remove decommissioned servers from rsgroup
120   * @param servers set of servers to remove
121   */
122  void removeServers(Set<Address> servers) throws IOException;
123
124  /**
125   * Rename RSGroup
126   * @param oldName old rsgroup name
127   * @param newName new rsgroup name
128   */
129  void renameRSGroup(String oldName, String newName) throws IOException;
130
131  /**
132   * Determine {@code RSGroupInfo} for the given table.
133   * @param tableName table name
134   * @return {@link RSGroupInfo} which table should belong to
135   */
136  RSGroupInfo determineRSGroupInfoForTable(TableName tableName) throws IOException;
137
138  /**
139   * Update RSGroup configuration
140   * @param groupName     the group name
141   * @param configuration new configuration of the group name to be set
142   * @throws IOException if a remote or network exception occurs
143   */
144  void updateRSGroupConfig(String groupName, Map<String, String> configuration) throws IOException;
145}