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