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 sync is completed.
43 */
44 void postSync();
45
46 /**
47 * triggered when the store is not able to write out data.
48 * the main process should abort.
49 */
50 void abortProcess();
51 }
52
53 /**
54 * Add the listener to the notification list.
55 * @param listener The AssignmentListener to register
56 */
57 void registerListener(ProcedureStoreListener listener);
58
59 /**
60 * Remove the listener from the notification list.
61 * @param listener The AssignmentListener to unregister
62 * @return true if the listner was in the list and it was removed, otherwise false.
63 */
64 boolean unregisterListener(ProcedureStoreListener listener);
65
66 /**
67 * Start/Open the procedure store
68 * @param numThreads
69 */
70 void start(int numThreads) throws IOException;
71
72 /**
73 * Stop/Close the procedure store
74 * @param abort true if the stop is an abort
75 */
76 void stop(boolean abort);
77
78 /**
79 * @return true if the store is running, otherwise false.
80 */
81 boolean isRunning();
82
83 /**
84 * @return the number of threads/slots passed to start()
85 */
86 int getNumThreads();
87
88 /**
89 * Acquire the lease for the procedure store.
90 */
91 void recoverLease() throws IOException;
92
93 /**
94 * Load the Procedures in the store.
95 * @return the set of procedures present in the store
96 */
97 Iterator<Procedure> load() throws IOException;
98
99 /**
100 * When a procedure is submitted to the executor insert(proc, null) will be called.
101 * 'proc' has a 'RUNNABLE' state and the initial information required to start up.
102 *
103 * When a procedure is executed and it returns children insert(proc, subprocs) will be called.
104 * 'proc' has a 'WAITING' state and an update state.
105 * 'subprocs' are the children in 'RUNNABLE' state with the initial information.
106 *
107 * @param proc the procedure to serialize and write to the store.
108 * @param subprocs the newly created child of the proc.
109 */
110 void insert(Procedure proc, Procedure[] subprocs);
111
112 /**
113 * The specified procedure was executed,
114 * and the new state should be written to the store.
115 * @param proc the procedure to serialize and write to the store.
116 */
117 void update(Procedure proc);
118
119 /**
120 * The specified procId was removed from the executor,
121 * due to completion, abort or failure.
122 * The store implementor should remove all the information about the specified procId.
123 * @param procId the ID of the procedure to remove.
124 */
125 void delete(long procId);
126 }