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