View Javadoc

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.coordination;
20  import java.io.IOException;
21  import java.util.concurrent.atomic.AtomicLong;
22  
23  import org.apache.hadoop.conf.Configuration;
24  import org.apache.hadoop.fs.FileSystem;
25  import org.apache.hadoop.fs.Path;
26  import org.apache.hadoop.hbase.SplitLogTask;
27  import org.apache.hadoop.hbase.classification.InterfaceAudience;
28  import org.apache.hadoop.hbase.protobuf.generated.ClusterStatusProtos.RegionStoreSequenceIds;
29  import org.apache.hadoop.hbase.regionserver.RegionServerServices;
30  import org.apache.hadoop.hbase.regionserver.SplitLogWorker;
31  import org.apache.hadoop.hbase.regionserver.SplitLogWorker.TaskExecutor;
32  
33  /**
34   * Coordinated operations for {@link SplitLogWorker} and 
35   * {@link org.apache.hadoop.hbase.regionserver.handler.WALSplitterHandler} Important
36   * methods for SplitLogWorker: <BR>
37   * {@link #isReady()} called from {@link SplitLogWorker#run()} to check whether the coordination is
38   * ready to supply the tasks <BR>
39   * {@link #taskLoop()} loop for new tasks until the worker is stopped <BR>
40   * {@link #isStop()} a flag indicates whether worker should finish <BR>
41   * {@link #registerListener()} called from {@link SplitLogWorker#run()} and could register listener
42   * for external changes in coordination (if required) <BR>
43   * {@link #endTask(SplitLogTask, AtomicLong, SplitTaskDetails)} notify coordination engine that
44   * <p>
45   * Important methods for WALSplitterHandler: <BR>
46   * splitting task has completed.
47   */
48  @InterfaceAudience.Private
49  public interface SplitLogWorkerCoordination {
50  
51  /* SplitLogWorker part */
52    public static final int DEFAULT_MAX_SPLITTERS = 2;
53  
54    /**
55     * Initialize internal values. This method should be used when corresponding SplitLogWorker
56     * instance is created
57     * @param server instance of RegionServerServices to work with
58     * @param conf is current configuration.
59     * @param splitTaskExecutor split executor from SplitLogWorker
60     * @param worker instance of SplitLogWorker
61     */
62    void init(RegionServerServices server, Configuration conf,
63        TaskExecutor splitTaskExecutor, SplitLogWorker worker);
64  
65    /**
66     *  called when Coordination should stop processing tasks and exit
67     */
68    void stopProcessingTasks();
69  
70    /**
71     * @return the current value of exitWorker
72     */
73    boolean isStop();
74  
75    /**
76     * Wait for the new tasks and grab one
77     * @throws InterruptedException if the SplitLogWorker was stopped
78     */
79    void taskLoop() throws InterruptedException;
80  
81    /**
82     * marks log file as corrupted
83     * @param rootDir where to find the log
84     * @param name of the log
85     * @param fs file system
86     */
87    void markCorrupted(Path rootDir, String name, FileSystem fs);
88  
89    /**
90     * Check whether the log splitter is ready to supply tasks
91     * @return false if there is no tasks
92     * @throws InterruptedException if the SplitLogWorker was stopped
93     */
94    boolean isReady() throws InterruptedException;
95  
96    /**
97     * Used by unit tests to check how many tasks were processed
98     * @return number of tasks
99     */
100   int getTaskReadySeq();
101 
102   /**
103    * set the listener for task changes. Implementation specific
104    */
105   void registerListener();
106 
107   /**
108    * remove the listener for task changes. Implementation specific
109    */
110   void removeListener();
111 
112   /* WALSplitterHandler part */
113 
114   /**
115    * Notify coordination engine that splitting task has completed.
116    * @param slt See {@link SplitLogTask}
117    * @param ctr counter to be updated
118    * @param splitTaskDetails details about log split task (specific to coordination engine being
119    *          used).
120    */
121   void endTask(SplitLogTask slt, AtomicLong ctr, SplitTaskDetails splitTaskDetails);
122 
123   /**
124    * Interface for log-split tasks Used to carry implementation details in encapsulated way through
125    * Handlers to the coordination API.
126    */
127   static interface SplitTaskDetails {
128 
129     /**
130      * @return full file path in HDFS for the WAL file to be split.
131      */
132     String getWALFile();
133   }
134 
135   RegionStoreSequenceIds getRegionFlushedSequenceId(String failedServerName, String key)
136       throws IOException;
137 
138 }