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.ProcedureInfo;
30 import org.apache.hadoop.hbase.Server;
31 import org.apache.hadoop.hbase.TableDescriptors;
32 import org.apache.hadoop.hbase.TableName;
33 import org.apache.hadoop.hbase.TableNotDisabledException;
34 import org.apache.hadoop.hbase.TableNotFoundException;
35 import org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv;
36 import org.apache.hadoop.hbase.master.snapshot.SnapshotManager;
37 import org.apache.hadoop.hbase.procedure2.ProcedureExecutor;
38 import org.apache.hadoop.hbase.executor.ExecutorService;
39 import org.apache.hadoop.hbase.quotas.MasterQuotaManager;
40 import org.apache.hadoop.hbase.security.User;
41
42 import com.google.protobuf.Service;
43
44 /**
45 * Services Master supplies
46 */
47 @InterfaceAudience.Private
48 public interface MasterServices extends Server {
49 /**
50 * @return the underlying snapshot manager
51 */
52 SnapshotManager getSnapshotManager();
53
54 /**
55 * @return Master's instance of the {@link AssignmentManager}
56 */
57 AssignmentManager getAssignmentManager();
58
59 /**
60 * @return Master's filesystem {@link MasterFileSystem} utility class.
61 */
62 MasterFileSystem getMasterFileSystem();
63
64 /**
65 * @return Master's {@link ServerManager} instance.
66 */
67 ServerManager getServerManager();
68
69 /**
70 * @return Master's instance of {@link ExecutorService}
71 */
72 ExecutorService getExecutorService();
73
74 /**
75 * @return Master's instance of {@link TableLockManager}
76 */
77 TableLockManager getTableLockManager();
78
79 /**
80 * @return Master's instance of {@link MasterCoprocessorHost}
81 */
82 MasterCoprocessorHost getMasterCoprocessorHost();
83
84 /**
85 * @return Master's instance of {@link TableNamespaceManager}
86 */
87 TableNamespaceManager getTableNamespaceManager();
88
89 /**
90 * @return Master's instance of {@link MasterQuotaManager}
91 */
92 MasterQuotaManager getMasterQuotaManager();
93
94 /**
95 * @return Master's instance of {@link ProcedureExecutor}
96 */
97 ProcedureExecutor<MasterProcedureEnv> getMasterProcedureExecutor();
98
99 /**
100 * @return load balancer
101 */
102 LoadBalancer getLoadBalancer();
103
104 /**
105 * Check table is modifiable; i.e. exists and is offline.
106 * @param tableName Name of table to check.
107 * @throws TableNotDisabledException
108 * @throws TableNotFoundException
109 * @throws IOException
110 */
111 // We actually throw the exceptions mentioned in the
112 void checkTableModifiable(final TableName tableName)
113 throws IOException, TableNotFoundException, TableNotDisabledException;
114
115 /**
116 * Create a table using the given table definition.
117 * @param desc The table definition
118 * @param splitKeys Starting row keys for the initial table regions. If null
119 * @param nonceGroup
120 * @param nonce
121 * a single region is created.
122 */
123 long createTable(
124 final HTableDescriptor desc,
125 final byte[][] splitKeys,
126 final long nonceGroup,
127 final long nonce) throws IOException;
128
129 /**
130 * Create a system table using the given table definition.
131 * @param hTableDescriptor The system table definition
132 * a single region is created.
133 */
134 long createSystemTable(final HTableDescriptor hTableDescriptor) throws IOException;
135
136 /**
137 * Delete a table
138 * @param tableName The table name
139 * @param nonceGroup
140 * @param nonce
141 * @throws IOException
142 */
143 long deleteTable(
144 final TableName tableName,
145 final long nonceGroup,
146 final long nonce) throws IOException;
147
148 /**
149 * Truncate a table
150 * @param tableName The table name
151 * @param preserveSplits True if the splits should be preserved
152 * @param nonceGroup
153 * @param nonce
154 * @throws IOException
155 */
156 public void truncateTable(
157 final TableName tableName,
158 final boolean preserveSplits,
159 final long nonceGroup,
160 final long nonce) throws IOException;
161
162 /**
163 * Modify the descriptor of an existing table
164 * @param tableName The table name
165 * @param descriptor The updated table descriptor
166 * @param nonceGroup
167 * @param nonce
168 * @throws IOException
169 */
170 void modifyTable(
171 final TableName tableName,
172 final HTableDescriptor descriptor,
173 final long nonceGroup,
174 final long nonce)
175 throws IOException;
176
177 /**
178 * Enable an existing table
179 * @param tableName The table name
180 * @param nonceGroup
181 * @param nonce
182 * @throws IOException
183 */
184 long enableTable(
185 final TableName tableName,
186 final long nonceGroup,
187 final long nonce) throws IOException;
188
189 /**
190 * Disable an existing table
191 * @param tableName The table name
192 * @param nonceGroup
193 * @param nonce
194 * @throws IOException
195 */
196 long disableTable(
197 final TableName tableName,
198 final long nonceGroup,
199 final long nonce) throws IOException;
200
201
202 /**
203 * Add a new column to an existing table
204 * @param tableName The table name
205 * @param column The column definition
206 * @param nonceGroup
207 * @param nonce
208 * @throws IOException
209 */
210 void addColumn(
211 final TableName tableName,
212 final HColumnDescriptor column,
213 final long nonceGroup,
214 final long nonce)
215 throws IOException;
216
217 /**
218 * Modify the column descriptor of an existing column in an existing table
219 * @param tableName The table name
220 * @param descriptor The updated column definition
221 * @param nonceGroup
222 * @param nonce
223 * @throws IOException
224 */
225 void modifyColumn(
226 final TableName tableName,
227 final HColumnDescriptor descriptor,
228 final long nonceGroup,
229 final long nonce)
230 throws IOException;
231
232 /**
233 * Delete a column from an existing table
234 * @param tableName The table name
235 * @param columnName The column name
236 * @param nonceGroup
237 * @param nonce
238 * @throws IOException
239 */
240 void deleteColumn(
241 final TableName tableName,
242 final byte[] columnName,
243 final long nonceGroup,
244 final long nonce)
245 throws IOException;
246
247 /**
248 * @return Return table descriptors implementation.
249 */
250 TableDescriptors getTableDescriptors();
251
252 /**
253 * @return true if master enables ServerShutdownHandler;
254 */
255 boolean isServerCrashProcessingEnabled();
256
257 /**
258 * Registers a new protocol buffer {@link Service} subclass as a master coprocessor endpoint.
259 *
260 * <p>
261 * Only a single instance may be registered for a given {@link Service} subclass (the
262 * instances are keyed on {@link com.google.protobuf.Descriptors.ServiceDescriptor#getFullName()}.
263 * After the first registration, subsequent calls with the same service name will fail with
264 * a return value of {@code false}.
265 * </p>
266 * @param instance the {@code Service} subclass instance to expose as a coprocessor endpoint
267 * @return {@code true} if the registration was successful, {@code false}
268 * otherwise
269 */
270 boolean registerService(Service instance);
271
272 /**
273 * Merge two regions. The real implementation is on the regionserver, master
274 * just move the regions together and send MERGE RPC to regionserver
275 * @param region_a region to merge
276 * @param region_b region to merge
277 * @param forcible true if do a compulsory merge, otherwise we will only merge
278 * two adjacent regions
279 * @param user effective user
280 * @throws IOException
281 */
282 void dispatchMergingRegions(
283 final HRegionInfo region_a, final HRegionInfo region_b, final boolean forcible, final User user
284 ) throws IOException;
285
286 /**
287 * @return true if master is initialized
288 */
289 boolean isInitialized();
290
291 /**
292 * Create a new namespace
293 * @param descriptor descriptor which describes the new namespace
294 * @param nonceGroup
295 * @param nonce
296 * @throws IOException
297 */
298 public void createNamespace(
299 final NamespaceDescriptor descriptor,
300 final long nonceGroup,
301 final long nonce) throws IOException;
302
303 /**
304 * Create a new namespace synchronously.
305 * @param descriptor descriptor which describes the new namespace
306 * @param nonceGroup
307 * @param nonce
308 * @throws IOException
309 */
310 public void createNamespaceSync(
311 final NamespaceDescriptor descriptor,
312 final long nonceGroup,
313 final long nonce,
314 final boolean executeCoprocessor) throws IOException;
315
316 /**
317 * Modify an existing namespace
318 * @param descriptor descriptor which updates the existing namespace
319 * @param nonceGroup
320 * @param nonce
321 * @throws IOException
322 */
323 public void modifyNamespace(
324 final NamespaceDescriptor descriptor,
325 final long nonceGroup,
326 final long nonce) throws IOException;
327
328 /**
329 * Delete an existing namespace. Only empty namespaces (no tables) can be removed.
330 * @param name namespace name
331 * @param nonceGroup
332 * @param nonce
333 * @throws IOException
334 */
335 public void deleteNamespace(
336 final String name,
337 final long nonceGroup,
338 final long nonce) throws IOException;
339
340 /**
341 * Abort a procedure.
342 * @param procId ID of the procedure
343 * @param mayInterruptIfRunning if the proc completed at least one step, should it be aborted?
344 * @return true if aborted, false if procedure already completed or does not exist
345 * @throws IOException
346 */
347 public boolean abortProcedure(final long procId, final boolean mayInterruptIfRunning)
348 throws IOException;
349
350 /**
351 * List procedures
352 * @return procedure list
353 * @throws IOException
354 */
355 public List<ProcedureInfo> listProcedures() throws IOException;
356
357 /**
358 * Get a namespace descriptor by name
359 * @param name name of namespace descriptor
360 * @return A descriptor
361 * @throws IOException
362 */
363 public NamespaceDescriptor getNamespaceDescriptor(String name) throws IOException;
364
365 /**
366 * List available namespace descriptors
367 * @return A descriptor
368 * @throws IOException
369 */
370 public List<NamespaceDescriptor> listNamespaceDescriptors() throws IOException;
371
372 /**
373 * Get list of table descriptors by namespace
374 * @param name namespace name
375 * @return descriptors
376 * @throws IOException
377 */
378 public List<HTableDescriptor> listTableDescriptorsByNamespace(String name) throws IOException;
379
380 /**
381 * Get list of table names by namespace
382 * @param name namespace name
383 * @return table names
384 * @throws IOException
385 */
386 public List<TableName> listTableNamesByNamespace(String name) throws IOException;
387
388 /**
389 * @param table the table for which last successful major compaction time is queried
390 * @return the timestamp of the last successful major compaction for the passed table,
391 * or 0 if no HFile resulting from a major compaction exists
392 * @throws IOException
393 */
394 public long getLastMajorCompactionTimestamp(TableName table) throws IOException;
395
396 /**
397 * @param regionName
398 * @return the timestamp of the last successful major compaction for the passed region
399 * or 0 if no HFile resulting from a major compaction exists
400 * @throws IOException
401 */
402 public long getLastMajorCompactionTimestampForRegion(byte[] regionName) throws IOException;
403 }