View Javadoc

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  package org.apache.hadoop.hbase.procedure;
19  
20  import java.io.IOException;
21  
22  import org.apache.hadoop.hbase.classification.InterfaceAudience;
23  import org.apache.hadoop.hbase.classification.InterfaceStability;
24  import org.apache.hadoop.hbase.Stoppable;
25  import org.apache.hadoop.hbase.master.MasterServices;
26  import org.apache.hadoop.hbase.master.MetricsMaster;
27  import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.ProcedureDescription;
28  import org.apache.zookeeper.KeeperException;
29  
30  /**
31  * A life-cycle management interface for globally barriered procedures on master.
32  * See the following doc on details of globally barriered procedure:
33  * https://issues.apache.org/jira/secure/attachment/12555103/121127-global-barrier-proc.pdf
34  *
35  * To implement a custom globally barriered procedure, user needs to extend two classes:
36  * {@link MasterProcedureManager} and {@link RegionServerProcedureManager}. Implementation of
37  * {@link MasterProcedureManager} is loaded into {@link org.apache.hadoop.hbase.master.HMaster} 
38  * process via configuration parameter 'hbase.procedure.master.classes', while implementation of
39  * {@link RegionServerProcedureManager} is loaded into 
40  * {@link org.apache.hadoop.hbase.regionserver.HRegionServer} process via
41  * configuration parameter 'hbase.procedure.regionserver.classes'.
42  *
43  * An example of globally barriered procedure implementation is 
44  * {@link org.apache.hadoop.hbase.master.snapshot.SnapshotManager} and
45  * {@link org.apache.hadoop.hbase.regionserver.snapshot.RegionServerSnapshotManager}.
46  *
47  * A globally barriered procedure is identified by its signature (usually it is the name of the
48  * procedure znode). During the initialization phase, the initialize methods are called by both
49  * {@link org.apache.hadoop.hbase.master.HMaster} and 
50  * {@link org.apache.hadoop.hbase.regionserver.HRegionServer} witch create the procedure znode 
51  * and register the listeners. A procedure can be triggered by its signature and an instant name 
52  * (encapsulated in a {@link ProcedureDescription} object). When the servers are shutdown, 
53  * the stop methods on both classes are called to clean up the data associated with the procedure.
54  */
55  @InterfaceAudience.Private
56  @InterfaceStability.Evolving
57  public abstract class MasterProcedureManager extends ProcedureManager implements
58      Stoppable {
59    /**
60     * Initialize a globally barriered procedure for master.
61     *
62     * @param master Master service interface
63     * @throws KeeperException
64     * @throws IOException
65     * @throws UnsupportedOperationException
66     */
67    public abstract void initialize(MasterServices master, MetricsMaster metricsMaster)
68        throws KeeperException, IOException, UnsupportedOperationException;
69  
70    /**
71     * Execute a distributed procedure on cluster
72     *
73     * @param desc Procedure description
74     * @throws IOException
75     */
76    public void execProcedure(ProcedureDescription desc) throws IOException {
77  
78    }
79  
80    /**
81     * Execute a distributed procedure on cluster with return data.
82     *
83     * @param desc Procedure description
84     * @return data returned from the procedure execution, null if no data
85     * @throws IOException
86     */
87    public byte[] execProcedureWithRet(ProcedureDescription desc)
88        throws IOException {
89      return null;
90    }
91  
92    /**
93     * Check if the procedure is finished successfully
94     *
95     * @param desc Procedure description
96     * @return true if the specified procedure is finished successfully
97     * @throws IOException
98     */
99    public abstract boolean isProcedureDone(ProcedureDescription desc) throws IOException;
100 }