1 /**
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19 package org.apache.hadoop.hbase.master;
20
21 import java.io.IOException;
22 import java.util.List;
23
24 import org.apache.hadoop.hbase.classification.InterfaceAudience;
25 import org.apache.hadoop.hbase.HColumnDescriptor;
26 import org.apache.hadoop.hbase.HRegionInfo;
27 import org.apache.hadoop.hbase.HTableDescriptor;
28 import org.apache.hadoop.hbase.NamespaceDescriptor;
29 import org.apache.hadoop.hbase.Server;
30 import org.apache.hadoop.hbase.TableDescriptors;
31 import org.apache.hadoop.hbase.TableName;
32 import org.apache.hadoop.hbase.TableNotDisabledException;
33 import org.apache.hadoop.hbase.TableNotFoundException;
34 import org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv;
35 import org.apache.hadoop.hbase.procedure2.ProcedureExecutor;
36 import org.apache.hadoop.hbase.executor.ExecutorService;
37 import org.apache.hadoop.hbase.quotas.MasterQuotaManager;
38
39 import com.google.protobuf.Service;
40
41 /**
42 * Services Master supplies
43 */
44 @InterfaceAudience.Private
45 public interface MasterServices extends Server {
46 /**
47 * @return Master's instance of the {@link AssignmentManager}
48 */
49 AssignmentManager getAssignmentManager();
50
51 /**
52 * @return Master's filesystem {@link MasterFileSystem} utility class.
53 */
54 MasterFileSystem getMasterFileSystem();
55
56 /**
57 * @return Master's {@link ServerManager} instance.
58 */
59 ServerManager getServerManager();
60
61 /**
62 * @return Master's instance of {@link ExecutorService}
63 */
64 ExecutorService getExecutorService();
65
66 /**
67 * @return Master's instance of {@link TableLockManager}
68 */
69 TableLockManager getTableLockManager();
70
71 /**
72 * @return Master's instance of {@link MasterCoprocessorHost}
73 */
74 MasterCoprocessorHost getMasterCoprocessorHost();
75
76 /**
77 * @return Master's instance of {@link MasterQuotaManager}
78 */
79 MasterQuotaManager getMasterQuotaManager();
80
81 /**
82 * @return Master's instance of {@link ProcedureExecutor}
83 */
84 ProcedureExecutor<MasterProcedureEnv> getMasterProcedureExecutor();
85
86 /**
87 * Check table is modifiable; i.e. exists and is offline.
88 * @param tableName Name of table to check.
89 * @throws TableNotDisabledException
90 * @throws TableNotFoundException
91 * @throws IOException
92 */
93 // We actually throw the exceptions mentioned in the
94 void checkTableModifiable(final TableName tableName)
95 throws IOException, TableNotFoundException, TableNotDisabledException;
96
97 /**
98 * Check whether the procedure executor is enabled
99 */
100 boolean isMasterProcedureExecutorEnabled();
101
102 /**
103 * Create a table using the given table definition.
104 * @param desc The table definition
105 * @param splitKeys Starting row keys for the initial table regions. If null
106 * a single region is created.
107 */
108 long createTable(HTableDescriptor desc, byte[][] splitKeys)
109 throws IOException;
110
111 /**
112 * Delete a table
113 * @param tableName The table name
114 * @throws IOException
115 */
116 long deleteTable(final TableName tableName) throws IOException;
117
118 /**
119 * Truncate a table
120 * @param tableName The table name
121 * @param preserveSplits True if the splits should be preserved
122 * @throws IOException
123 */
124 public void truncateTable(final TableName tableName, boolean preserveSplits) throws IOException;
125
126 /**
127 * Modify the descriptor of an existing table
128 * @param tableName The table name
129 * @param descriptor The updated table descriptor
130 * @throws IOException
131 */
132 void modifyTable(final TableName tableName, final HTableDescriptor descriptor)
133 throws IOException;
134
135 /**
136 * Enable an existing table
137 * @param tableName The table name
138 * @throws IOException
139 */
140 long enableTable(final TableName tableName) throws IOException;
141
142 /**
143 * Disable an existing table
144 * @param tableName The table name
145 * @throws IOException
146 */
147 long disableTable(final TableName tableName) throws IOException;
148
149
150 /**
151 * Add a new column to an existing table
152 * @param tableName The table name
153 * @param column The column definition
154 * @throws IOException
155 */
156 void addColumn(final TableName tableName, final HColumnDescriptor column)
157 throws IOException;
158
159 /**
160 * Modify the column descriptor of an existing column in an existing table
161 * @param tableName The table name
162 * @param descriptor The updated column definition
163 * @throws IOException
164 */
165 void modifyColumn(TableName tableName, HColumnDescriptor descriptor)
166 throws IOException;
167
168 /**
169 * Delete a column from an existing table
170 * @param tableName The table name
171 * @param columnName The column name
172 * @throws IOException
173 */
174 void deleteColumn(final TableName tableName, final byte[] columnName)
175 throws IOException;
176
177 /**
178 * @return Return table descriptors implementation.
179 */
180 TableDescriptors getTableDescriptors();
181
182 /**
183 * @return true if master enables ServerShutdownHandler;
184 */
185 boolean isServerShutdownHandlerEnabled();
186
187 /**
188 * Registers a new protocol buffer {@link Service} subclass as a master coprocessor endpoint.
189 *
190 * <p>
191 * Only a single instance may be registered for a given {@link Service} subclass (the
192 * instances are keyed on {@link com.google.protobuf.Descriptors.ServiceDescriptor#getFullName()}.
193 * After the first registration, subsequent calls with the same service name will fail with
194 * a return value of {@code false}.
195 * </p>
196 * @param instance the {@code Service} subclass instance to expose as a coprocessor endpoint
197 * @return {@code true} if the registration was successful, {@code false}
198 * otherwise
199 */
200 boolean registerService(Service instance);
201
202 /**
203 * Merge two regions. The real implementation is on the regionserver, master
204 * just move the regions together and send MERGE RPC to regionserver
205 * @param region_a region to merge
206 * @param region_b region to merge
207 * @param forcible true if do a compulsory merge, otherwise we will only merge
208 * two adjacent regions
209 * @throws IOException
210 */
211 void dispatchMergingRegions(
212 final HRegionInfo region_a, final HRegionInfo region_b, final boolean forcible
213 ) throws IOException;
214
215 /**
216 * @return true if master is initialized
217 */
218 boolean isInitialized();
219
220 /**
221 * Create a new namespace
222 * @param descriptor descriptor which describes the new namespace
223 * @throws IOException
224 */
225 public void createNamespace(NamespaceDescriptor descriptor) throws IOException;
226
227 /**
228 * Modify an existing namespace
229 * @param descriptor descriptor which updates the existing namespace
230 * @throws IOException
231 */
232 public void modifyNamespace(NamespaceDescriptor descriptor) throws IOException;
233
234 /**
235 * Delete an existing namespace. Only empty namespaces (no tables) can be removed.
236 * @param name namespace name
237 * @throws IOException
238 */
239 public void deleteNamespace(String name) throws IOException;
240
241 /**
242 * Get a namespace descriptor by name
243 * @param name name of namespace descriptor
244 * @return A descriptor
245 * @throws IOException
246 */
247 public NamespaceDescriptor getNamespaceDescriptor(String name) throws IOException;
248
249 /**
250 * List available namespace descriptors
251 * @return A descriptor
252 * @throws IOException
253 */
254 public List<NamespaceDescriptor> listNamespaceDescriptors() throws IOException;
255
256 /**
257 * Get list of table descriptors by namespace
258 * @param name namespace name
259 * @return descriptors
260 * @throws IOException
261 */
262 public List<HTableDescriptor> listTableDescriptorsByNamespace(String name) throws IOException;
263
264 /**
265 * Get list of table names by namespace
266 * @param name namespace name
267 * @return table names
268 * @throws IOException
269 */
270 public List<TableName> listTableNamesByNamespace(String name) throws IOException;
271
272 /**
273 * @param table
274 * @return the timestamp of the last successful major compaction for the passed table,
275 * or 0 if no HFile resulting from a major compaction exists
276 * @throws IOException
277 */
278 public long getLastMajorCompactionTimestamp(TableName table) throws IOException;
279
280 /**
281 * @param regionName
282 * @return the timestamp of the last successful major compaction for the passed region
283 * or 0 if no HFile resulting from a major compaction exists
284 * @throws IOException
285 */
286 public long getLastMajorCompactionTimestampForRegion(byte[] regionName) throws IOException;
287 }