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