View Javadoc

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.ipc;
21  
22  import java.io.IOException;
23  
24  import org.apache.hadoop.hbase.ClusterStatus;
25  import org.apache.hadoop.hbase.HColumnDescriptor;
26  import org.apache.hadoop.hbase.HTableDescriptor;
27  import org.apache.hadoop.hbase.UnknownRegionException;
28  
29  /**
30   * Clients interact with the HMasterInterface to gain access to meta-level
31   * HBase functionality, like finding an HRegionServer and creating/destroying
32   * tables.
33   *
34   * <p>NOTE: if you change the interface, you must change the RPC version
35   * number in HBaseRPCProtocolVersion
36   *
37   */
38  public interface HMasterInterface extends HBaseRPCProtocolVersion {
39  
40    /** @return true if master is available */
41    public boolean isMasterRunning();
42  
43    // Admin tools would use these cmds
44  
45    /**
46     * Creates a new table.  If splitKeys are specified, then the table will be
47     * created with an initial set of multiple regions.  If splitKeys is null,
48     * the table will be created with a single region.
49     * @param desc table descriptor
50     * @param splitKeys
51     * @throws IOException
52     */
53    public void createTable(HTableDescriptor desc, byte [][] splitKeys)
54    throws IOException;
55  
56    /**
57     * Deletes a table
58     * @param tableName table to delete
59     * @throws IOException e
60     */
61    public void deleteTable(final byte [] tableName) throws IOException;
62  
63    /**
64     * Adds a column to the specified table
65     * @param tableName table to modify
66     * @param column column descriptor
67     * @throws IOException e
68     */
69    public void addColumn(final byte [] tableName, HColumnDescriptor column)
70    throws IOException;
71  
72    /**
73     * Modifies an existing column on the specified table
74     * @param tableName table name
75     * @param descriptor new column descriptor
76     * @throws IOException e
77     */
78    public void modifyColumn(final byte [] tableName, HColumnDescriptor descriptor)
79    throws IOException;
80  
81  
82    /**
83     * Deletes a column from the specified table. Table must be disabled.
84     * @param tableName table to alter
85     * @param columnName column family to remove
86     * @throws IOException e
87     */
88    public void deleteColumn(final byte [] tableName, final byte [] columnName)
89    throws IOException;
90  
91    /**
92     * Puts the table on-line (only needed if table has been previously taken offline)
93     * @param tableName table to enable
94     * @throws IOException e
95     */
96    public void enableTable(final byte [] tableName) throws IOException;
97  
98    /**
99     * Take table offline
100    *
101    * @param tableName table to take offline
102    * @throws IOException e
103    */
104   public void disableTable(final byte [] tableName) throws IOException;
105 
106   /**
107    * Modify a table's metadata
108    *
109    * @param tableName table to modify
110    * @param htd new descriptor for table
111    * @throws IOException e
112    */
113   public void modifyTable(byte[] tableName, HTableDescriptor htd)
114   throws IOException;
115 
116   /**
117    * Shutdown an HBase cluster.
118    * @throws IOException e
119    */
120   public void shutdown() throws IOException;
121 
122   /**
123    * Stop HBase Master only.
124    * Does not shutdown the cluster.
125    * @throws IOException e
126    */
127   public void stopMaster() throws IOException;
128 
129   /**
130    * Return cluster status.
131    * @return status object
132    */
133   public ClusterStatus getClusterStatus();
134 
135 
136   /**
137    * Move the region <code>r</code> to <code>dest</code>.
138    * @param encodedRegionName The encoded region name; i.e. the hash that makes
139    * up the region name suffix: e.g. if regionname is
140    * <code>TestTable,0094429456,1289497600452.527db22f95c8a9e0116f0cc13c680396.</code>,
141    * then the encoded region name is: <code>527db22f95c8a9e0116f0cc13c680396</code>.
142    * @param destServerName The servername of the destination regionserver.  If
143    * passed the empty byte array we'll assign to a random server.  A server name
144    * is made of host, port and startcode.  Here is an example:
145    * <code> host187.example.com,60020,1289493121758</code>.
146    * @throws UnknownRegionException Thrown if we can't find a region named
147    * <code>encodedRegionName</code>
148    */
149   public void move(final byte [] encodedRegionName, final byte [] destServerName)
150   throws UnknownRegionException;
151 
152   /**
153    * Assign a region to a server chosen at random.
154    * @param regionName Region to assign.  Will use existing RegionPlan if one
155    * found.
156    * @param force If true, will force the assignment.
157    * @throws IOException
158    */
159   public void assign(final byte [] regionName, final boolean force)
160   throws IOException;
161 
162   /**
163    * Unassign a region from current hosting regionserver.  Region will then be
164    * assigned to a regionserver chosen at random.  Region could be reassigned
165    * back to the same server.  Use {@link #move(byte[], byte[])} if you want
166    * to control the region movement.
167    * @param regionName Region to unassign. Will clear any existing RegionPlan
168    * if one found.
169    * @param force If true, force unassign (Will remove region from
170    * regions-in-transition too if present).
171    * @throws IOException
172    */
173   public void unassign(final byte [] regionName, final boolean force)
174   throws IOException;
175 
176   /**
177    * Run the balancer.  Will run the balancer and if regions to move, it will
178    * go ahead and do the reassignments.  Can NOT run for various reasons.  Check
179    * logs.
180    * @return True if balancer ran and was able to tell the region servers to
181    * unassign all the regions to balance (the re-assignment itself is async),
182    * false otherwise.
183    */
184   public boolean balance();
185 
186   /**
187    * Turn the load balancer on or off.
188    * @param b If true, enable balancer. If false, disable balancer.
189    * @return Previous balancer value
190    */
191   public boolean balanceSwitch(final boolean b);
192 }