001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.hbase.coordination; 019import java.util.concurrent.atomic.LongAdder; 020import org.apache.hadoop.conf.Configuration; 021import org.apache.hadoop.fs.FileSystem; 022import org.apache.hadoop.fs.Path; 023import org.apache.hadoop.hbase.SplitLogTask; 024import org.apache.hadoop.hbase.regionserver.RegionServerServices; 025import org.apache.hadoop.hbase.regionserver.SplitLogWorker; 026import org.apache.hadoop.hbase.regionserver.SplitLogWorker.TaskExecutor; 027import org.apache.yetus.audience.InterfaceAudience; 028 029/** 030 * Coordinated operations for {@link SplitLogWorker} and 031 * {@link org.apache.hadoop.hbase.regionserver.handler.WALSplitterHandler} Important 032 * methods for SplitLogWorker: <BR> 033 * {@link #isReady()} called from {@link SplitLogWorker#run()} to check whether the coordination is 034 * ready to supply the tasks <BR> 035 * {@link #taskLoop()} loop for new tasks until the worker is stopped <BR> 036 * {@link #isStop()} a flag indicates whether worker should finish <BR> 037 * {@link #registerListener()} called from {@link SplitLogWorker#run()} and could register listener 038 * for external changes in coordination (if required) <BR> 039 * {@link #endTask(SplitLogTask, LongAdder, SplitTaskDetails)} notify coordination engine that 040 * <p> 041 * Important methods for WALSplitterHandler: <BR> 042 * splitting task has completed. 043 * @deprecated since 2.4.0 and in 3.0.0, to be removed in 4.0.0, replaced by procedure-based 044 * distributed WAL splitter, see SplitWALManager 045 */ 046@Deprecated 047@InterfaceAudience.Private 048public interface SplitLogWorkerCoordination { 049 050 /** 051 * Initialize internal values. This method should be used when corresponding SplitLogWorker 052 * instance is created 053 * @param server instance of RegionServerServices to work with 054 * @param conf is current configuration. 055 * @param splitTaskExecutor split executor from SplitLogWorker 056 * @param worker instance of SplitLogWorker 057 */ 058 void init(RegionServerServices server, Configuration conf, 059 TaskExecutor splitTaskExecutor, SplitLogWorker worker); 060 061 /** 062 * called when Coordination should stop processing tasks and exit 063 */ 064 void stopProcessingTasks(); 065 066 /** 067 * @return the current value of exitWorker 068 */ 069 boolean isStop(); 070 071 /** 072 * Wait for the new tasks and grab one 073 * @throws InterruptedException if the SplitLogWorker was stopped 074 */ 075 void taskLoop() throws InterruptedException; 076 077 /** 078 * marks log file as corrupted 079 * @param rootDir where to find the log 080 * @param name of the log 081 * @param fs file system 082 */ 083 void markCorrupted(Path rootDir, String name, FileSystem fs); 084 085 /** 086 * Check whether the log splitter is ready to supply tasks 087 * @return false if there is no tasks 088 * @throws InterruptedException if the SplitLogWorker was stopped 089 */ 090 boolean isReady() throws InterruptedException; 091 092 /** 093 * Used by unit tests to check how many tasks were processed 094 * @return number of tasks 095 */ 096 int getTaskReadySeq(); 097 098 /** 099 * set the listener for task changes. Implementation specific 100 */ 101 void registerListener(); 102 103 /** 104 * remove the listener for task changes. Implementation specific 105 */ 106 void removeListener(); 107 108 /* WALSplitterHandler part */ 109 110 /** 111 * Notify coordination engine that splitting task has completed. 112 * @param slt See {@link SplitLogTask} 113 * @param ctr counter to be updated 114 * @param splitTaskDetails details about log split task (specific to coordination engine being 115 * used). 116 */ 117 void endTask(SplitLogTask slt, LongAdder ctr, SplitTaskDetails splitTaskDetails); 118 119 /** 120 * Interface for log-split tasks Used to carry implementation details in encapsulated way through 121 * Handlers to the coordination API. 122 */ 123 interface SplitTaskDetails { 124 125 /** 126 * @return full file path in HDFS for the WAL file to be split. 127 */ 128 String getWALFile(); 129 } 130}