1 /**
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19 package org.apache.hadoop.hbase.procedure2.store;
20
21 import java.io.IOException;
22 import java.util.Iterator;
23
24 import org.apache.hadoop.hbase.classification.InterfaceAudience;
25 import org.apache.hadoop.hbase.classification.InterfaceStability;
26 import org.apache.hadoop.hbase.procedure2.Procedure;
27
28 /**
29 * The ProcedureStore is used by the executor to persist the state of each procedure execution.
30 * This allows to resume the execution of pending/in-progress procedures in case
31 * of machine failure or service shutdown.
32 */
33 @InterfaceAudience.Private
34 @InterfaceStability.Evolving
35 public interface ProcedureStore {
36 /**
37 * Store listener interface.
38 * The main process should register a listener and respond to the store events.
39 */
40 public interface ProcedureStoreListener {
41 /**
42 * triggered when the store is not able to write out data.
43 * the main process should abort.
44 */
45 void abortProcess();
46 }
47
48 /**
49 * Add the listener to the notification list.
50 * @param listener The AssignmentListener to register
51 */
52 void registerListener(ProcedureStoreListener listener);
53
54 /**
55 * Remove the listener from the notification list.
56 * @param listener The AssignmentListener to unregister
57 * @return true if the listner was in the list and it was removed, otherwise false.
58 */
59 boolean unregisterListener(ProcedureStoreListener listener);
60
61 /**
62 * Start/Open the procedure store
63 * @param numThreads
64 */
65 void start(int numThreads) throws IOException;
66
67 /**
68 * Stop/Close the procedure store
69 * @param abort true if the stop is an abort
70 */
71 void stop(boolean abort);
72
73 /**
74 * @return true if the store is running, otherwise false.
75 */
76 boolean isRunning();
77
78 /**
79 * @return the number of threads/slots passed to start()
80 */
81 int getNumThreads();
82
83 /**
84 * Acquire the lease for the procedure store.
85 */
86 void recoverLease() throws IOException;
87
88 /**
89 * Load the Procedures in the store.
90 * @return the set of procedures present in the store
91 */
92 Iterator<Procedure> load() throws IOException;
93
94 /**
95 * When a procedure is submitted to the executor insert(proc, null) will be called.
96 * 'proc' has a 'RUNNABLE' state and the initial information required to start up.
97 *
98 * When a procedure is executed and it returns children insert(proc, subprocs) will be called.
99 * 'proc' has a 'WAITING' state and an update state.
100 * 'subprocs' are the children in 'RUNNABLE' state with the initial information.
101 *
102 * @param proc the procedure to serialize and write to the store.
103 * @param subprocs the newly created child of the proc.
104 */
105 void insert(Procedure proc, Procedure[] subprocs);
106
107 /**
108 * The specified procedure was executed,
109 * and the new state should be written to the store.
110 * @param proc the procedure to serialize and write to the store.
111 */
112 void update(Procedure proc);
113
114 /**
115 * The specified procId was removed from the executor,
116 * due to completion, abort or failure.
117 * The store implementor should remove all the information about the specified procId.
118 * @param procId the ID of the procedure to remove.
119 */
120 void delete(long procId);
121 }